Trait GetField

Source
pub trait GetField
where Self: Sized,
{ // Required methods fn get_field<T>(&self, fr: FieldRef<Self, T>) -> &T; fn try_get_field<'x, FR, T>(&'x self, fr: FR) -> Option<&'x T> where FR: OptionFieldRef<'x, Input = Self, Output = T>; }
Expand description

A trait to obtain a value to which FieldRef references via description like obj.get_field(field_ref).

Required Methods§

Source

fn get_field<T>(&self, fr: FieldRef<Self, T>) -> &T

§Examples
use field_ref::{GetField, field_ref_of};

struct Foo(u32, u32, f64);

let fr = field_ref_of!(Foo => 1);
let foo = Foo(10, 20, 0.5);
assert_eq!(foo.get_field(fr), &20);
Source

fn try_get_field<'x, FR, T>(&'x self, fr: FR) -> Option<&'x T>
where FR: OptionFieldRef<'x, Input = Self, Output = T>,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S: Sized> GetField for S