Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused_mut)]
- #![allow(dead_code)]
- struct Bar(isize);
- impl Bar {
- fn new(i: isize) -> Bar { Bar(i) }
- }
- #[derive(Copy, Clone)]
- struct FooCore {
- fc: i32,
- }
- impl FooCore {
- fn new(fc: i32) -> FooCore {
- FooCore {
- fc: fc
- }
- }
- }
- struct Foo<'a> {
- core: &'a mut FooCore,
- bar: &'a mut Bar,
- }
- impl<'a> Foo<'a> {
- fn new(core: &'a mut FooCore, bar: &'a mut Bar) -> Foo<'a> {
- Foo {
- core: core,
- bar: bar
- }
- }
- }
- fn main() {
- // Set up first state
- let mut bar = Bar::new(42);
- let mut core = FooCore::new(20);
- let mut foo = Foo::new(&mut core, &mut bar);
- println!("{}", foo.bar.0);
- // Set up second state
- core.fc = 30;
- let mut bar2 = Bar::new(10);
- let mut foo = Foo::new(&mut core, &mut bar2);
- println!("{}", foo.bar.0);
- }
Add Comment
Please, Sign In to add comment