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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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