#Is generic the right tool to use on functions with different function bodies?
17 messages · Page 1 of 1 (latest)
Generics is about grouping types in sets according to some properties, and writing a function that acts on said properties just once, but your types don't have anything in common that you can abstract between those two functions.
In this case would I just leave it as is?
I was thinking maybe there's a way to clean up the function call, e.g.
convert::<64>(some_bytes)
TryFrom<[u8]> might be implemented for f64 and u64, let me look at the docs
I can't exactly use try_from() since the bytes are of utf8 strings
Doesn't seem like. If you had a &str you can use parse
There's also the crate lexical to lex numbers partially
I have my own algorithm to do the conversion, it's just I was hoping I can have a clean function signature
I think that's pretty concise already. If your bytes are utf8 you can use &str and &str methods with it. &[u8] for parsing is used when all bytes are ascii so you don't spend time computing the byte lengths of each character.
Parse a value from a string
and the crate I mentioned: https://docs.rs/lexical/latest/lexical/
Fast lexical conversion routines.
just to have the information complete.