pub trait Accessor<R>: Clone {
    type Value;
    fn value<'a>(&self, data: &'a R) -> &'a Self::Value;
}
Expand description

Something which returns a particular member of an instance by reference.

When Accessor is combined with the marker trait ReferenceField, you will automatically get a derivation of Field.

Example:

use django_query::ordering::{Accessor, Field, Compare, ReferenceField};
use core::cmp::Ordering;

struct Foo {
  a: i32
}

#[derive(Clone)]
struct FooA;

impl Accessor<Foo> for FooA {
    type Value = i32;
    fn value<'a>(&self, data: &'a Foo) -> &'a i32 {
       &data.a
    }
}

impl ReferenceField for FooA {}

let f_a = FooA;
let foo1 = Foo { a: 20 };
let foo2 = Foo { a: 10 };
assert_eq!(f_a.value(&foo1), &20i32);
assert_eq!(f_a.apply_sorter(&Compare, &foo1, &foo2), Ordering::Greater);

Associated Types

Required methods

Return a reference to a member of data

Implementors