ExactSize

Struct ExactSize 

Source
pub struct ExactSize<Tag> { /* private fields */ }
Expand description

The exact length separating slices and indices for a tag.

This serves as an constructor basis for ‘importing’ lengths and slices that are not previously connected through with_ref or equivalent constructors. This is also useful for cases where you want to create some bounds prior to the slice being available, or for creating bounds of custom tags.

Implementations§

Source§

impl<T> ExactSize<T>

The const methods for ExactSize.

Since trait bounds are not currently usable on stable the selection is limited. Note: It is of importance to soundness that it is not possible to construct an instance without the Tag bound. Otherwise, one might coerce into an ExactSize with an improper tag. This is not likely to be possible but nevertheless the Tag does not require it to be impossible.

Source

pub const unsafe fn new_untagged(len: usize, tag: T) -> Self

Construct a new bound between yet-to-create indices and slices.

§Safety

All ExactSize instances with the same tag type must also have the same len field.

Source

pub const unsafe fn from_len_untagged(bound: Prefix<T>) -> Self

Construct a new bound from a length.

§Safety

You must ensure that no slice with this same tag can be shorter than len. In particular there mustn’t be any other ExactSize with a differing length.

T should be a type implementing Tag but this can not be expressed with const fn atm.

Source

pub const fn get(&self) -> usize

Returns the length.

Source§

impl<'lt> ExactSize<Generative<'lt>>

Source

pub fn with_guard(len: usize, _: Guard<'lt>) -> Self

Construct a size with a generative guard.

The Guard instance is a token that verifies that no other instance with that particular lifetime exists. It is thus not possible to safely construct a second ExactSize with the same tag but a different length. This uniquely ties the value len to that lifetime.

FIXME: make this const fn which requires PhantomData<fn()> to be allowed in const context (a small subset of #57563).

Source§

impl<T: Tag> ExactSize<T>

Source

pub unsafe fn new(len: usize, tag: T) -> Self

Construct a new bound between yet-to-create indices and slices.

§Safety

All ExactSize instances with the same tag type must also have the same len field.

Source

pub unsafe fn from_len(len: Prefix<T>) -> Self

Construct a new bound from a length.

§Safety

You must ensure that no slice with this same tag can be shorter than len. In particular there mustn’t be any other ExactSize with a differing length.

Source

pub unsafe fn from_capacity(cap: Capacity<T>) -> Self

Construct a new bound from a capacity.

§Safety

You must ensure that no index with this same tag can be above cap. In particular there mustn’t be any other ExactSize with a differing length but the same tag type.

Source

pub fn with_tag<NewT>(self, equality: TagEq<T, NewT>) -> ExactSize<NewT>

Interpret this with the tag of an equal sized slice.

The proof of equality was performed in any of the possible constructors that allow the instance of TagEq to exist in the first place.

Source

pub fn into_len(self) -> Prefix<T>

Convert this into a simple Prefix without changing the length.

The Prefix is only required to be not longer than all slices but not required to have the exact separating size. As such, one can not use it to infer that some particular slice is long enough to be allowed. This is not safely reversible.

Source

pub fn into_capacity(self) -> Capacity<T>

Convert this into a simple Capacity without changing the length.

The Capacity is only required to be not shorter than all slices but not required to have the exact separating size. As such, one can use it only to infer that some particular slice is long enough to be allowed. This is not safely reversible.

Source

pub fn with_matching_pair(len: Prefix<T>, cap: Capacity<T>) -> Option<Self>

Construct a new bound from an pair of Prefix and Capacity with the same value.

Note that the invariant of ExactSize is that all Prefix are guaranteed to be at most the size and all Capacity are guaranteed to be at least the size. The only possible overlap between the two is the exact length, which we can dynamically check.

Trait Implementations§

Source§

impl<Tag: Clone> Clone for ExactSize<Tag>

Source§

fn clone(&self) -> ExactSize<Tag>

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<Tag: Copy> Copy for ExactSize<Tag>

Auto Trait Implementations§

§

impl<Tag> Freeze for ExactSize<Tag>
where Tag: Freeze,

§

impl<Tag> RefUnwindSafe for ExactSize<Tag>
where Tag: RefUnwindSafe,

§

impl<Tag> Send for ExactSize<Tag>
where Tag: Send,

§

impl<Tag> Sync for ExactSize<Tag>
where Tag: Sync,

§

impl<Tag> Unpin for ExactSize<Tag>
where Tag: Unpin,

§

impl<Tag> UnwindSafe for ExactSize<Tag>
where Tag: 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> 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, 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.