Skip to main content

RefinedBrand

Struct RefinedBrand 

Source
pub struct RefinedBrand<A, B, E = String> { /* private fields */ }
Expand description

A branded constructor that validates the inner value at runtime.

Mirrors Effect.ts Brand.refined(refine, onFailure).

Implementations§

Source§

impl<A: Clone, B, E: Clone> RefinedBrand<A, B, E>

Source

pub fn new(refine: impl Fn(&A) -> Result<(), E> + Send + Sync + 'static) -> Self

Create a new refined brand constructor with a validation function.

refine returns Ok(()) when the value is valid, Err(e) otherwise.

Source

pub fn try_make(&self, value: A) -> Result<Brand<A, B>, E>

Try to brand value. Returns Ok(Brand<A,B>) or Err(E).

Source

pub fn make_option(&self, value: A) -> Option<Brand<A, B>>

Returns Some(Brand<A,B>) if valid, None otherwise.

Source

pub fn is(&self, value: &A) -> bool

Returns true if value would pass validation.

Auto Trait Implementations§

§

impl<A, B, E = String> !RefUnwindSafe for RefinedBrand<A, B, E>

§

impl<A, B, E = String> !UnwindSafe for RefinedBrand<A, B, E>

§

impl<A, B, E> Freeze for RefinedBrand<A, B, E>

§

impl<A, B, E> Send for RefinedBrand<A, B, E>
where B: Send,

§

impl<A, B, E> Sync for RefinedBrand<A, B, E>
where B: Sync,

§

impl<A, B, E> Unpin for RefinedBrand<A, B, E>
where B: Unpin,

§

impl<A, B, E> UnsafeUnpin for RefinedBrand<A, B, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Capability for T
where T: Send + Sync + 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pipe for T

Source§

fn pipe<F, R>(self, f: F) -> R
where F: FnOnce(Self) -> R,

Applies f to self (F#-style forward pipe).
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.