Multiple trait bounds notation


#1

While studying the multiple trait bounds section of the rust book:
https://doc.rust-lang.org/book/traits.html#multiple-trait-bounds
I though it would be clearer to use & instead of +, so the example would become:

fn foo<T: Clone & Debug>(x: T) {
    x.clone();
    println!("{:?}", x);
}

This would also allow the use of | with “or” meaning:

fn foo<T: Clone | Debug>(x: T) {
    x.clone();
    println!("{:?}", x);
}

Just for your consideration.


#2

I do not understand how | would work, because the function body uses both and would therefore require both, not require at least one.

-1 though Beta has hit and i am not for random changes that don’t affect anything just because some person wants it changed.


#3

On a better thought, I agree with you. Originally I thought if you had traits HasEngine, HasPedals, HasTwoWheels, HasFourWheels, HasCrawlers, you could write for instance:

fn yearly_cost_for_gasoline_and_tires<T: HasEngine & (HasTwoWheels | HasFourWheels)>(x: T) { ... };

but of course you could better solve this with trait HasWheels.