4 ms·
function max with type parameter T with arguments a of type T and b of type T and returns a value of type T where T implements trait PartialEq
by estebank 2y ago
function max with type parameter T
with arguments
a of type T and b of type T
and returns a value of type T
where T implements trait PartialEq
Vs
fn max<T>(a: T, b: T) -> T where T: PartialEq
- yencabulator 2y agoLimiting examples to a subset of Rust syntax will produce more readable answers, sure. You have no lifetimes and no borrows, and very limited generics.
- estebank 2y agoThe information density of the "human syntax" Rust syntax both remain linear in size, but with a significant different N. function max with a lifetime a, a lifetime b, and type parameter T with argument a of a reference to type T that lives as long as lifetime a argument b of a reference to type T that lives as long as lifetime b and returns a value of type parameter T where T implements trait PartialEq Vs fn max<'a, 'b, T: PartialEq>(a: &'a T, b: &'b T) -> T If you want a real life example: #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, A: Allocator> IntoIterator for &'a Vec<T, A> { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; fn into_iter(self) -> Self::IntoIter { self.iter() } } An implementation of trait IntoIterator (that has been stable since Rust 1.0.0) with a lifetime a a type parameter T a type parameter A which implements the trait Allocator for a borrow for the duration of lifetime a of type Vec with type parameters T and A it has an associated type Item, which is a borrow for the duration of lifetime a of type T it has an associated type IntoIter, which is type Iter from module slice with parameters lifetime a and type T it has a method into_iter that consumes the receiver and returns associated type IntoIter the methods body calls method iter on the receiver and returns its resulting value
- yencabulator 2y agoI'm not arguing that complex things will somehow become non-complex. However, none of the human syntax of Rust includes things like :: or '. To a first approximation[1], those are the parts that people can experience as "ugly", and they are not present in the human syntax. This is what people mean when they say "sigil heavy" or "punctuation based" syntax -- things that are generally are not read out as such. This is the space where you can make arguments about beauty. [1]: Only roughly so because your chosen human syntax still encodes some Rust syntax decisions like predeclaring generic lifetimes and types, and using "where" instead of an inline clause. Those parts of syntax can also be shuffled around for subjective values of "not ugly".