pub struct SBox<T: Sentinel, A: Allocator = Global> { /* private fields */ }Expand description
An allocated SSlice<T> instance.
Implementations§
source§impl<T: Sentinel, A: Allocator> SBox<T, A>
impl<T: Sentinel, A: Allocator> SBox<T, A>
sourcepub fn from_sslice_in(
slice: &SSlice<T>,
allocator: A
) -> Result<Self, AllocError>where
T: Clone,
pub fn from_sslice_in(
slice: &SSlice<T>,
allocator: A
) -> Result<Self, AllocError>where
T: Clone,
Clones the content of slice into a SBox<T>.
sourcepub unsafe fn from_slice_unchecked_in(
slice: &[T],
allocator: A
) -> Result<Self, AllocError>where
T: Clone,
pub unsafe fn from_slice_unchecked_in(
slice: &[T],
allocator: A
) -> Result<Self, AllocError>where
T: Clone,
sourcepub fn from_slice_in(slice: &[T], allocator: A) -> Result<Self, AllocError>where
T: Clone,
pub fn from_slice_in(slice: &[T], allocator: A) -> Result<Self, AllocError>where
T: Clone,
Creates a new SBox<T, A> from the provided slice.
If the slice contains a sentinel value, the procuded SBox<T> will only clone the values
up to that point. If the slice contains no sentinel value, a default sentinel value will
be used instead (see [DefaultSentinel]).
sourcepub fn into_raw_parts(b: SBox<T, A>) -> (*mut T, A)
pub fn into_raw_parts(b: SBox<T, A>) -> (*mut T, A)
Turns the provided SBox<T> into its raw representation.
The returned pointer can be used to re-construct a box using from_raw_parts.
source§impl<T: Sentinel> SBox<T, Global>
impl<T: Sentinel> SBox<T, Global>
sourcepub fn from_sslice(slice: &SSlice<T>) -> Result<Self, AllocError>where
T: Clone,
pub fn from_sslice(slice: &SSlice<T>) -> Result<Self, AllocError>where
T: Clone,
Clones the content of slice into a SBox<T>.
sourcepub fn from_slice(slice: &[T]) -> Result<Self, AllocError>where
T: Clone,
pub fn from_slice(slice: &[T]) -> Result<Self, AllocError>where
T: Clone,
Clones the content of slice into a SBox<T>.
If the provided slice contains a sentinel value, the produced box will contain values up to
that point. Otherwise, a default sentinel value will be used (see [DefaultSentinel]).
sourcepub unsafe fn from_box_unchecked(b: Box<[T]>) -> Self
pub unsafe fn from_box_unchecked(b: Box<[T]>) -> Self
Methods from Deref<Target = SSlice<T>>§
sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns a pointer to the first element that is part of the slice.
Notes
This pointer is always valid and will reference an initialized instance of T. Note,
however, that this value cannot be modified (even if it supports interior mutability). Or,
rather, if it is a sentinel, it must remain a sentinel.
sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Returns a pointer to the first element that is part of the slice.
Notes
This pointer is always valid and will reference an initialized instance of T. Note,
however, that this value cannot be modified. Or, rather, if it is a sentinel, it must
remain a sentinel.
sourcepub fn iter(&self) -> &Iter<T> ⓘ
pub fn iter(&self) -> &Iter<T> ⓘ
Returns an iterator over the elements of the slice.
Examples
let s = sentinel::cstr!("Hello!");
let mut iter = s.iter();
assert_eq!(iter.next(), Some(&b'H'));
assert_eq!(iter.next(), Some(&b'e'));
assert_eq!(iter.next(), Some(&b'l'));
assert_eq!(iter.next(), Some(&b'l'));
assert_eq!(iter.next(), Some(&b'o'));
assert_eq!(iter.next(), Some(&b'!'));
assert_eq!(iter.next(), None);sourcepub fn iter_mut(&mut self) -> &mut Iter<T> ⓘ
pub fn iter_mut(&mut self) -> &mut Iter<T> ⓘ
Returns an iterator over the elements of the slice.
Examples
let mut array = *b"abc\0";
let mut sslice = sentinel::SSlice::<u8>::from_slice_mut(&mut array).unwrap();
let mut iter = sslice.iter_mut();
*iter.next().unwrap() = b'1';
*iter.next().unwrap() = b'2';
*iter.next().unwrap() = b'3';
assert_eq!(sslice, b"123");sourcepub unsafe fn get_unchecked<Idx>(&self, index: Idx) -> &Idx::Outputwhere
Idx: SliceIndex<T>,
pub unsafe fn get_unchecked<Idx>(&self, index: Idx) -> &Idx::Outputwhere
Idx: SliceIndex<T>,
sourcepub unsafe fn get_unchecked_mut<Idx>(&mut self, index: Idx) -> &mut Idx::Outputwhere
Idx: SliceIndex<T>,
pub unsafe fn get_unchecked_mut<Idx>(&mut self, index: Idx) -> &mut Idx::Outputwhere
Idx: SliceIndex<T>,
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the slice is currently empty.
Examples
use sentinel::SSlice;
assert!(!SSlice::<u8>::from_slice(b"123\0").unwrap().is_empty());
assert!(SSlice::<u8>::from_slice(b"\0").unwrap().is_empty());sourcepub fn split_first(&self) -> Option<(&T, &Self)>
pub fn split_first(&self) -> Option<(&T, &Self)>
Returns a pointer to the first element of the slice, and a slice to the remaining elements.
None is returned if the slice is empty.
Examples
use sentinel::SSlice;
let sslice = SSlice::<u8>::from_slice(b"1234\0").unwrap();
let (first, remainder) = sslice.split_first().unwrap();
assert_eq!(*first, '1' as u8);
assert_eq!(remainder, b"234");sourcepub fn split_first_mut(&mut self) -> Option<(&mut T, &mut Self)>
pub fn split_first_mut(&mut self) -> Option<(&mut T, &mut Self)>
Returns a pointer to the first element of the slice, and a slice to the remaining elements.
None is returned if the slice is empty.
Examples
use sentinel::SSlice;
let mut array = *b"1234\0";
let mut sslice = SSlice::<u8>::from_slice_mut(&mut array).unwrap();
let (first, remainder) = sslice.split_first_mut().unwrap();
assert_eq!(*first, '1' as u8);
assert_eq!(remainder, b"234");
*first = 0;
assert!(sslice.is_empty());sourcepub unsafe fn raw_first(&self) -> &T
pub unsafe fn raw_first(&self) -> &T
Returns a shared reference to the first element of the slice, or a sentinel value if the slice is empty.
Safety
If the returned value is a sentinel, it must not be modified (or rather, it must remain a sentinel).
sourcepub unsafe fn raw_first_mut(&mut self) -> &mut T
pub unsafe fn raw_first_mut(&mut self) -> &mut T
Returns an exclusive reference to the first element of the slice, or a sentinel value if the slice is empty.
Safety
If the returned value is a sentinel, it must not be modified (or rather, it must remain a sentinel).
sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice referencing every element of this SSlice<T>, not including the
terminating sentinel character.
sourcepub fn as_slice_mut(&mut self) -> &mut [T]
pub fn as_slice_mut(&mut self) -> &mut [T]
Returns a slice referencing every element of this SSlice<T>, not including the
terminating sentinel character.
sourcepub fn as_slice_with_sentinel(&self) -> &[T]
pub fn as_slice_with_sentinel(&self) -> &[T]
Returns a slice referencing every element of this SSlice<T>, including the
terminating sentinel character.
sourcepub fn as_slice_with_sentinel_mut(&mut self) -> &mut [T]
pub fn as_slice_with_sentinel_mut(&mut self) -> &mut [T]
Returns a slice referencing every element of this SSlice<T>, including the
terminating sentinel character.
sourcepub fn as_std_cstr(&self) -> &CStr
pub fn as_std_cstr(&self) -> &CStr
Turns this SSlice<T> into a standard core::ffi::CStr.
sourcepub fn display(&self) -> &Display
pub fn display(&self) -> &Display
An implementation of fmt::Display and fmt::Debug for the CStr type.
When an invalid character is found, the REPLACEMENT_CHARACTER is displayed instead.
Trait Implementations§
source§impl<T: Sentinel, A: Allocator> BorrowMut<SSlice<T>> for SBox<T, A>
impl<T: Sentinel, A: Allocator> BorrowMut<SSlice<T>> for SBox<T, A>
source§fn borrow_mut(&mut self) -> &mut SSlice<T>
fn borrow_mut(&mut self) -> &mut SSlice<T>
source§impl<T: Sentinel> FromIterator<T> for SBox<T, Global>
impl<T: Sentinel> FromIterator<T> for SBox<T, Global>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a new SBox<T> from the values returned by the provided iterator. If a sentinel
value is returned, it is ignored.
source§impl<T, A> Ord for SBox<T, A>
impl<T, A> Ord for SBox<T, A>
source§impl<T, T2, A> PartialEq<SBox<T, A>> for [T2]
impl<T, T2, A> PartialEq<SBox<T, A>> for [T2]
source§impl<T, T2, A, const N: usize> PartialEq<SBox<T, A>> for [T2; N]
impl<T, T2, A, const N: usize> PartialEq<SBox<T, A>> for [T2; N]
source§impl<T, T2, A> PartialEq<SBox<T, A>> for SSlice<T2>
impl<T, T2, A> PartialEq<SBox<T, A>> for SSlice<T2>
source§impl<T, T2, A> PartialOrd<SBox<T, A>> for [T2]where
T: Sentinel,
A: Allocator,
T2: PartialOrd<T>,
impl<T, T2, A> PartialOrd<SBox<T, A>> for [T2]where
T: Sentinel,
A: Allocator,
T2: PartialOrd<T>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<T, T2, A, const N: usize> PartialOrd<SBox<T, A>> for [T2; N]where
T: Sentinel,
A: Allocator,
T2: PartialOrd<T>,
impl<T, T2, A, const N: usize> PartialOrd<SBox<T, A>> for [T2; N]where
T: Sentinel,
A: Allocator,
T2: PartialOrd<T>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<T, T2, A> PartialOrd<SBox<T, A>> for SSlice<T2>
impl<T, T2, A> PartialOrd<SBox<T, A>> for SSlice<T2>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<T, U, A> PartialOrd<U> for SBox<T, A>
impl<T, U, A> PartialOrd<U> for SBox<T, A>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more