1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crateHasReverseGet;
use Infallible;
/// Provides a simplified interface for optics with infallible reverse-get operations.
///
/// This trait is automatically implemented for any optic that implements
/// [`HasReverseGet`] with a [`ReverseError`] type of [`Infallible`] and
/// [`HasGetter`] with a [`GetterError`] type of [`Infallible`]
///
/// # Example
///
/// ```rust
/// use optics::{HasTotalReverseGet, mapped_iso};
///
/// #[derive(PartialEq, Debug)]
/// struct Point {
/// x: u16,
/// y: u16,
/// }
///
/// let point_iso = mapped_iso(
/// |p: &Point| (p.x as u32) << 16 + p.y as u32,
/// |v| Point { x: (v / (1<<16)) as u16 , y: (v % (1<<16)) as u16 },
/// );
///
/// let point = point_iso.reverse_get(&10);
/// assert_eq!(point, Point { x: 0, y: 10 });
/// ```
///
/// [`HasReverseGet`]: crate::HasReverseGet
/// [`ReverseError`]: crate::HasReverseGet::ReverseError
/// [`Infallible`]: std::convert::Infallible