Reputation: 4464
I was reading the hyperium/http source code and I found this:
pub fn put<T>(uri: T) -> Builder
where
Uri: TryFrom<T>,
<Uri as TryFrom<T>>::Error: Into<crate::Error>,
{
Builder::new().method(Method::PUT).uri(uri)
}
In this snippet, Uri
is a type and T
a generic element.
I have always seen the construction where T: SomeTrait
, but not SomeType: SomeTrait<T>
.
Does this construction have a name and is it documented somewhere?
Upvotes: 0
Views: 2865
Reputation: 36071
Quoting https://doc.rust-lang.org/reference/trait-bounds.html#higher-ranked-trait-bounds:
Bounds on an item must be satisfied when using the item. When type checking and borrow checking a generic item, the bounds can be used to determine that a trait is implemented for a type. For example, given
Ty: Trait
In the body of a generic function, methods from
Trait
can be called onTy
values. Likewise associated constants on theTrait
can be used. Associated types fromTrait
can be used. Generic functions and types with aT: Trait
bounds can be used withTy
being used forT
.
Nothing states that Ty
is a type parameter (and not a fixed type). So I would say it is simply a trait bound, albeit admittedly not very often encountered in Rust tutorials.
Upvotes: 1