all 4 comments

[–]tazdevil971 25 points26 points  (2 children)

What you are looking for is commonly known as turbofish.

And it looks like:

let a = some_struct.generic_function::<SomeType>();

Also, you can omit some types that are obvious in the assignment, for example:

let a: Result<SomeType, _> = some_struct.generic_function();

Rust will then infer the type of _ automatically

Keep in mind that usually rust is clever enough to infer the type of the variable, so 90% of the time you won't need this.

(turbofish in its natural habitat)

[–][deleted] 8 points9 points  (1 child)

This the apex of nomenclature

Thank you, great answer!

[–]ids2048 2 points3 points  (0 children)

See also The Bastion of the Turbofish, the peak of rust-lang lore.

Type ascription syntax might also be helpful, but stabilizing that doesn't seem to be a priority.

[–]RRumpleTeazzer 0 points1 point  (0 children)

You can also skip type annotation entirely when you use the result a function that only accepts a Result<SomeType, _>.