pub struct People { /* fields omitted */ }
Basic usage:
#[derive(Debug, PartialEq)]
struct People {
name: &'static str,
gender: u32,
}
impl People {
fn new(name: &'static str, gender: u32) -> Self{
return People{name: name, gender: gender};
}
fn name(&self) {
println!("name: {:?}", self.name);
}
fn set_name(&mut self, name: &'static str) {
self.name = name;
}
fn gender(&self){
let gender = if (self.gender == 1) {"boy"} else {"girl"};
println!("gender: {:?}", gender);
}
}
let alex = People::new( "Alex", 1);
alex.name();
alex.gender();
assert_eq!(alex, People { name: "Alex", gender: 1 });
let mut alice = People::new("Alice", 0);
alice.name();
alice.gender();
assert_eq!(alice, People { name: "Alice", gender: 0 });
alice.set_name("Rose");
alice.name();
assert_eq!(alice, People { name: "Rose", gender: 0 });Run
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)