Struct MaybeStaticSlice

pub struct MaybeStaticSlice<T: 'static> { /* private fields */ }

A slice that is either 'static or on the heap.

This is useful for representing a sequence of data that can be either created at runtime and put on the heap (when dynamic memory allocation is needed), or when it needs to be constructed at compile time. For example, this is used to represent time zone transitions inside this crate's TZif representation.

The downside of this type is that T cannot contain any borrows.

This is similar to SmallStr, but there is no array-only variant. As such, this isn't intended for small data. (Indeed, time zone transitions can get pretty long.) This also makes the API simpler: all constructors are infallible.

Implementations

impl<T: 'static> MaybeStaticSlice<T>

const fn statik(data: &'static [T]) -> MaybeStaticSlice<T>

Creates a new static slice from the data provided.

const fn heap(data: Box<[T]>) -> MaybeStaticSlice<T>

Creates a new slice on the heap from the data provided.

const fn as_slice(&self) -> &[T]

Returns the underlying data as a slice.

Trait Implementations

impl<T: 'static> Deref for MaybeStaticSlice<T>

type Target = [T];
fn deref(&self) -> &[T]

impl<T: 'static> From<&'static [T]> for MaybeStaticSlice<T>

fn from(data: &'static [T]) -> MaybeStaticSlice<T>

impl<T: 'static> From<Box<[T]>> for MaybeStaticSlice<T>

fn from(data: Box<[T]>) -> MaybeStaticSlice<T>

impl<T: Clone + 'static> Clone for MaybeStaticSlice<T>

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

impl<T: Debug + 'static> Debug for MaybeStaticSlice<T>

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

impl<T: Eq + 'static> Eq for MaybeStaticSlice<T>

impl<T: PartialEq + 'static> PartialEq for MaybeStaticSlice<T>

fn eq(&self, other: &MaybeStaticSlice<T>) -> bool

impl<T: PartialEq + 'static> StructuralPartialEq for MaybeStaticSlice<T>

Auto Trait Implementations

impl<T> Freeze for MaybeStaticSlice<T> where MaybeStaticSliceKind<T>: Freeze,

impl<T> RefUnwindSafe for MaybeStaticSlice<T> where MaybeStaticSliceKind<T>: RefUnwindSafe,

impl<T> Send for MaybeStaticSlice<T> where MaybeStaticSliceKind<T>: Send,

impl<T> Sync for MaybeStaticSlice<T> where MaybeStaticSliceKind<T>: Sync,

impl<T> Unpin for MaybeStaticSlice<T> where MaybeStaticSliceKind<T>: Unpin,

impl<T> UnsafeUnpin for MaybeStaticSlice<T> where MaybeStaticSliceKind<T>: UnsafeUnpin,

impl<T> UnwindSafe for MaybeStaticSlice<T> where MaybeStaticSliceKind<T>: UnwindSafe,

Blanket Implementations

impl<P, T> Receiver for MaybeStaticSlice<T> where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

impl<T> Any for MaybeStaticSlice<T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for MaybeStaticSlice<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for MaybeStaticSlice<T> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for MaybeStaticSlice<T> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for MaybeStaticSlice<T>

fn from(t: T) -> T

Returns the argument unchanged.

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for MaybeStaticSlice<T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for MaybeStaticSlice<T> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for MaybeStaticSlice<T> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>