Help with trait bounds

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?

It's exactly the same construct. Type: Trait is still a "trait bound", and it still means that Type has an implementation of Trait, no matter how complicated the type or trait expressions happen to be.

2 Likes

It's not a different construct, in one case you have a generic parameter, in another a concrete type, but they are both still types. Trait bounds can be applied to any type.

1 Like

Amazing and fast answers. Thanks :star_struck: !

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.