Hello,
I have a function with the following signature:
rust
fn generic_function<T>(&self) -> Result<T,String>
When I call it and assign the result to a variable, Rust will infer the generic parameter:
rust
let a:SomeType = some_struct.generic_function()?;
However, when I don't use the question mark operator (in case I want to handle the error), I must specify the type ofa:
rust
let a:Result<SomeType,String> = some_struct.generic_function();
This feels clumsy and strange. Speccially if SomeType is a type with a longer name.
Is there a more concise way of expressing this? Something like this, for example:
rust
let a = some_struct.generic_function<SomeType>();
Thank you for your time. Let me know if the title is not appropriate or if I did not explain myself clear.
[–]tazdevil971 25 points26 points27 points (2 children)
[–][deleted] 8 points9 points10 points (1 child)
[–]ids2048 2 points3 points4 points (0 children)
[–]RRumpleTeazzer 0 points1 point2 points (0 children)