pub struct MultipleConstructors {
pub a: i32,
pub b: i32,
pub c: i32,
pub identical: bool,
}
Expand description
An example showing how to efficiently create multiple constructors.
It is defined as follows:
#[make_constructor]
/// ^ This is documentation for the first constructor. Notice how a, b, and c have been
/// ^ automatically generated for us.
#[make_constructor(pub new_identical(shared: i32))]
/// ^ This is documentation for the second constructor. Notice how the only argument is
/// ^ `shared`, since we have specified the code that sets up all the other fields in this case.
pub struct MultipleConstructors {
// Note that we do not provide a default `value` or `[value] for new` for any of these
// fields, so the macro will automatically add parameters for them in the `new` constructor.
#[value(shared for new_identical)]
pub a: i32,
#[value(shared for new_identical)]
pub b: i32,
#[value(shared for new_identical)]
pub c: i32,
/// This field will always be `true` when created with `new_identical` and `false` when
/// created with `new`.
#[value(true)]
#[value(false for new)]
pub identical: bool,
}
Fields§
§a: i32
§b: i32
§c: i32
§identical: bool
This field will always be true
when created with new_identical
and false
when
created with new
.
Implementations§
Source§impl MultipleConstructors
impl MultipleConstructors
Sourcepub fn new(a: i32, b: i32, c: i32) -> Self
pub fn new(a: i32, b: i32, c: i32) -> Self
This is documentation for the first constructor. Notice how a, b, and c have been automatically generated for us.
Sourcepub fn new_identical(shared: i32) -> Self
pub fn new_identical(shared: i32) -> Self
This is documentation for the second constructor. Notice how the only argument is
shared
, since we have specified the code that sets up all the other fields in this case.
Auto Trait Implementations§
impl Freeze for MultipleConstructors
impl RefUnwindSafe for MultipleConstructors
impl Send for MultipleConstructors
impl Sync for MultipleConstructors
impl Unpin for MultipleConstructors
impl UnwindSafe for MultipleConstructors
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more