Struct refined_type::Refined

source ·
pub struct Refined<RULE>
where RULE: Rule,
{ /* private fields */ }
Expand description

Refined is a versatile type in ensuring that T satisfies the conditions of RULE (predicate type)

§Example

use refined_type::rule::{NonEmptyString, NonEmptyStringRule};
use refined_type::Refined;

let non_empty_string_result = Refined::<NonEmptyStringRule>::new("Hello World".to_string());
assert_eq!(non_empty_string_result.unwrap().into_value(), "Hello World");

let empty_string_result = Refined::<NonEmptyStringRule>::new("".to_string());
assert!(empty_string_result.is_err())

Implementations§

source§

impl<RULE, T> Refined<RULE>
where RULE: Rule<Item = T>,

source

pub fn new(value: T) -> Result<Self, Error>

source

pub fn unsafe_new(value: T) -> Self

source

pub fn value(&self) -> &RULE::Item

source

pub fn into_value(self) -> RULE::Item

source§

impl<K, V, S> Refined<Not<EmptyRule<HashMap<K, V, S>>>>

source

pub fn into_iter(self) -> NonEmpty<IntoIter<K, V>>

source

pub fn iter(&self) -> NonEmpty<Iter<'_, K, V>>

source

pub fn hasher(&self) -> &S

source

pub fn capacity(&self) -> usize

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn keys(&self) -> Keys<'_, K, V>

source

pub fn into_keys(self) -> IntoKeys<K, V>

source

pub fn values(&self) -> Values<'_, K, V>

source

pub fn into_values(self) -> IntoValues<K, V>

source§

impl<K, V, S> Refined<Not<EmptyRule<HashMap<K, V, S>>>>
where K: Eq + Hash, S: BuildHasher,

source

pub fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq,

source

pub fn insert(self, k: K, v: V) -> Self

source§

impl<T, S> Refined<Not<EmptyRule<HashSet<T, S>>>>

source

pub fn into_iter(self) -> NonEmpty<IntoIter<T>>

source

pub fn iter(&self) -> NonEmpty<Iter<'_, T>>

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn capacity(&self) -> usize

source

pub fn hasher(&self) -> &S

source§

impl<T, S> Refined<Not<EmptyRule<HashSet<T, S>>>>
where T: Eq + Hash, S: BuildHasher,

source

pub fn insert(self, value: T) -> Self

source

pub fn get<Q>(&self, value: &Q) -> Option<&T>
where T: Borrow<Q>, Q: Hash + Eq,

source

pub fn contains<Q>(&self, value: &Q) -> bool
where T: Borrow<Q>, Q: Hash + Eq,

source

pub fn difference<'a>( &'a self, other: &'a HashSet<T, S> ) -> Difference<'a, T, S>

source§

impl Refined<Not<EmptyRule<String>>>

source

pub fn insert(self, idx: usize, ch: char) -> Self

source

pub fn push(self, ch: char) -> Self

source

pub fn push_str(self, string: &str) -> Self

source

pub fn as_bytes(&self) -> NonEmptyVec<u8>

source

pub fn repeat(&self, n: usize) -> Self

source

pub fn to_ascii_lowercase(&self) -> Self

source

pub fn to_lowercase(&self) -> Self

source

pub fn to_ascii_uppercase(&self) -> Self

source

pub fn to_uppercase(&self) -> Self

source

pub fn capacity(&self) -> usize

source

pub fn len(&self) -> usize

source§

impl<T> Refined<Not<EmptyRule<Vec<T>>>>

source

pub fn into_iter(self) -> NonEmpty<IntoIter<T>>

source

pub fn iter(&self) -> NonEmpty<Iter<'_, T>>

source

pub fn get(&self, index: usize) -> Option<&T>

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn push(self, value: T) -> Self

source§

impl<T> Refined<Not<EmptyRule<VecDeque<T>>>>

source

pub fn into_iter(self) -> NonEmpty<IntoIter<T>>

source

pub fn iter(&self) -> NonEmpty<Iter<'_, T>>

source

pub fn get(&self, index: usize) -> Option<&T>

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn push_front(self, value: T) -> Self

source

pub fn push_back(self, value: T) -> Self

source§

impl<I: ExactSizeIterator + EmptyDefinition> Refined<Not<EmptyRule<I>>>

source

pub fn map<B, F>(self, f: F) -> Refined<NonEmptyRule<Map<I, F>>>
where Self: Sized, F: FnMut(I::Item) -> B,

source

pub fn collect<B: FromIterator<I::Item> + EmptyDefinition>(self) -> NonEmpty<B>
where Self: Sized,

Trait Implementations§

source§

impl<RULE> Debug for Refined<RULE>
where RULE: Rule + Debug, RULE::Item: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, RULE, T> Deserialize<'de> for Refined<RULE>
where RULE: Rule<Item = T>, T: Deserialize<'de>,

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<RULE, T> Display for Refined<RULE>
where RULE: Rule<Item = T>, T: Display,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<RULE> Ord for Refined<RULE>
where RULE: Rule + Ord, RULE::Item: Ord,

source§

fn cmp(&self, other: &Refined<RULE>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<RULE> PartialEq for Refined<RULE>
where RULE: Rule + PartialEq, RULE::Item: PartialEq,

source§

fn eq(&self, other: &Refined<RULE>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<RULE> PartialOrd for Refined<RULE>
where RULE: Rule + PartialOrd, RULE::Item: PartialOrd,

source§

fn partial_cmp(&self, other: &Refined<RULE>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<RULE, T> Serialize for Refined<RULE>
where RULE: Rule<Item = T>, T: Serialize,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<RULE> Eq for Refined<RULE>
where RULE: Rule + Eq, RULE::Item: Eq,

source§

impl<RULE> StructuralPartialEq for Refined<RULE>
where RULE: Rule,

Auto Trait Implementations§

§

impl<RULE> Freeze for Refined<RULE>
where <RULE as Rule>::Item: Freeze,

§

impl<RULE> RefUnwindSafe for Refined<RULE>
where <RULE as Rule>::Item: RefUnwindSafe, RULE: RefUnwindSafe,

§

impl<RULE> Send for Refined<RULE>
where <RULE as Rule>::Item: Send, RULE: Send,

§

impl<RULE> Sync for Refined<RULE>
where <RULE as Rule>::Item: Sync, RULE: Sync,

§

impl<RULE> Unpin for Refined<RULE>
where <RULE as Rule>::Item: Unpin, RULE: Unpin,

§

impl<RULE> UnwindSafe for Refined<RULE>
where <RULE as Rule>::Item: UnwindSafe, RULE: UnwindSafe,

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> 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,