Converting to types from slices of bytes

Having slice &[u8] is there a better way (fewer conversions) to get those types from it:

let date_time:NaiveDateTime = NaiveDateTime::parse_from_str(&String::from_utf8(slice.to_vec()).unwrap(),"%Y-%m-%d %H:%M");
As you can see, here I first convert that slice to Vec then to String and only then to NaiveDateTime. It seems very "unoptimal" and clumsy.
Same here:
let long:i64 = String::from_utf8(slice.to_vec()).unwrap().parse::<i64>().unwrap();

Any advice on that topic more than welcome.
Thank you

No need to go through Vec or String, just go to str.

Not sure about dates, but for integers, crates like atoi also exist (to go strait from &[u8] without UTF8 validation).

Thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.