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]

[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);

[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);

[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);

[src]

Get the offset of target field.

[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);

[src]

Deprecated

: Use get instead

[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);

[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);

[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]

[src]

Returns a copy of the value. Read more

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]

[src]

Formats the value using the given formatter. Read more

impl<T, U> PartialEq for FieldRef<T, U>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

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]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

Auto Trait Implementations

impl<T, U> Send for FieldRef<T, U> where
    T: Send,
    U: Send

impl<T, U> Sync for FieldRef<T, U> where
    T: Sync,
    U: Sync