rust_programming_book 0.1.1

Programming works from THE RUST PROGRAMMING LANGUAGE
Documentation
use crate::implementation::Elephant;

/**

 Traits are like abstract class and interfaces in Java, which shows polymorphism.
  Traits can be used by multiple structs thus function declarations inside a traits can be
  implemented in any structs. Thus traits decouples the functions.
*/
pub trait SomeTraits {
    fn is_lovely(&self) -> bool;

    fn is_big_enough(&self) -> bool;
}

pub struct Cow<'a> {
    pub age: i8,
    pub height: f32,
    pub name: &'a str,
}

impl<'a> SomeTraits for Elephant<'a> {
    fn is_big_enough(&self) -> bool {
        self.tusk_size > 2.0
    }

    fn is_lovely(&self) -> bool {
        true
    }
}

impl<'a> SomeTraits for Cow<'a> {
    fn is_big_enough(&self) -> bool {
        self.height > 2.0
    }
    fn is_lovely(&self) -> bool {
        true
    }
}