use std::fs::File;
use std::path::Path;
use std::io::Read;
struct SomeStruct {
data: [u8; 1024],
size: usize,
}
impl SomeStruct {
fn from_file(path: &Path) -> Result<SomeStruct, std::io::Error> {
let mut file = File::open(path)?;
let mut buf: [u8; 1024] = [0; 1024];
let val = SomeStruct {
data: [0; 1024],
size: file.read(&mut <this_struct>.data)?,
};
Ok(val)
}
}
somehow?
Specifically I mean to initialize the struct without needing to create it first, and then mutably change it's data value. Any way to access the <this_struct>?