Skip to content

Instantly share code, notes, and snippets.

@richo
Created December 27, 2020 01:01
Show Gist options
  • Select an option

  • Save richo/ab3a38cbfc07c54aa0b290036ccaf7b8 to your computer and use it in GitHub Desktop.

Select an option

Save richo/ab3a38cbfc07c54aa0b290036ccaf7b8 to your computer and use it in GitHub Desktop.

Revisions

  1. richo created this gist Dec 27, 2020.
    34 changes: 34 additions & 0 deletions lib.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    struct Thing {
    inner: Inner,
    }

    struct Inner {
    name: Composite,
    }

    struct Composite {
    t1: String,
    t2: String,
    }

    pub fn boop() {
    let mut thing = Thing{
    inner: Inner {
    name: Composite {
    t1: "t1".into(),
    t2: "t2".into(),
    }
    }
    };
    thing.rename("butts".into());
    }

    impl Thing {
    fn rename(&mut self, newname: String) {
    let old = self.inner.name;
    self.inner.name = Composite {
    t1: old.t1,
    t2: newname,
    }
    }
    }