What does the "expected element found let" mean?

My code below returns an error

expected item, found `let` 

What does it mean?

 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]}; 
+2
source share
1 answer

There are a number of problems in this code, but the error you get is that you are trying to execute the code, but not from a function:

 let my_storage = MyStorage{name = [0x11]}; 

You need to say something. Here I 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 fix the vector construct ( vec! ), Delete the link that doesn't exist ( MyStorage ), and change the self type to get . In this case, the code is compiled.

+5
source

Source: https://habr.com/ru/post/984116/


All Articles