strck

Struct Check

source
#[repr(transparent)]
pub struct Check<I: Invariant, B: AsRef<str> + 'static = String> { pub(crate) _marker: PhantomData<I>, pub(crate) buf: B, }
Expand description

Owned immutable string with invariants.

Similar to how String derefs to &str, Check derefs to &Ck. This means APIs requiring &Check<I> as an argument should instead consider accepting &Ck<I> for more flexibility.

§Buffers

By default, this type is backed by a String, but it can also be backed by any AsRef<str> + 'static type. In particular, types like SmolStr are good candidates since they’re designed to be immutable.

It’s recommended to use a type alias when using a custom backing type, since extra generics can make the type signature long.

Fields§

§_marker: PhantomData<I>§buf: B

Implementations§

source§

impl<I: Invariant, B: AsRef<str>> Check<I, B>

source

pub fn from_buf(buf: B) -> Result<Self, I::Error>

Returns an Ok if the buffer upholds the invariants, otherwise Err.

source

pub unsafe fn from_buf_unchecked(buf: B) -> Self

Create a new Check without validating the buffer.

§Safety

The buffer must contain a valid string.

source

pub fn as_ck(&self) -> &Ck<I>

Returns a &Ck that borrows from self.

source

pub fn into_inner(self) -> B

Returns the inner representation.

Methods from Deref<Target = Ck<I>>§

source

pub fn to_check<'a, B>(&'a self) -> Check<I, B>
where B: AsRef<str> + From<&'a str>,

Returns an owned Check from &self.

source

pub fn as_str(&self) -> &str

Returns the &str representation.

Trait Implementations§

source§

impl<I: Invariant, B: AsRef<str>> AsRef<Ck<I>> for Check<I, B>

source§

fn as_ref(&self) -> &Ck<I>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<I: Invariant, B: AsRef<str>> AsRef<str> for Check<I, B>

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<I: Invariant, B: AsRef<str>> Borrow<Ck<I>> for Check<I, B>

source§

fn borrow(&self) -> &Ck<I>

Immutably borrows from an owned value. Read more
source§

impl<I: Clone + Invariant, B: Clone + AsRef<str> + 'static> Clone for Check<I, B>

source§

fn clone(&self) -> Check<I, B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<I, B> Debug for Check<I, B>
where I: Invariant, B: AsRef<str> + Debug,

source§

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

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

impl<I: Invariant, B: AsRef<str>> Deref for Check<I, B>

source§

type Target = Ck<I>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<I: Invariant, B: AsRef<str>> Display for Check<I, B>

source§

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

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

impl<'a, I: Invariant, B: AsRef<str>> From<&'a Check<I, B>> for &'a Ck<I>

source§

