Skip to main content

Prism

Trait Prism 

Source
pub trait Prism<S, A> {
    // Required methods
    fn preview(&self, whole: &S) -> Option<A>;
    fn set_if(&self, whole: &mut S, part: A) -> bool;
}
Expand description

A prism for optional focusing (lens that may fail to view).

Unlike a lens, a prism’s preview returns Option<A> — the target may not exist. Useful for enum variants and optional fields.

Required Methods§

Source

fn preview(&self, whole: &S) -> Option<A>

Try to view the focused part. Returns None if the prism doesn’t match.

Source

fn set_if(&self, whole: &mut S, part: A) -> bool

Set the focused part if the prism matches. Returns true if applied.

Implementors§

Source§

impl<T: Clone> Prism<Option<T>, T> for SomePrism