Search code examples
rustsyntax

What is the difference between <Type>::method() AND Type::method()?


In Rust, is there difference between <Type>::method() and Type::method()? Any easy way to see the differences?

For example, this rocket swagger code uses <String>::responses(...).


Solution

  • They mean the same thing. However, Type::method() can only be used when Type is also a path. Other types may require using < > like:

    • <[u8]>::method()
    • <&str>::method()
    • <(u8, u8)>::method()
    • <Vec<u8>>::method() (though Vec::<u8>::method() does work too)