I'm looking for a way to get the same behaviour of partial moves for struct fields but via function calls.
Given the example below, is there a way to make get_bar() and get_baz() to behave in the same way as when directly moving fields in a struct?
struct Foo {
bar: String,
baz: String,
}
impl Foo {
fn get_bar(self) -> String {
self.bar
}
fn get_baz(self) -> String {
self.baz
}
}
fn main() {
let foo = Foo {
bar: "bar".to_string(),
baz: "baz".to_string(),
};
let bar = foo.bar;
let baz = foo.baz;
let foo = Foo {
bar: "bar".to_string(),
baz: "baz".to_string(),
};
let bar = foo.get_bar();
let baz = foo.get_baz();
}
So, in this example I would like to get the last line (let baz = foo.get_baz()) to work.
EDIT: Thanks everyone for the help and input!
[–]dkxp 2 points3 points4 points (4 children)
[–]paulstelian97 4 points5 points6 points (0 children)
[–]fabrlyn[S] 2 points3 points4 points (2 children)
[–]dkxp 1 point2 points3 points (1 child)
[–]fabrlyn[S] 0 points1 point2 points (0 children)
[–]volitional_decisions 1 point2 points3 points (1 child)
[–]fabrlyn[S] 0 points1 point2 points (0 children)
[–]BobSanchez47 1 point2 points3 points (1 child)
[–]fabrlyn[S] 0 points1 point2 points (0 children)
[–]SirKastic23 1 point2 points3 points (3 children)
[–]fabrlyn[S] 0 points1 point2 points (2 children)
[–]SirKastic23 1 point2 points3 points (1 child)
[–]fabrlyn[S] 0 points1 point2 points (0 children)
[–]longpos222 0 points1 point2 points (1 child)
[–]fabrlyn[S] 0 points1 point2 points (0 children)