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.
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.
Sourcepub const unsafe fn new_untagged(len: usize, tag: T) -> Self
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.
Sourcepub const unsafe fn from_len_untagged(bound: Prefix<T>) -> Self
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§impl<'lt> ExactSize<Generative<'lt>>
impl<'lt> ExactSize<Generative<'lt>>
Sourcepub fn with_guard(len: usize, _: Guard<'lt>) -> Self
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>
impl<T: Tag> ExactSize<T>
Sourcepub unsafe fn new(len: usize, tag: T) -> Self
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.
Sourcepub unsafe fn from_len(len: Prefix<T>) -> Self
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.
Sourcepub unsafe fn from_capacity(cap: Capacity<T>) -> Self
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.
Sourcepub fn with_tag<NewT>(self, equality: TagEq<T, NewT>) -> ExactSize<NewT>
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.
Sourcepub fn into_len(self) -> Prefix<T>
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.
Sourcepub fn into_capacity(self) -> Capacity<T>
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.
Sourcepub fn with_matching_pair(len: Prefix<T>, cap: Capacity<T>) -> Option<Self>
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.