I have this code (PLAYGROUND HERE):
#[derive(Debug, Default, Clone)] pub struct BaseFile { pub id: Option<String>, pub location: String, pub size: u64, } impl BaseFile { pub fn filename(&self) -> String { "CALCULATED_FILENAME".to_string() } } #[derive(Debug, Default, Clone)] pub struct AdvancedFile { pub id: Option<String>, pub filename: String, pub size: u64, } impl AdvancedFile { pub fn from_base( id: Option<String>, filename: String, size: u64, ) -> Self { Self { id, filename, size, } } } impl From<BaseFile> for AdvancedFile { fn from(base_file: BaseFile) -> Self { Self::from_base( base_file.id, base_file.filename(), base_file.size, ) } } #[tokio::main] async fn main() { let domain_file = BaseFile { id: None, location: "new_location".to_string(), size: 123, }; dbg!(domain_file); } with this error:
error[E0382]: borrow of partially moved value: `base_file` --> src/main.rs:39:13 | 38 | base_file.id, | ------------ value partially moved here 39 | base_file.filename(), | ^^^^^^^^^^^^^^^^^^^^ value borrowed here after partial move | = note: partial move occurs because `base_file.id` has type `Option<String>`, which does not implement the `Copy` trait Why this error if I'm using &self in pub fn filename(&self) -> String {?