Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Foo {
- value: u32
- }
- impl Foo {
- fn method(&mut self, value: &u32) {
- self.value += *value;
- }
- }
- struct Bar {
- value: u32,
- foo: Foo,
- }
- impl Bar {
- fn new() -> Self {
- Bar {
- value: 1,
- foo: Foo {
- value: 2,
- },
- }
- }
- fn get_mut(&mut self) -> Option<&mut u32> {
- Some(&mut self.value)
- }
- fn other_helper(&mut self, value: &mut u32) {
- self.foo.method(value);
- }
- fn static_helper(foo: &mut Foo, value: &mut u32) {
- foo.method(value);
- }
- fn helper(&mut self) {
- if let Some(value) = self.get_mut() {
- self.other_helper(&mut self.value);
- //Self::static_helper(&mut self.foo, &mut self.value);
- }
- }
- fn method(&mut self) {
- }
- }
- fn main() {
- let mut bar = Bar::new();
- bar.method();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement