You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have difficulties understanding how to use the funty::Numeric or funty::Fondumental trait in my crate. This is for sure because of my lack of knowledge of Rust, I'm still learning it.
Little background
I'm creating an audio crate, and some functions accept a Numeric value (a Sample) that could be f32, u8, i16 etc. I don't care what type of value is passed, I need only to be sure is a numeric value, so I can convert it to a Vec of little-endian.
Problem
I cannot convert the <T as funty::Numeric>::Bytes, returned by .to_le_bytes() function to Vec<u8>.
Process
So my first intuition was to declare a new trait using this syntax:
And, if I understand Rust correctly, I can create functions in this way:
pubfnuse_sample<T:Sample>(sample:T){
sample.to_le_bytes()}// and this function can be called any combination: // use_sample(3) or use_sample(0.1233123)println!("Result:{:?}", use_sample(3asu8))// Result: [3]println!("Result:{:?}", use_sample(0.1233123))// Result: [109, 205, 177, 23, 101, 145, 191, 63]
My problem starts now. I'm not able to use the funty::Bytes (<T as funty::Numeric>::Bytes) returned by to_le_bytes function.
What I need is the possibility to do the following:
Hi!
Thanks a lot for your effort on the crate!
I have difficulties understanding how to use the funty::Numeric or funty::Fondumental trait in my crate. This is for sure because of my lack of knowledge of Rust, I'm still learning it.
Little background
I'm creating an audio crate, and some functions accept a Numeric value (a Sample) that could be f32, u8, i16 etc. I don't care what type of value is passed, I need only to be sure is a numeric value, so I can convert it to a Vec of little-endian.
Problem
I cannot convert the
<T as funty::Numeric>::Bytes
, returned by.to_le_bytes()
function toVec<u8>
.Process
So my first intuition was to declare a new trait using this syntax:
And, if I understand Rust correctly, I can create functions in this way:
My problem starts now. I'm not able to use the
funty::Bytes
(<T as funty::Numeric>::Bytes
) returned byto_le_bytes
function.What I need is the possibility to do the following:
But the error triggered is:
So, after this introduction, the real question is:
how can I convert
<T as Numeric>::Bytes
intoVec<u8>
?The text was updated successfully, but these errors were encountered: