Name: Anonymous 2019-05-21 7:35
For no particular reason I'm endeavoring to make sense of how to compose a conventional capacity that takes a std::fs::File and peruses measure <T> from the record into <T>. It feels somewhat odd to me that when attempting to make a [u8] to fill that the Rust compiler whines that it doesn't know statically the size. I can't help suspecting that it should know at arrangement dependent on <T> however. I know this is effectively conceivable. I'm simply not unreasonably acquainted with the language.
So I'm requesting help in seeing how I help the compiler get it. The code I have so far is
The errore I'm getting is
Contemplations?
So I'm requesting help in seeing how I help the compiler get it. The code I have so far is
bar fn write_to_type<T: Sized>(f: &mut std::fs::File) - > T {
let mut bytes = [0u8; std::mem::size_of::<T>];
f.read_exact(&mut bytes).unwrap();
unsafe { std::mem::transmute::<[u8; 2], T>(bytes) }
}
The errore I'm getting is
unsized local people are gated as a temperamental component [E0277]
every single neighborhood variable must have a statically known size [E0277]
to find out additional, visit <https://doc.rust-lang.org/book/second-release/ch19-04-progressed-types.html#dynamically-sized-types-and-the-sized-trait> [E0277]
the attribute 'std::marker::Sized' isn't actualized for '[u8]' [E0277]
the size for estimations of sort '[u8]' can't be known at arrangement time (doesn't have a size known at gather time) [E0277]
Contemplations?