My code
pub struct MyStorage {
name: Vec<u8>,
}
impl Storage for MyStorage {
//let mut name: Vec<u8> = [0x11];
fn get(&mut self) -> Vec<u8> {
self.name
}
}
let my_storage = MyStorage { name = [0x11] };
returns the error
error: expected item, found keyword `let`
--> src/lib.rs:12:1
|
12 | let my_storage = MyStorage { name = [0x11] };
| ^^^ expected item
What does that mean?
There's a number of issues with this code, but the error you are getting is because you are trying to execute code but not from within a function:
let my_storage = MyStorage { name = [0x11] };
You need to put that in something. Here, I've added it to main
:
pub struct MyStorage {
name: Vec<u8>,
}
impl MyStorage {
fn get(self) -> Vec<u8> {
self.name
}
}
fn main() {
let my_storage = MyStorage { name: vec![0x11] };
}
I also had to:
vec!
)Storage
)self
in get
=
to :
With all that, the code compiles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With