Its not clear why a borrowed reference is not able to make a call to the function.
Standard Error
Compiling playground v0.0.1 (/playground)
warning: unused variable: `a`
--> src/main.rs:23:9
|
23 | let a = Astruct::new(Atype::TypeA, 100);
| ^ help: consider prefixing with an underscore: `_a`
|
= note: #[warn(unused_variables)] on by default
error[E0507]: cannot move out of borrowed content
--> src/main.rs:13:14
|
13 | Some(self.aType)
| ^^^^^^^^^^ cannot move out of borrowed content
error: aborting due to previous error
For more information about this error, try `rustc --explain E0507`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
enum Atype {
TypeA,
TypeB,
}
struct Astruct {
pub aType : Atype,
pub aVal : i32,
}
impl Astruct {
pub fn getType(&self) -> Option<Atype> {
Some(self.aType)
}
pub fn new(aType: Atype, aVal: i32) -> Astruct {
Astruct { aType: aType,
aVal: aVal}
}
}
fn main() {
let a = Astruct::new(Atype::TypeA, 100);
//println!("Type: {} Val: {}", a.aType, a.aVal);
}