[][src]Struct tao_of_rust::ch02::structs::People

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

Trait Implementations

impl PartialEq<People> for People
[src]

impl Debug for People
[src]

Auto Trait Implementations

impl Send for People

impl Sync for People

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.