Inline type defination

Is possible single line type definition in rust ?
for example:
my return type is haven't support &str but my next method needs str, so i must declare this like

let res: String = id;

Is available any solution to removing first line ?
something like this ?
uuid::Uuid::parse_str(&(res as String)).unwrap().simple().to_string()

You don't need the first line. The following should be fine:

1 Like

Origin (id) not have &str trait but it's have String, and destination just support &str.
if i use your code i will this error:

cannot infer type for

What is the type of id? I assumed it was String, but it sounds like that's not the case. Please provide a minimal example that shows your problem, if you can, ideally on the playground.

1 Like

Unfortunately playground could not support rusqlite library.
Id is a trait result. rusqlite::types::FromSql - Rust

Sorry when i uses your code, kind of error was different of cannot infer type for
I did attached my problem SC.

Try the following on line 65:

|r| r.get::<_, String>(0)

with all else the same.


Thanks man :bouquet::bouquet:

I want read more about ::<_, String> what's name of this section in rust documents ?

The term to search would be "turbofish" - it's the way to explicitly state the type you want, when type inference cannot determine it (like in the case here). I now see why you had let res: String = id - that informed type inference to use String as well.

1 Like