Skip to main content

Specified

Struct Specified 

Source
pub struct Specified<T> { /* private fields */ }
Expand description

Specified value.

This data type is a thin wrapper around a value of type T, augmenting the value with its computed Specificity, so it can be efficiently ordered.

Note that specifities are ordered from lowest to highest, with the least specific value being the first in order. It would be natural to reverse this order, but this would lead to more complex implementations for when a specified value is wrapped in an Option.

Implementations§

Source§

impl<T> Specified<T>

Source

pub fn into_inner(self) -> T

Returns the inner value, consuming the specified value.

§Examples
use zrx_id::selector;
use zrx_id::specificity::Specified;

// Create selector
let selector = selector!(location = "**/*.md")?;

// Create specified value from selector
let value = Specified::from(selector.clone());
assert_eq!(value.into_inner(), selector);
Source§

impl<T> Specified<T>

Source

pub fn specificity(&self) -> Specificity

Returns the specificity.

Trait Implementations§

Source§

impl<T: Clone> Clone for Specified<T>

Source§

fn clone(&self) -> Specified<T>

Returns a duplicate 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<T: Debug> Debug for Specified<T>

Source§

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

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

impl<T: Default> Default for Specified<T>

Source§

fn default() -> Specified<T>

Returns the “default value” for a type. Read more
Source§

impl<T> Deref for Specified<T>

Source§

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

Dereferences to the inner value.

Source§

type Target = T

The resulting type after dereferencing.
Source§

impl<T> From<T> for Specified<T>
where T: ToSpecificity,

Source§

fn from(inner: T) -> Self

Creates a specified value from a value.

§Examples
use zrx_id::selector;
use zrx_id::specificity::Specified;

// Create selector
let selector = selector!(location = "**/*.md")?;

// Create specified value from selector
let value = Specified::from(selector);
assert_eq!(value.specificity(), (0, 1, 1, 3).into());
Source§

impl<T> Ord for Specified<T>
where T: Eq,

Source§

fn cmp(&self, other: &Self) -> Ordering

Orders two values by specificity.

§Examples
use zrx_id::selector;
use zrx_id::specificity::Specified;

// Create and compare selectors by specificity
let a = Specified::from(selector!(location = "**/*.md")?);
let b = Specified::from(selector!(location = "*.md")?);
assert!(a < b);
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<T> PartialEq for Specified<T>
where T: PartialEq,

Source§

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

Compares two specified values for equality.

§Examples
use zrx_id::selector;
use zrx_id::specificity::Specified;

// Create and compare selectors
let a = Specified::from(selector!(location = "*.md")?);
let b = Specified::from(selector!(location = "*.md")?);
assert_eq!(a, b);
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<T> PartialOrd for Specified<T>
where T: Eq,

Source§

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

Orders two values by specificity.

§Examples
use zrx_id::selector;
use zrx_id::specificity::Specified;

// Create and compare selectors by specificity
let a = Specified::from(selector!(location = "**/*.md")?);
let b = Specified::from(selector!(location = "*.md")?);
assert!(a < b);
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<T> Eq for Specified<T>
where T: Eq,

Auto Trait Implementations§

§

impl<T> Freeze for Specified<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Specified<T>
where T: RefUnwindSafe,

§

impl<T> Send for Specified<T>
where T: Send,

§

impl<T> Sync for Specified<T>
where T: Sync,

§

impl<T> Unpin for Specified<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Specified<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Specified<T>
where T: 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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<K, V> TryAsStorage<K> for V
where K: Key, V: Value,

Source§

fn try_as_storage( item: &(dyn Any + 'static), ) -> Result<<V as TryAsStorage<K>>::Target<'_>, Error>

Attempts to convert into a storage reference.

§Errors

The following errors might be returned:

§Examples
use std::any::Any;
use zrx_storage::convert::TryAsStorage;
use zrx_storage::Storage;

// Create storage and initial state
let mut storage = Storage::default();
storage.insert("key", 42);

// Obtain type-erased reference
let item: &dyn Any = &storage;

// Obtain storage reference
let storage = <i32>::try_as_storage(item)?;
Source§

type Target<'a> = &'a Storage<K, V>

Target type of conversion.
Source§

impl<K, V> TryAsStorageMut<K> for V
where K: Key, V: Value,

Source§

fn try_as_storage_mut( item: &mut (dyn Any + 'static), ) -> Result<<V as TryAsStorageMut<K>>::Target<'_>, Error>

Attempts to convert into a mutable storage reference.

§Errors

The following errors might be returned:

§Examples
use std::any::Any;
use zrx_storage::convert::TryAsStorageMut;
use zrx_storage::Storage;

// Create storage and initial state
let mut storage = Storage::default();
storage.insert("key", 42);

// Obtain mutable type-erased reference
let item: &mut dyn Any = &mut storage;

// Obtain mutable storage reference
let storage = <i32>::try_as_storage_mut(item)?;
Source§

type Target<'a> = &'a mut Storage<K, V>

Target type of conversion.
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.
Source§

impl<T> Value for T
where T: Debug + Eq + 'static,