I'm new to Rust and have the following working code. But I don't think what I am doing is the best way. I'm looking for insights about this piece of simple code.
I have a simple struct that holds some data:
struct BlobRef {
hashname: String,
}
impl BlobRef {
fn hashname(self) -> String {
self.hashname
}
}
And a function call. Don't worry about the source: &[u8]
, it will have its time to shine.
fn write(bref: BlobRef, source: &[u8]) -> io::Result<String> {
let hashname = bref.hashname();
match fs::create_dir_all(&hashname) {
Ok(_) => Ok(hashname),
Err(e) => Err(e)
}
}
I need to assign another scoped variable hashname
to stop the compiler complaining about "use of moved variable". Is this idiomatic?
&self
as the parameter of thehashname
function instead ofself
– oli_obk