Struct field_ref::FieldRef
[−]
[src]
pub struct FieldRef<T, U> { /* fields omitted */ }
A reference to field of type U
(recursively) contained by an object of type T
.
Methods
impl<T, U> FieldRef<T, U>
[src]
pub unsafe fn from_offset(offset: usize) -> Self
[src]
Creates a new FieldRef
with offset bytes from the first byte of an object of type T
.
Examples
#[macro_use] extern crate field_ref; use field_ref::FieldRef; #[repr(C)] struct Foo(u32, u32); // references Foo.1 let fr = unsafe { FieldRef::<Foo, u32>::from_offset(4) }; let foo = Foo(10, 20); assert_eq!(fr.get(&foo), &20);
pub unsafe fn from_pointers(obj: *const T, field: *const U) -> Self
[src]
Creates a new FieldRef
from a reference to concrete object of type T
and a reference to concrete field of type U
.
Examples
extern crate field_ref; use field_ref::FieldRef; struct Foo(u32, u32, f64); let foo1 = Foo(10, 20, 0.5); let foo2 = Foo(30, 40, 1.5); let fr = unsafe { FieldRef::from_pointers(&foo1, &foo1.1) }; assert_eq!(fr.get(&foo2), &40);
pub unsafe fn from_references(obj: &T, field: &U) -> Self
[src]
Creates a new FieldRef
from a pointer to concrete object of type T
and a pointer to concrete field of type U
.
Examples
extern crate field_ref; use field_ref::FieldRef; struct Foo(u32, u32, f64); let foo1 = Foo(10, 20, 0.5); let foo2 = Foo(30, 40, 1.5); let fr = unsafe { FieldRef::from_references(&foo1, &foo1.1) }; assert_eq!(fr.get(&foo2), &40);
pub fn offset(&self) -> usize
[src]
Get the offset of target field.
pub fn get<'a, 'b>(&'a self, obj: &'b T) -> &'b U
[src]
Get a reference of value in an object to which FieldRef
refers.
Examples
#[macro_use] extern crate field_ref; struct Foo(u32, u32, f64); let fr = field_ref_of!(Foo => 1); let foo = Foo(10, 20, 0.5); assert_eq!(fr.get(&foo), &20);
pub fn get_ref<'a, 'b>(&'a self, obj: &'b T) -> &'b U
[src]
: Use get
instead
pub fn get_mut<'a, 'b>(&'a self, obj: &'b mut T) -> &'b mut U
[src]
Get a mutable reference of value in an object to which FieldRef
refers.
Examples
#[macro_use] extern crate field_ref; struct Foo(u32, u32, f64); let fr = field_ref_of!(Foo => 1); let mut foo = Foo(10, 20, 0.5); *fr.get_mut(&mut foo) = 30; assert_eq!(foo.1, 30);
pub fn chain<V>(&self, fr: FieldRef<U, V>) -> FieldRef<T, V>
[src]
Chains two field references.
Examples
#[macro_use] extern crate field_ref; struct Foo(u32, u32, f64); struct Bar { foo: Foo, x: u32, } let fr1 = field_ref_of!(Bar => foo); let fr2 = field_ref_of!(Foo => 1); let bar = Bar { foo: Foo(10, 20, 0.5), x: 30 }; assert_eq!(fr1.chain(fr2).get(&bar), &20);
pub fn as_opt_field_ref(&self) -> FieldRefAsOptionFieldRef<T, U>
[src]
Convert FieldRef<T, U>
into an instance of trait OptionFieldRef<'x, Input = T, Output = U>
.
Trait Implementations
impl<T, U> Clone for FieldRef<T, U>
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T, U> Copy for FieldRef<T, U>
[src]
impl<T, U> Debug for FieldRef<T, U>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl<T, U> PartialEq for FieldRef<T, U>
[src]
fn eq(&self, other: &Self) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T, U> Eq for FieldRef<T, U>
[src]
impl<T, U> PartialOrd for FieldRef<T, U>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T, U> Ord for FieldRef<T, U>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more