HasTotalGetter

Trait HasTotalGetter 

Source
pub trait HasTotalGetter<S, A> {
    // Required method
    fn get(&self, source: &S) -> A;
}
Expand description

Provides a simplified interface for optics with infallible getter operations.

This trait is automatically implemented for any optic that implements HasGetter with a [GetterError] type of Infallible.

§Example

use optics::{HasTotalGetter, mapped_getter};

struct Point {
    x: u32,
    y: u32,
}

let x_getter = mapped_getter(
    |p: &Point| p.x,
);

let point = Point { x: 10, y: 20 };
let x_value = x_getter.get(&point); // x_value is 10

§See also:

HasGetter: base trait for optics that provides a potentially fallible getter operation.

Required Methods§

Source

fn get(&self, source: &S) -> A

Retrieves a value of type A from a source of type S.

§Parameters
  • source: A reference to the source of type S from which the value is to be retrieved.
§Returns

Returns the value of type A that the optic focuses on.

Implementors§

Source§

impl<S, A, T> HasTotalGetter<S, A> for T
where T: HasGetter<S, A, GetterError = Infallible>,