Rust Structures

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • struct Foo { field1: Type1, field2: Type2 }
  • let foo = Foo { field1: Type1::new(), field2: Type2::new() };
  • struct Bar ( Type1, Type2 ); // tuple type
  • let _ = Bar(Type1::new(), Type2::new());
  • struct Baz; // unit-like type
  • let _ = Baz;
  • let Foo { field1, .. } = foo; // extract field1 by pattern matching
  • let Foo { field1: x, .. } = foo; // extract field1 as x
  • let foo2 = Foo { field1: Type1::new(), .. foo }; // construct from existing
  • impl Foo { fn fiddle(&self) {} } // declare instance method for Foo
  • impl Foo { fn tweak(&mut self) {} } // declare mutable instance method for Foo
  • impl Foo { fn double(self) {} } // declare owning instance method for Foo
  • impl Foo { fn new() {} } // declare associated method for Foo


Got any Rust Question?