[][src]Trait photonix::focus::GetRef

pub trait GetRef<Value> {
    fn get_ref(&self) -> &Value;
}

Returns the target field of a container (struct) by reference, keeps the container.

Auto-derive creates the implementation for all fields, works for structs (both with named and unnamed fields) if

  • all fields have concrete types,
  • all field types are different.

Examples

 #[derive(GetRef)]
 pub struct Person {
     pub name: String,
     pub age: u8,
 }

 let joe = Person { name: String::from("Joe"), age: 42 };

 assert_eq!(42u8, *joe.get_ref());

 let name: &String = joe.get_ref();

 assert_eq!("Joe", name.as_str());

Required methods

fn get_ref(&self) -> &Value

Loading content...

Implementors

Loading content...