fn from(check: &'a Check<I, B>) -> Self

Converts to this type from the input type.
source§

impl<'a, I, B> From<&'a Ck<I>> for Check<I, B>
where I: Invariant, B: AsRef<str> + From<&'a str>,

source§

fn from(check: &'a Ck<I>) -> Self

Converts to this type from the input type.
source§

impl<I, B> FromStr for Check<I, B>
where I: Invariant, for<'a> B: AsRef<str> + From<&'a str>,

source§

type Err = <I as Invariant>::Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<I: Invariant, B: AsRef<str>> Hash for Check<I, B>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<I: Invariant, B: AsRef<str>> Ord for Check<I, B>

source§

fn cmp(&self, other: &Self) -> 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,

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<&'a Check<I, B>> for Ck<I>

source§

fn eq(&self, other: &&'a Check<I, B>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<&'a Check<I, B>> for String

source§

fn eq(&self, other: &&'a Check<I, B>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<&'a Check<I, B>> for str

source§

fn eq(&self, other: &&'a Check<I, B>) -> bool

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

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

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

impl<'a, I, B1, B2> PartialEq<&'a Check<I, B2>> for Check<I, B1>
where I: Invariant, B1: AsRef<str>, B2: AsRef<str>,

source§

fn eq(&self, other: &&'a Check<I, B2>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<&'a Ck<I>> for Check<I, B>

source§

fn eq(&self, other: &&'a Ck<I>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<&'a String> for Check<I, B>

source§

fn eq(&self, other: &&'a String) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<&'a str> for Check<I, B>

source§

fn eq(&self, other: &&'a str) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<Check<I, B>> for &'a Ck<I>

source§

fn eq(&self, other: &Check<I, B>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<Check<I, B>> for &'a String

source§

fn eq(&self, other: &Check<I, B>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<Check<I, B>> for &'a str

source§

fn eq(&self, other: &Check<I, B>) -> bool

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

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

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

impl<I: Invariant, B: AsRef<str>> PartialEq<Check<I, B>> for Ck<I>

source§

fn eq(&self, other: &Check<I, B>) -> bool

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

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

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

impl<I: Invariant, B: AsRef<str>> PartialEq<Check<I, B>> for String

source§

fn eq(&self, other: &Check<I, B>) -> bool

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

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

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

impl<I: Invariant, B: AsRef<str>> PartialEq<Check<I, B>> for str

source§

fn eq(&self, other: &Check<I, B>) -> bool

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

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

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

impl<'a, I, B1, B2> PartialEq<Check<I, B2>> for &'a Check<I, B1>
where I: Invariant, B1: AsRef<str>, B2: AsRef<str>,

source§

fn eq(&self, other: &Check<I, B2>) -> bool

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

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

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

impl<I, B1, B2> PartialEq<Check<I, B2>> for Check<I, B1>
where I: Invariant, B1: AsRef<str>, B2: AsRef<str>,

source§

fn eq(&self, other: &Check<I, B2>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<Ck<I>> for &'a Check<I, B>

source§

fn eq(&self, other: &Ck<I>) -> bool

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

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

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

impl<I: Invariant, B: AsRef<str>> PartialEq<Ck<I>> for Check<I, B>

source§

fn eq(&self, other: &Ck<I>) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<String> for &'a Check<I, B>

source§

fn eq(&self, other: &String) -> bool

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

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

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

impl<I: Invariant, B: AsRef<str>> PartialEq<String> for Check<I, B>

source§

fn eq(&self, other: &String) -> bool

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

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

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

impl<'a, I: Invariant, B: AsRef<str>> PartialEq<str> for &'a Check<I, B>

source§

fn eq(&self, other: &str) -> bool

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

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

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

impl<I: Invariant, B: AsRef<str>> PartialEq<str> for Check<I, B>

source§

fn eq(&self, other: &str) -> bool

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

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

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

impl<I, B1, B2> PartialOrd<Check<I, B2>> for Check<I, B1>
where I: Invariant, B1: AsRef<str>, B2: AsRef<str>,

source§

fn partial_cmp(&self, other: &Check<I, B2>) -> 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

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

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

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

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

impl<I: Invariant, B: AsRef<str>> Eq for Check<I, B>

Auto Trait Implementations§

§

impl<I, B> Freeze for Check<I, B>
where B: Freeze,

§

impl<I, B> RefUnwindSafe for Check<I, B>

§

impl<I, B> Send for Check<I, B>
where B: Send, I: Send,

§

impl<I, B> Sync for Check<I, B>
where B: Sync, I: Sync,

§

impl<I, B> Unpin for Check<I, B>
where B: Unpin, I: Unpin,

§

impl<I, B> UnwindSafe for Check<I, B>
where B: UnwindSafe, I: 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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoCheck for T
where T: AsRef<str> + 'static,

source§

fn check<I>(self) -> Result<Check<I, T>, <I as Invariant>::Error>
where I: Invariant,

Returns a validated Check owning self. Read more
source§

impl<T> IntoCk for T
where T: AsRef<str>,

source§

fn ck<I>(&self) -> Result<&Ck<I>, <I as Invariant>::Error>
where I: Invariant,

Returns a validated Ck borrowing from self. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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>,

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.