pub struct Stack<T, const CAP: usize, IDX, S: Storage = Bare> { /* private fields */ }
Expand description
A static stack backed by an Array
.
It is generic in respect to its
elements (T
),
capacity (CAP
),
index size (IDX
)
and storage (S
).
The index size will upper-bound the capacity to the maximum for that type,
e.g. u8::MAX
for StackU8
.
The index size determines the maximum possible number of elements in the stack,
thereby upper-bounding the capacity to the maximum value representable by the
index type. For example, u8::MAX
for StackU8
.
The total size in bytes of the stack may be influenced by the chosen index size, depending on the size and alignment of the elements. This difference could only be significant for small capacities, as only one index is stored.
See also the related aliases that specify IDX
:
StackU8
, StackU16
, StackU32
, StackUsize
,
and the DataStack
trait.
§Methods
All the stack operations are done from the back.
The methods are the same for all IDX
sizes:
The following list of methods links to the ones implemented for StackU8
:
-
Construct:
new
,new_copied
,from_array
(copy
). -
Deconstruct:
to_array
,to_vec
(alloc
).as_slice
,as_mut_slice
, -
Query:
len
,is_empty
,is_full
,capacity
,remaining_capacity
,contains
. -
Resize:
resize_default
(own),resize_default_truncate
(own). -
Convert:
to_idx_u8
(own),to_idx_u16
(own),to_idx_u32
(own),to_idx_usize
(own). -
Stack operations without bounds on
T
: -
Stack chainable const operations depending on
T: Copy
.- clear:
own_clear
. - push:
own_push
(uc), - pop:
own_pop
(uc). - drop:
own_drop
(uc),own_drop_n
(uc). - nip:
own_nip
(uc),own_nip2
(uc). - swap:
own_swap
(uc),own_swap2
(uc). - rot:
own_rot
(uc),own_rot_cc
(uc),own_rot2
(uc),own_rot2_cc
(uc). - dup:
own_dup
(uc),own_dup2
(uc). - over:
own_over
(uc),own_over2
(uc). - tuck:
own_tuck
(uc),own_tuck2
(uc).
- clear:
Implementations§
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, u8, Bare>
§Stack resize.
impl<T: Default, const CAP: usize> Stack<T, CAP, u8, Bare>
§Stack resize.
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, u8, Bare>, IndexOutOfBounds> ⓘ
Available on crate feature _stack_u8
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, u8, Bare>, IndexOutOfBounds> ⓘ
_stack_u8
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU8::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackU8::<_, 4> = s.resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackU8::<_, 12> = s.resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, u8, Bare>
Available on crate feature _stack_u8
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, u8, Bare>
_stack_u8
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackU8::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackU8::<_, 4> = s.resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackU8::<_, 12> = s.resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackU8::<_, 2> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, u8, Boxed>
impl<T: Default, const CAP: usize> Stack<T, CAP, u8, Boxed>
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, u8, Boxed>, IndexOutOfBounds> ⓘ
Available on crate features alloc
and _stack_u8
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, u8, Boxed>, IndexOutOfBounds> ⓘ
alloc
and _stack_u8
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU8::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackU8::<_, 4, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackU8::<_, 12, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, u8, Boxed>
Available on crate features alloc
and _stack_u8
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, u8, Boxed>
alloc
and _stack_u8
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackU8::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackU8::<_, 4, Boxed> = s.clone().resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackU8::<_, 12, Boxed> = s.clone().resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackU8::<_, 2, Boxed> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
Sourcepub const fn own_resize_default<const NEW_CAP: usize>(
self,
) -> Own<Result<Stack<T, NEW_CAP, u8, Bare>, IndexOutOfBounds>, ()>
Available on crate feature _stack_u8
only.
pub const fn own_resize_default<const NEW_CAP: usize>( self, ) -> Own<Result<Stack<T, NEW_CAP, u8, Bare>, IndexOutOfBounds>, ()>
_stack_u8
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU8<i32, 8> = StackU8::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU8<i32, 4> = S.own_resize_default().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
let _ = S.own_resize_default::<2>().s_assert_err(); // too small
Sourcepub const fn own_resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Own<Stack<T, NEW_CAP, u8, Bare>, ()>
Available on crate feature _stack_u8
only.
pub const fn own_resize_default_truncate<const NEW_CAP: usize>( self, ) -> Own<Stack<T, NEW_CAP, u8, Bare>, ()>
_stack_u8
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
const S: StackU8<i32, 8> = StackU8::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU8<i32, 4> = S.own_resize_default_truncate().s;
assert_eq![S.as_slice(), T.as_slice()];
const U: StackU8<i32, 2> = S.own_resize_default_truncate().s;
assert_eq![U.as_slice(), &[2, 3]];
Source§impl<T, const CAP: usize> Stack<T, CAP, u8, Bare>
§Stack index-size conversion.
impl<T, const CAP: usize> Stack<T, CAP, u8, Bare>
§Stack index-size conversion.
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
Available on crate feature _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
_stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackU8::<_, 6>::from([1, 2, 3, 4]);
let t: StackU8::<_, 6> = s.to_idx_u8().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u8
and _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
_stack_u8
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackU8::<_, 6>::from([1, 2, 3, 4]);
let t: StackU16::<_, 6> = s.to_idx_u16().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u8
and _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
_stack_u8
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackU8::<_, 6>::from([1, 2, 3, 4]);
let t: StackU32::<_, 6> = s.to_idx_u32().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u8
and _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
_stack_u8
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackU8::<_, 6>::from([1, 2, 3, 4]);
let t: StackUsize::<_, 6> = s.to_idx_usize().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Source§impl<T, const CAP: usize> Stack<T, CAP, u8, Boxed>
impl<T, const CAP: usize> Stack<T, CAP, u8, Boxed>
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackU8::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU8::<_, 6, Boxed> = s.to_idx_u8().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u8
and _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u8
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackU8::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU16::<_, 6, Boxed> = s.to_idx_u16().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u8
and _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u8
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackU8::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU32::<_, 6, Boxed> = s.to_idx_u32().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u8
and _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u8
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackU8::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackUsize::<_, 6, Boxed> = s.to_idx_usize().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
Sourcepub const fn own_to_idx_u8(
self,
) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
Available on crate feature _stack_u8
only.
pub const fn own_to_idx_u8( self, ) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
_stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
const S: StackU8<i32, 6> = StackU8::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU8<i32, 6> = S.own_to_idx_u8().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u16(
self,
) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u8
and _stack_u16
only.
pub const fn own_to_idx_u16( self, ) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
_stack_u8
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
const S: StackU8<i32, 6> = StackU8::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU16<i32, 6> = S.own_to_idx_u16().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u32(
self,
) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u8
and _stack_u32
only.
pub const fn own_to_idx_u32( self, ) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
_stack_u8
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
const S: StackU8<i32, 6> = StackU8::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU32<i32, 6> = S.own_to_idx_u32().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_usize(
self,
) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u8
and _stack_usize
only.
pub const fn own_to_idx_usize( self, ) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
_stack_u8
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
const S: StackU8<i32, 6> = StackU8::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackUsize<i32, 6> = S.own_to_idx_usize().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, u16, Bare>
§Stack resize.
impl<T: Default, const CAP: usize> Stack<T, CAP, u16, Bare>
§Stack resize.
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, u16, Bare>, IndexOutOfBounds> ⓘ
Available on crate feature _stack_u16
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, u16, Bare>, IndexOutOfBounds> ⓘ
_stack_u16
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u16::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU16::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackU16::<_, 4> = s.resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackU16::<_, 12> = s.resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, u16, Bare>
Available on crate feature _stack_u16
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, u16, Bare>
_stack_u16
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackU16::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackU16::<_, 4> = s.resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackU16::<_, 12> = s.resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackU16::<_, 2> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, u16, Boxed>
impl<T: Default, const CAP: usize> Stack<T, CAP, u16, Boxed>
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, u16, Boxed>, IndexOutOfBounds> ⓘ
Available on crate features alloc
and _stack_u16
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, u16, Boxed>, IndexOutOfBounds> ⓘ
alloc
and _stack_u16
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u16::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU16::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackU16::<_, 4, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackU16::<_, 12, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, u16, Boxed>
Available on crate features alloc
and _stack_u16
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, u16, Boxed>
alloc
and _stack_u16
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackU16::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackU16::<_, 4, Boxed> = s.clone().resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackU16::<_, 12, Boxed> = s.clone().resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackU16::<_, 2, Boxed> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
Sourcepub const fn own_resize_default<const NEW_CAP: usize>(
self,
) -> Own<Result<Stack<T, NEW_CAP, u16, Bare>, IndexOutOfBounds>, ()>
Available on crate feature _stack_u16
only.
pub const fn own_resize_default<const NEW_CAP: usize>( self, ) -> Own<Result<Stack<T, NEW_CAP, u16, Bare>, IndexOutOfBounds>, ()>
_stack_u16
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u16::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU16<i32, 8> = StackU16::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU16<i32, 4> = S.own_resize_default().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
let _ = S.own_resize_default::<2>().s_assert_err(); // too small
Sourcepub const fn own_resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Own<Stack<T, NEW_CAP, u16, Bare>, ()>
Available on crate feature _stack_u16
only.
pub const fn own_resize_default_truncate<const NEW_CAP: usize>( self, ) -> Own<Stack<T, NEW_CAP, u16, Bare>, ()>
_stack_u16
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
const S: StackU16<i32, 8> = StackU16::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU16<i32, 4> = S.own_resize_default_truncate().s;
assert_eq![S.as_slice(), T.as_slice()];
const U: StackU16<i32, 2> = S.own_resize_default_truncate().s;
assert_eq![U.as_slice(), &[2, 3]];
Source§impl<T, const CAP: usize> Stack<T, CAP, u16, Bare>
§Stack index-size conversion.
impl<T, const CAP: usize> Stack<T, CAP, u16, Bare>
§Stack index-size conversion.
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u16
and _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
_stack_u16
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackU16::<_, 6>::from([1, 2, 3, 4]);
let t: StackU8::<_, 6> = s.to_idx_u8().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
Available on crate feature _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
_stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackU16::<_, 6>::from([1, 2, 3, 4]);
let t: StackU16::<_, 6> = s.to_idx_u16().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u16
and _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
_stack_u16
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackU16::<_, 6>::from([1, 2, 3, 4]);
let t: StackU32::<_, 6> = s.to_idx_u32().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u16
and _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
_stack_u16
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackU16::<_, 6>::from([1, 2, 3, 4]);
let t: StackUsize::<_, 6> = s.to_idx_usize().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Source§impl<T, const CAP: usize> Stack<T, CAP, u16, Boxed>
impl<T, const CAP: usize> Stack<T, CAP, u16, Boxed>
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u16
and _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u16
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackU16::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU8::<_, 6, Boxed> = s.to_idx_u8().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackU16::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU16::<_, 6, Boxed> = s.to_idx_u16().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u16
and _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u16
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackU16::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU32::<_, 6, Boxed> = s.to_idx_u32().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u16
and _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u16
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackU16::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackUsize::<_, 6, Boxed> = s.to_idx_usize().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
Sourcepub const fn own_to_idx_u8(
self,
) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u16
and _stack_u8
only.
pub const fn own_to_idx_u8( self, ) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
_stack_u16
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
const S: StackU16<i32, 6> = StackU16::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU8<i32, 6> = S.own_to_idx_u8().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u16(
self,
) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
Available on crate feature _stack_u16
only.
pub const fn own_to_idx_u16( self, ) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
_stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
const S: StackU16<i32, 6> = StackU16::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU16<i32, 6> = S.own_to_idx_u16().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u32(
self,
) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u16
and _stack_u32
only.
pub const fn own_to_idx_u32( self, ) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
_stack_u16
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
const S: StackU16<i32, 6> = StackU16::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU32<i32, 6> = S.own_to_idx_u32().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_usize(
self,
) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u16
and _stack_usize
only.
pub const fn own_to_idx_usize( self, ) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
_stack_u16
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
const S: StackU16<i32, 6> = StackU16::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackUsize<i32, 6> = S.own_to_idx_usize().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, u32, Bare>
§Stack resize.
impl<T: Default, const CAP: usize> Stack<T, CAP, u32, Bare>
§Stack resize.
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, u32, Bare>, IndexOutOfBounds> ⓘ
Available on crate feature _stack_u32
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, u32, Bare>, IndexOutOfBounds> ⓘ
_stack_u32
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u32::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU32::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackU32::<_, 4> = s.resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackU32::<_, 12> = s.resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, u32, Bare>
Available on crate feature _stack_u32
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, u32, Bare>
_stack_u32
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackU32::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackU32::<_, 4> = s.resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackU32::<_, 12> = s.resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackU32::<_, 2> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, u32, Boxed>
impl<T: Default, const CAP: usize> Stack<T, CAP, u32, Boxed>
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, u32, Boxed>, IndexOutOfBounds> ⓘ
Available on crate features alloc
and _stack_u32
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, u32, Boxed>, IndexOutOfBounds> ⓘ
alloc
and _stack_u32
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u32::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU32::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackU32::<_, 4, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackU32::<_, 12, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, u32, Boxed>
Available on crate features alloc
and _stack_u32
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, u32, Boxed>
alloc
and _stack_u32
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackU32::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackU32::<_, 4, Boxed> = s.clone().resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackU32::<_, 12, Boxed> = s.clone().resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackU32::<_, 2, Boxed> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
Sourcepub const fn own_resize_default<const NEW_CAP: usize>(
self,
) -> Own<Result<Stack<T, NEW_CAP, u32, Bare>, IndexOutOfBounds>, ()>
Available on crate feature _stack_u32
only.
pub const fn own_resize_default<const NEW_CAP: usize>( self, ) -> Own<Result<Stack<T, NEW_CAP, u32, Bare>, IndexOutOfBounds>, ()>
_stack_u32
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
u32::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU32<i32, 8> = StackU32::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU32<i32, 4> = S.own_resize_default().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
let _ = S.own_resize_default::<2>().s_assert_err(); // too small
Sourcepub const fn own_resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Own<Stack<T, NEW_CAP, u32, Bare>, ()>
Available on crate feature _stack_u32
only.
pub const fn own_resize_default_truncate<const NEW_CAP: usize>( self, ) -> Own<Stack<T, NEW_CAP, u32, Bare>, ()>
_stack_u32
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
const S: StackU32<i32, 8> = StackU32::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU32<i32, 4> = S.own_resize_default_truncate().s;
assert_eq![S.as_slice(), T.as_slice()];
const U: StackU32<i32, 2> = S.own_resize_default_truncate().s;
assert_eq![U.as_slice(), &[2, 3]];
Source§impl<T, const CAP: usize> Stack<T, CAP, u32, Bare>
§Stack index-size conversion.
impl<T, const CAP: usize> Stack<T, CAP, u32, Bare>
§Stack index-size conversion.
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u32
and _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
_stack_u32
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackU32::<_, 6>::from([1, 2, 3, 4]);
let t: StackU8::<_, 6> = s.to_idx_u8().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u32
and _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
_stack_u32
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackU32::<_, 6>::from([1, 2, 3, 4]);
let t: StackU16::<_, 6> = s.to_idx_u16().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
Available on crate feature _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
_stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackU32::<_, 6>::from([1, 2, 3, 4]);
let t: StackU32::<_, 6> = s.to_idx_u32().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_u32
and _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
_stack_u32
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackU32::<_, 6>::from([1, 2, 3, 4]);
let t: StackUsize::<_, 6> = s.to_idx_usize().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Source§impl<T, const CAP: usize> Stack<T, CAP, u32, Boxed>
impl<T, const CAP: usize> Stack<T, CAP, u32, Boxed>
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u32
and _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u32
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackU32::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU8::<_, 6, Boxed> = s.to_idx_u8().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u32
and _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u32
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackU32::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU16::<_, 6, Boxed> = s.to_idx_u16().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackU32::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU32::<_, 6, Boxed> = s.to_idx_u32().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_u32
and _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_u32
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackU32::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackUsize::<_, 6, Boxed> = s.to_idx_usize().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
Sourcepub const fn own_to_idx_u8(
self,
) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u32
and _stack_u8
only.
pub const fn own_to_idx_u8( self, ) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
_stack_u32
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
const S: StackU32<i32, 6> = StackU32::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU8<i32, 6> = S.own_to_idx_u8().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u16(
self,
) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u32
and _stack_u16
only.
pub const fn own_to_idx_u16( self, ) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
_stack_u32
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
const S: StackU32<i32, 6> = StackU32::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU16<i32, 6> = S.own_to_idx_u16().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u32(
self,
) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
Available on crate feature _stack_u32
only.
pub const fn own_to_idx_u32( self, ) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
_stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
const S: StackU32<i32, 6> = StackU32::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU32<i32, 6> = S.own_to_idx_u32().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_usize(
self,
) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_u32
and _stack_usize
only.
pub const fn own_to_idx_usize( self, ) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
_stack_u32
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
const S: StackU32<i32, 6> = StackU32::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackUsize<i32, 6> = S.own_to_idx_usize().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, usize, Bare>
§Stack resize.
impl<T: Default, const CAP: usize> Stack<T, CAP, usize, Bare>
§Stack resize.
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, usize, Bare>, IndexOutOfBounds> ⓘ
Available on crate feature _stack_usize
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, usize, Bare>, IndexOutOfBounds> ⓘ
_stack_usize
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
usize::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackUsize::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackUsize::<_, 4> = s.resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackUsize::<_, 12> = s.resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, usize, Bare>
Available on crate feature _stack_usize
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, usize, Bare>
_stack_usize
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackUsize::<_, 8>::from([1, 2, 3, 4]);
let less_cap: StackUsize::<_, 4> = s.resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackUsize::<_, 12> = s.resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackUsize::<_, 2> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: Default, const CAP: usize> Stack<T, CAP, usize, Boxed>
impl<T: Default, const CAP: usize> Stack<T, CAP, usize, Boxed>
Sourcepub fn resize_default<const NEW_CAP: usize>(
self,
) -> Result<Stack<T, NEW_CAP, usize, Boxed>, IndexOutOfBounds> ⓘ
Available on crate features alloc
and _stack_usize
only.
pub fn resize_default<const NEW_CAP: usize>( self, ) -> Result<Stack<T, NEW_CAP, usize, Boxed>, IndexOutOfBounds> ⓘ
alloc
and _stack_usize
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
usize::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackUsize::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackUsize::<_, 4, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), less_cap.as_slice()];
let more_cap: StackUsize::<_, 12, Boxed> = s.clone().resize_default().unwrap();
assert_eq![s.as_slice(), more_cap.as_slice()];
assert![s.resize_default::<2>().is_err()]; // too small
Sourcepub fn resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Stack<T, NEW_CAP, usize, Boxed>
Available on crate features alloc
and _stack_usize
only.
pub fn resize_default_truncate<const NEW_CAP: usize>( self, ) -> Stack<T, NEW_CAP, usize, Boxed>
alloc
and _stack_usize
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
let s = StackUsize::<_, 8, Boxed>::from([1, 2, 3, 4]);
let less_cap: StackUsize::<_, 4, Boxed> = s.clone().resize_default_truncate();
assert_eq![less_cap.as_slice(), s.as_slice()];
let more_cap: StackUsize::<_, 12, Boxed> = s.clone().resize_default_truncate();
assert_eq![more_cap.as_slice(), s.as_slice()];
let drop_cap: StackUsize::<_, 2, Boxed> = s.resize_default_truncate();
assert_eq![drop_cap.as_slice(), &[3, 4]];
Source§impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
impl<T: ConstDefault + Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
Sourcepub const fn own_resize_default<const NEW_CAP: usize>(
self,
) -> Own<Result<Stack<T, NEW_CAP, usize, Bare>, IndexOutOfBounds>, ()>
Available on crate feature _stack_usize
only.
pub const fn own_resize_default<const NEW_CAP: usize>( self, ) -> Own<Result<Stack<T, NEW_CAP, usize, Bare>, IndexOutOfBounds>, ()>
_stack_usize
only.Converts the current stack to a different capacity while preserving all existing elements.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation ensures that the new stack can accommodate the number of elements currently held in the stack. It is designed to work with both increases and decreases in capacity, as long as the new capacity can fit the current number of elements.
§Errors
Returns [IndexOutOfBounds(Some(NEW_CAP))
] if NEW_CAP < self.len()
,
if CAP >
usize::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackUsize<i32, 8> = StackUsize::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackUsize<i32, 4> = S.own_resize_default().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
let _ = S.own_resize_default::<2>().s_assert_err(); // too small
Sourcepub const fn own_resize_default_truncate<const NEW_CAP: usize>(
self,
) -> Own<Stack<T, NEW_CAP, usize, Bare>, ()>
Available on crate feature _stack_usize
only.
pub const fn own_resize_default_truncate<const NEW_CAP: usize>( self, ) -> Own<Stack<T, NEW_CAP, usize, Bare>, ()>
_stack_usize
only.Converts the current stack to a different capacity, dropping elements if needed.
This method creates a new stack with the specified new capacity and moves the current elements into it. The operation will drop any elements that can’t fit in the new capacity, starting with the first ones (from the front of the stack).
§Examples
const S: StackUsize<i32, 8> = StackUsize::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackUsize<i32, 4> = S.own_resize_default_truncate().s;
assert_eq![S.as_slice(), T.as_slice()];
const U: StackUsize<i32, 2> = S.own_resize_default_truncate().s;
assert_eq![U.as_slice(), &[2, 3]];
Source§impl<T, const CAP: usize> Stack<T, CAP, usize, Bare>
§Stack index-size conversion.
impl<T, const CAP: usize> Stack<T, CAP, usize, Bare>
§Stack index-size conversion.
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_usize
and _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace> ⓘ
_stack_usize
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackUsize::<_, 6>::from([1, 2, 3, 4]);
let t: StackU8::<_, 6> = s.to_idx_u8().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_usize
and _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace> ⓘ
_stack_usize
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackUsize::<_, 6>::from([1, 2, 3, 4]);
let t: StackU16::<_, 6> = s.to_idx_u16().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
Available on crate features _stack_usize
and _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace> ⓘ
_stack_usize
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackUsize::<_, 6>::from([1, 2, 3, 4]);
let t: StackU32::<_, 6> = s.to_idx_u32().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
Available on crate feature _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace> ⓘ
_stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackUsize::<_, 6>::from([1, 2, 3, 4]);
let t: StackUsize::<_, 6> = s.to_idx_usize().unwrap();
assert_eq![s.as_slice(), t.as_slice()];
Source§impl<T, const CAP: usize> Stack<T, CAP, usize, Boxed>
impl<T, const CAP: usize> Stack<T, CAP, usize, Boxed>
Sourcepub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_usize
and _stack_u8
only.
pub fn to_idx_u8(self) -> Result<Stack<T, CAP, u8, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_usize
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
let s = StackUsize::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU8::<_, 6, Boxed> = s.to_idx_u8().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_usize
and _stack_u16
only.
pub fn to_idx_u16(self) -> Result<Stack<T, CAP, u16, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_usize
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
let s = StackUsize::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU16::<_, 6, Boxed> = s.to_idx_u16().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_usize
and _stack_u32
only.
pub fn to_idx_u32(self) -> Result<Stack<T, CAP, u32, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_usize
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
let s = StackUsize::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackU32::<_, 6, Boxed> = s.to_idx_u32().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Sourcepub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
Available on crate features alloc
and _stack_usize
only.
pub fn to_idx_usize(self) -> Result<Stack<T, CAP, usize, Boxed>, NotEnoughSpace> ⓘ
alloc
and _stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
let s = StackUsize::<_, 6, Boxed>::from([1, 2, 3]);
let t: StackUsize::<_, 6, Boxed> = s.to_idx_usize().unwrap();
assert_eq![t.as_slice(), &[1, 2, 3]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
Sourcepub const fn own_to_idx_u8(
self,
) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_usize
and _stack_u8
only.
pub const fn own_to_idx_u8( self, ) -> Own<Result<Stack<T, CAP, u8, Bare>, NotEnoughSpace>, ()>
_stack_usize
and _stack_u8
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u8::MAX
.
§Examples
const S: StackUsize<i32, 6> = StackUsize::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU8<i32, 6> = S.own_to_idx_u8().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u16(
self,
) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_usize
and _stack_u16
only.
pub const fn own_to_idx_u16( self, ) -> Own<Result<Stack<T, CAP, u16, Bare>, NotEnoughSpace>, ()>
_stack_usize
and _stack_u16
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u16::MAX
.
§Examples
const S: StackUsize<i32, 6> = StackUsize::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU16<i32, 6> = S.own_to_idx_u16().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_u32(
self,
) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
Available on crate features _stack_usize
and _stack_u32
only.
pub const fn own_to_idx_u32( self, ) -> Own<Result<Stack<T, CAP, u32, Bare>, NotEnoughSpace>, ()>
_stack_usize
and _stack_u32
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
u32::MAX
.
§Examples
const S: StackUsize<i32, 6> = StackUsize::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackU32<i32, 6> = S.own_to_idx_u32().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
Sourcepub const fn own_to_idx_usize(
self,
) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
Available on crate feature _stack_usize
only.
pub const fn own_to_idx_usize( self, ) -> Own<Result<Stack<T, CAP, usize, Bare>, NotEnoughSpace>, ()>
_stack_usize
only.Converts the current stack index size IDX
to a NEW_IDX
.
§Errors
Returns NotEnoughSpace
if CAP >
usize::MAX
.
§Examples
const S: StackUsize<i32, 6> = StackUsize::own_new(0)
.s_const_unwrap().s.own_push(1).s.own_push(2).s.own_push(3).s;
const T: StackUsize<i32, 6> = S.own_to_idx_usize().s_const_unwrap().s;
assert_eq![S.as_slice(), T.as_slice()];
impl<T: Clone, const CAP: usize> Stack<T, CAP, u8, Bare>
Source§impl<T: Clone, const CAP: usize> Stack<T, CAP, u8, Bare>
impl<T: Clone, const CAP: usize> Stack<T, CAP, u8, Bare>
Sourcepub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
cloning element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU8::<_, 16>::new(0).unwrap();
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
Sourcepub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data, in compile-time.
§Errors
Returns MismatchedCapacity
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU8<i32, 16> = unwrap![ok StackU8::new_copied(0)];
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
Sourcepub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, u8, S>
pub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, u8, S>
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the stack is empty.
§Examples
let s = StackU8::<i32, 8>::default();
assert![s.is_empty()];
Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true
if the stack is full.
§Examples
let s = StackU8::<_, 3>::from([1, 2, 3]);
assert![s.is_full()];
Sourcepub const fn capacity(&self) -> u8 ⓘ
pub const fn capacity(&self) -> u8 ⓘ
Returns the stack’s total capacity.
§Examples
let s = StackU8::<i32, 3>::default();
assert_eq![3, s.capacity()];
Sourcepub const fn remaining_capacity(&self) -> u8 ⓘ
pub const fn remaining_capacity(&self) -> u8 ⓘ
Returns the stack’s remaining capacity.
§Examples
let mut s = StackU8::<_, 3>::default();
assert_eq![3, s.remaining_capacity()];
s.push(1)?;
assert_eq![2, s.remaining_capacity()];
Sourcepub fn as_slice(&self) -> &[T] ⓘ
pub fn as_slice(&self) -> &[T] ⓘ
Returns the stack as a shared slice.
§Examples
let s = StackU8::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
Sourcepub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
Returns the stack as an exclusive slice.
§Examples
let mut s = StackU8::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_mut_slice(), &mut [1, 2, 3]];
Sourcepub const fn clear(&mut self)
pub const fn clear(&mut self)
Clears the stack.
( 1 2 3 -- )
§Examples
let mut s = StackU8::<_, 8>::from([1, 2, 3, 4]);
s.clear();
assert![s.is_empty()];
Sourcepub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
pub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
Pushes a new element
to the top of the stack.
( 1 -- 1 2 )
§Errors
Returns NotEnoughSpace
if the stack is full.
§Examples
let mut s = StackU8::<_, 2>::default();
s.push(1)?;
s.push(2)?;
assert![s.push(3).is_err()];
assert_eq![s.as_slice(), &[1, 2]];
Sourcepub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
Available on crate feature unsafe_ptr
or Clone
only.
pub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
unsafe_ptr
or Clone
only.Pops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU8::<_, 2>::from([1, 2]);
assert_eq![2, s.pop()?];
assert_eq![1, s.pop()?];
assert![s.is_empty()];
§Features
It’s depends on T: Clone
, unless the unsafe_ptr
feature is enabled.
Sourcepub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
Peeks the top stack element.
( 1 -- 1 )
Returns a shared reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let s = StackU8::<_, 2>::from([1, 2]);
assert_eq![s.peek(), Ok(&2)];
Sourcepub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the top stack element.
( 1 -- 1 )
Returns an exclusive reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU8::<_, 2>::from([1, 2]);
assert_eq![s.peek_mut(), Ok(&mut 2)];
Sourcepub fn peek_nth(&self, nth: u8) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_nth(&self, nth: u8) -> Result<&T, NotEnoughElements> ⓘ
Peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns a shared reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let s = StackU8::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth(0), Ok(&5)];
assert_eq![s.peek_nth(4), Ok(&1)];
Sourcepub fn peek_nth_mut(&mut self, nth: u8) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_nth_mut(&mut self, nth: u8) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns an exclusive reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let mut s = StackU8::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth_mut(0), Ok(&mut 5)];
assert_eq![s.peek_nth_mut(4), Ok(&mut 1)];
Sourcepub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU8::<_, 2>::from([1, 2]);
s.drop();
assert_eq![s.as_slice(), &[1]];
Sourcepub fn drop_n(&mut self, n: u8) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_n(&mut self, n: u8) -> Result<(), NotEnoughElements> ⓘ
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least n
elements.
§Examples
let mut s = StackU8::<_, 4>::from([1, 2, 3, 4]);
s.drop_n(3);
assert_eq![s.as_slice(), &[1]];
Sourcepub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the next of stack element.
( 1 2 -- 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackU8::<_, 2>::from([1, 2]);
s.nip();
assert_eq![s.as_slice(), &[2]];
Sourcepub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackU8::<_, 8>::from([1, 2, 3, 4]);
s.nip2();
assert_eq![s.as_slice(), &[3, 4]];
Sourcepub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two stack elements.
( 1 2 -- 2 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackU8::<_, 2>::from([1, 2]);
s.swap();
assert_eq![s.as_slice(), &[2, 1]];
Sourcepub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two pair stack elements.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackU8::<_, 4>::from([1, 2, 3, 4]);
s.swap2();
assert_eq![s.as_slice(), &[3, 4, 1, 2]];
Sourcepub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackU8::<_, 3>::from(['a', 'b', 'c']);
s.rot()?;
assert_eq![s.as_slice(), &['b', 'c', 'a']];
Sourcepub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackU8::<_, 3>::from(['a', 'b', 'c']);
s.rot_cc()?;
assert_eq![s.as_slice(), &['c', 'a', 'b']];
Sourcepub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackU8::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Sourcepub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackU8::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Source§impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
Sourcepub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns DataNotEnough::Elements
if the stack is empty or
DataNotEnough::Space
if the stack is full.
§Examples
let mut s = StackU8::<_, 2>::from([1]);
s.dup()?;
assert_eq![&[1, 1], s.as_slice()];
Sourcepub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU8::<_, 5>::from([1, 2]);
s.dup2()?;
assert_eq![&[1, 2, 1, 2], s.as_slice()];
Sourcepub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackU8::<_, 3>::from([1, 2]);
s.over()?;
assert_eq![&[1, 2, 1], s.as_slice()];
Sourcepub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU8::<_, 6>::from([1, 2, 3, 4]);
s.over2()?;
assert_eq![&[1, 2, 3, 4, 1, 2], s.as_slice()];
Sourcepub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackU8::<_, 3>::from([1, 2]);
s.tuck()?;
assert_eq![&[2, 1, 2], s.as_slice()];
Sourcepub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU8::<_, 6>::from([1, 2, 3, 4]);
s.tuck2()?;
assert_eq![&[3, 4, 1, 2, 3, 4], s.as_slice()];
Sourcepub fn to_vec(&self) -> Vec<T> ⓘ
Available on crate feature alloc
only.
pub fn to_vec(&self) -> Vec<T> ⓘ
alloc
only.Returns the stacked elements as a vector.
§Examples
let mut s = StackU8::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_vec(), vec![1, 2, 3, 4, 5]];
Sourcepub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
pub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
Returns some LEN
stacked elements as an array, or None
if the stack
is empty, or there are not at least LEN
elements.
This is a non alloc
alternative method to to_vec
.
§Panics
Panics if the new LEN
sized array can’t be allocated.
§Examples
let mut s = StackU8::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_array::<5>(), Some([1, 2, 3, 4, 5])];
§Features
Makes use of the unsafe_array
feature if enabled.
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
Sourcepub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
pub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
Extends the stack from an iterator.
§Errors
Returns NotEnoughSpace
if the stack becomes full before the iterator finishes.
§Examples
let mut s = StackU8::<_, 5>::default();
s.extend([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
s.extend([4, 5, 6, 7, 8]);
assert_eq![s.as_slice(), &[1, 2, 3, 4, 5]];
Source§impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, u8, S>
Sourcepub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top of stack element, replacing the underlying data with the default value.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU8::<_, 2>::from([1, 2]);
s.drop_replace_default();
assert_eq![s.as_slice(), &[1]];
impl<T: Clone, const CAP: usize> Stack<T, CAP, u16, Bare>
Source§impl<T: Clone, const CAP: usize> Stack<T, CAP, u16, Bare>
impl<T: Clone, const CAP: usize> Stack<T, CAP, u16, Bare>
Sourcepub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
cloning element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
u16::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU16::<_, 16>::new(0).unwrap();
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
Sourcepub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data, in compile-time.
§Errors
Returns MismatchedCapacity
if CAP >
u16::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU16<i32, 16> = unwrap![ok StackU16::new_copied(0)];
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
Sourcepub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, u16, S>
pub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, u16, S>
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the stack is empty.
§Examples
let s = StackU16::<i32, 8>::default();
assert![s.is_empty()];
Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true
if the stack is full.
§Examples
let s = StackU16::<_, 3>::from([1, 2, 3]);
assert![s.is_full()];
Sourcepub const fn capacity(&self) -> u16 ⓘ
pub const fn capacity(&self) -> u16 ⓘ
Returns the stack’s total capacity.
§Examples
let s = StackU16::<i32, 3>::default();
assert_eq![3, s.capacity()];
Sourcepub const fn remaining_capacity(&self) -> u16 ⓘ
pub const fn remaining_capacity(&self) -> u16 ⓘ
Returns the stack’s remaining capacity.
§Examples
let mut s = StackU16::<_, 3>::default();
assert_eq![3, s.remaining_capacity()];
s.push(1)?;
assert_eq![2, s.remaining_capacity()];
Sourcepub fn as_slice(&self) -> &[T] ⓘ
pub fn as_slice(&self) -> &[T] ⓘ
Returns the stack as a shared slice.
§Examples
let s = StackU16::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
Sourcepub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
Returns the stack as an exclusive slice.
§Examples
let mut s = StackU16::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_mut_slice(), &mut [1, 2, 3]];
Sourcepub const fn clear(&mut self)
pub const fn clear(&mut self)
Clears the stack.
( 1 2 3 -- )
§Examples
let mut s = StackU16::<_, 8>::from([1, 2, 3, 4]);
s.clear();
assert![s.is_empty()];
Sourcepub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
pub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
Pushes a new element
to the top of the stack.
( 1 -- 1 2 )
§Errors
Returns NotEnoughSpace
if the stack is full.
§Examples
let mut s = StackU16::<_, 2>::default();
s.push(1)?;
s.push(2)?;
assert![s.push(3).is_err()];
assert_eq![s.as_slice(), &[1, 2]];
Sourcepub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
Available on crate feature unsafe_ptr
or Clone
only.
pub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
unsafe_ptr
or Clone
only.Pops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU16::<_, 2>::from([1, 2]);
assert_eq![2, s.pop()?];
assert_eq![1, s.pop()?];
assert![s.is_empty()];
§Features
It’s depends on T: Clone
, unless the unsafe_ptr
feature is enabled.
Sourcepub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
Peeks the top stack element.
( 1 -- 1 )
Returns a shared reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let s = StackU16::<_, 2>::from([1, 2]);
assert_eq![s.peek(), Ok(&2)];
Sourcepub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the top stack element.
( 1 -- 1 )
Returns an exclusive reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU16::<_, 2>::from([1, 2]);
assert_eq![s.peek_mut(), Ok(&mut 2)];
Sourcepub fn peek_nth(&self, nth: u16) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_nth(&self, nth: u16) -> Result<&T, NotEnoughElements> ⓘ
Peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns a shared reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let s = StackU16::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth(0), Ok(&5)];
assert_eq![s.peek_nth(4), Ok(&1)];
Sourcepub fn peek_nth_mut(&mut self, nth: u16) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_nth_mut(&mut self, nth: u16) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns an exclusive reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let mut s = StackU16::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth_mut(0), Ok(&mut 5)];
assert_eq![s.peek_nth_mut(4), Ok(&mut 1)];
Sourcepub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU16::<_, 2>::from([1, 2]);
s.drop();
assert_eq![s.as_slice(), &[1]];
Sourcepub fn drop_n(&mut self, n: u16) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_n(&mut self, n: u16) -> Result<(), NotEnoughElements> ⓘ
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least n
elements.
§Examples
let mut s = StackU16::<_, 4>::from([1, 2, 3, 4]);
s.drop_n(3);
assert_eq![s.as_slice(), &[1]];
Sourcepub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the next of stack element.
( 1 2 -- 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackU16::<_, 2>::from([1, 2]);
s.nip();
assert_eq![s.as_slice(), &[2]];
Sourcepub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackU16::<_, 8>::from([1, 2, 3, 4]);
s.nip2();
assert_eq![s.as_slice(), &[3, 4]];
Sourcepub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two stack elements.
( 1 2 -- 2 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackU16::<_, 2>::from([1, 2]);
s.swap();
assert_eq![s.as_slice(), &[2, 1]];
Sourcepub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two pair stack elements.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackU16::<_, 4>::from([1, 2, 3, 4]);
s.swap2();
assert_eq![s.as_slice(), &[3, 4, 1, 2]];
Sourcepub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackU16::<_, 3>::from(['a', 'b', 'c']);
s.rot()?;
assert_eq![s.as_slice(), &['b', 'c', 'a']];
Sourcepub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackU16::<_, 3>::from(['a', 'b', 'c']);
s.rot_cc()?;
assert_eq![s.as_slice(), &['c', 'a', 'b']];
Sourcepub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackU16::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Sourcepub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackU16::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Source§impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
Sourcepub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns DataNotEnough::Elements
if the stack is empty or
DataNotEnough::Space
if the stack is full.
§Examples
let mut s = StackU16::<_, 2>::from([1]);
s.dup()?;
assert_eq![&[1, 1], s.as_slice()];
Sourcepub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU16::<_, 5>::from([1, 2]);
s.dup2()?;
assert_eq![&[1, 2, 1, 2], s.as_slice()];
Sourcepub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackU16::<_, 3>::from([1, 2]);
s.over()?;
assert_eq![&[1, 2, 1], s.as_slice()];
Sourcepub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU16::<_, 6>::from([1, 2, 3, 4]);
s.over2()?;
assert_eq![&[1, 2, 3, 4, 1, 2], s.as_slice()];
Sourcepub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackU16::<_, 3>::from([1, 2]);
s.tuck()?;
assert_eq![&[2, 1, 2], s.as_slice()];
Sourcepub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU16::<_, 6>::from([1, 2, 3, 4]);
s.tuck2()?;
assert_eq![&[3, 4, 1, 2, 3, 4], s.as_slice()];
Sourcepub fn to_vec(&self) -> Vec<T> ⓘ
Available on crate feature alloc
only.
pub fn to_vec(&self) -> Vec<T> ⓘ
alloc
only.Returns the stacked elements as a vector.
§Examples
let mut s = StackU16::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_vec(), vec![1, 2, 3, 4, 5]];
Sourcepub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
pub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
Returns some LEN
stacked elements as an array, or None
if the stack
is empty, or there are not at least LEN
elements.
This is a non alloc
alternative method to to_vec
.
§Panics
Panics if the new LEN
sized array can’t be allocated.
§Examples
let mut s = StackU16::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_array::<5>(), Some([1, 2, 3, 4, 5])];
§Features
Makes use of the unsafe_array
feature if enabled.
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
Sourcepub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
pub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
Extends the stack from an iterator.
§Errors
Returns NotEnoughSpace
if the stack becomes full before the iterator finishes.
§Examples
let mut s = StackU16::<_, 5>::default();
s.extend([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
s.extend([4, 5, 6, 7, 8]);
assert_eq![s.as_slice(), &[1, 2, 3, 4, 5]];
Source§impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, u16, S>
Sourcepub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top of stack element, replacing the underlying data with the default value.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU16::<_, 2>::from([1, 2]);
s.drop_replace_default();
assert_eq![s.as_slice(), &[1]];
impl<T: Clone, const CAP: usize> Stack<T, CAP, u32, Bare>
Source§impl<T: Clone, const CAP: usize> Stack<T, CAP, u32, Bare>
impl<T: Clone, const CAP: usize> Stack<T, CAP, u32, Bare>
Sourcepub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
cloning element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
u32::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackU32::<_, 16>::new(0).unwrap();
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
Sourcepub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data, in compile-time.
§Errors
Returns MismatchedCapacity
if CAP >
u32::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU32<i32, 16> = unwrap![ok StackU32::new_copied(0)];
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
Sourcepub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, u32, S>
pub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, u32, S>
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the stack is empty.
§Examples
let s = StackU32::<i32, 8>::default();
assert![s.is_empty()];
Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true
if the stack is full.
§Examples
let s = StackU32::<_, 3>::from([1, 2, 3]);
assert![s.is_full()];
Sourcepub const fn capacity(&self) -> u32 ⓘ
pub const fn capacity(&self) -> u32 ⓘ
Returns the stack’s total capacity.
§Examples
let s = StackU32::<i32, 3>::default();
assert_eq![3, s.capacity()];
Sourcepub const fn remaining_capacity(&self) -> u32 ⓘ
pub const fn remaining_capacity(&self) -> u32 ⓘ
Returns the stack’s remaining capacity.
§Examples
let mut s = StackU32::<_, 3>::default();
assert_eq![3, s.remaining_capacity()];
s.push(1)?;
assert_eq![2, s.remaining_capacity()];
Sourcepub fn as_slice(&self) -> &[T] ⓘ
pub fn as_slice(&self) -> &[T] ⓘ
Returns the stack as a shared slice.
§Examples
let s = StackU32::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
Sourcepub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
Returns the stack as an exclusive slice.
§Examples
let mut s = StackU32::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_mut_slice(), &mut [1, 2, 3]];
Sourcepub const fn clear(&mut self)
pub const fn clear(&mut self)
Clears the stack.
( 1 2 3 -- )
§Examples
let mut s = StackU32::<_, 8>::from([1, 2, 3, 4]);
s.clear();
assert![s.is_empty()];
Sourcepub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
pub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
Pushes a new element
to the top of the stack.
( 1 -- 1 2 )
§Errors
Returns NotEnoughSpace
if the stack is full.
§Examples
let mut s = StackU32::<_, 2>::default();
s.push(1)?;
s.push(2)?;
assert![s.push(3).is_err()];
assert_eq![s.as_slice(), &[1, 2]];
Sourcepub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
Available on crate feature unsafe_ptr
or Clone
only.
pub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
unsafe_ptr
or Clone
only.Pops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU32::<_, 2>::from([1, 2]);
assert_eq![2, s.pop()?];
assert_eq![1, s.pop()?];
assert![s.is_empty()];
§Features
It’s depends on T: Clone
, unless the unsafe_ptr
feature is enabled.
Sourcepub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
Peeks the top stack element.
( 1 -- 1 )
Returns a shared reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let s = StackU32::<_, 2>::from([1, 2]);
assert_eq![s.peek(), Ok(&2)];
Sourcepub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the top stack element.
( 1 -- 1 )
Returns an exclusive reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU32::<_, 2>::from([1, 2]);
assert_eq![s.peek_mut(), Ok(&mut 2)];
Sourcepub fn peek_nth(&self, nth: u32) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_nth(&self, nth: u32) -> Result<&T, NotEnoughElements> ⓘ
Peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns a shared reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let s = StackU32::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth(0), Ok(&5)];
assert_eq![s.peek_nth(4), Ok(&1)];
Sourcepub fn peek_nth_mut(&mut self, nth: u32) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_nth_mut(&mut self, nth: u32) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns an exclusive reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let mut s = StackU32::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth_mut(0), Ok(&mut 5)];
assert_eq![s.peek_nth_mut(4), Ok(&mut 1)];
Sourcepub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU32::<_, 2>::from([1, 2]);
s.drop();
assert_eq![s.as_slice(), &[1]];
Sourcepub fn drop_n(&mut self, n: u32) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_n(&mut self, n: u32) -> Result<(), NotEnoughElements> ⓘ
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least n
elements.
§Examples
let mut s = StackU32::<_, 4>::from([1, 2, 3, 4]);
s.drop_n(3);
assert_eq![s.as_slice(), &[1]];
Sourcepub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the next of stack element.
( 1 2 -- 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackU32::<_, 2>::from([1, 2]);
s.nip();
assert_eq![s.as_slice(), &[2]];
Sourcepub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackU32::<_, 8>::from([1, 2, 3, 4]);
s.nip2();
assert_eq![s.as_slice(), &[3, 4]];
Sourcepub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two stack elements.
( 1 2 -- 2 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackU32::<_, 2>::from([1, 2]);
s.swap();
assert_eq![s.as_slice(), &[2, 1]];
Sourcepub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two pair stack elements.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackU32::<_, 4>::from([1, 2, 3, 4]);
s.swap2();
assert_eq![s.as_slice(), &[3, 4, 1, 2]];
Sourcepub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackU32::<_, 3>::from(['a', 'b', 'c']);
s.rot()?;
assert_eq![s.as_slice(), &['b', 'c', 'a']];
Sourcepub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackU32::<_, 3>::from(['a', 'b', 'c']);
s.rot_cc()?;
assert_eq![s.as_slice(), &['c', 'a', 'b']];
Sourcepub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackU32::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Sourcepub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackU32::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Source§impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
Sourcepub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns DataNotEnough::Elements
if the stack is empty or
DataNotEnough::Space
if the stack is full.
§Examples
let mut s = StackU32::<_, 2>::from([1]);
s.dup()?;
assert_eq![&[1, 1], s.as_slice()];
Sourcepub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU32::<_, 5>::from([1, 2]);
s.dup2()?;
assert_eq![&[1, 2, 1, 2], s.as_slice()];
Sourcepub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackU32::<_, 3>::from([1, 2]);
s.over()?;
assert_eq![&[1, 2, 1], s.as_slice()];
Sourcepub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU32::<_, 6>::from([1, 2, 3, 4]);
s.over2()?;
assert_eq![&[1, 2, 3, 4, 1, 2], s.as_slice()];
Sourcepub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackU32::<_, 3>::from([1, 2]);
s.tuck()?;
assert_eq![&[2, 1, 2], s.as_slice()];
Sourcepub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackU32::<_, 6>::from([1, 2, 3, 4]);
s.tuck2()?;
assert_eq![&[3, 4, 1, 2, 3, 4], s.as_slice()];
Sourcepub fn to_vec(&self) -> Vec<T> ⓘ
Available on crate feature alloc
only.
pub fn to_vec(&self) -> Vec<T> ⓘ
alloc
only.Returns the stacked elements as a vector.
§Examples
let mut s = StackU32::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_vec(), vec![1, 2, 3, 4, 5]];
Sourcepub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
pub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
Returns some LEN
stacked elements as an array, or None
if the stack
is empty, or there are not at least LEN
elements.
This is a non alloc
alternative method to to_vec
.
§Panics
Panics if the new LEN
sized array can’t be allocated.
§Examples
let mut s = StackU32::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_array::<5>(), Some([1, 2, 3, 4, 5])];
§Features
Makes use of the unsafe_array
feature if enabled.
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
Sourcepub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
pub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
Extends the stack from an iterator.
§Errors
Returns NotEnoughSpace
if the stack becomes full before the iterator finishes.
§Examples
let mut s = StackU32::<_, 5>::default();
s.extend([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
s.extend([4, 5, 6, 7, 8]);
assert_eq![s.as_slice(), &[1, 2, 3, 4, 5]];
Source§impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, u32, S>
Sourcepub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top of stack element, replacing the underlying data with the default value.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackU32::<_, 2>::from([1, 2]);
s.drop_replace_default();
assert_eq![s.as_slice(), &[1]];
impl<T: Clone, const CAP: usize> Stack<T, CAP, usize, Bare>
Source§impl<T: Clone, const CAP: usize> Stack<T, CAP, usize, Bare>
impl<T: Clone, const CAP: usize> Stack<T, CAP, usize, Bare>
Sourcepub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
cloning element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
usize::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let s = StackUsize::<_, 16>::new(0).unwrap();
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
impl<T: Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
Sourcepub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data, in compile-time.
§Errors
Returns MismatchedCapacity
if CAP >
usize::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackUsize<i32, 16> = unwrap![ok StackUsize::new_copied(0)];
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
Sourcepub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, usize, S>
pub fn from_array(arr: [T; CAP]) -> Stack<T, CAP, usize, S>
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the stack is empty.
§Examples
let s = StackUsize::<i32, 8>::default();
assert![s.is_empty()];
Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true
if the stack is full.
§Examples
let s = StackUsize::<_, 3>::from([1, 2, 3]);
assert![s.is_full()];
Sourcepub const fn capacity(&self) -> usize ⓘ
pub const fn capacity(&self) -> usize ⓘ
Returns the stack’s total capacity.
§Examples
let s = StackUsize::<i32, 3>::default();
assert_eq![3, s.capacity()];
Sourcepub const fn remaining_capacity(&self) -> usize ⓘ
pub const fn remaining_capacity(&self) -> usize ⓘ
Returns the stack’s remaining capacity.
§Examples
let mut s = StackUsize::<_, 3>::default();
assert_eq![3, s.remaining_capacity()];
s.push(1)?;
assert_eq![2, s.remaining_capacity()];
Sourcepub fn as_slice(&self) -> &[T] ⓘ
pub fn as_slice(&self) -> &[T] ⓘ
Returns the stack as a shared slice.
§Examples
let s = StackUsize::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
Sourcepub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
Returns the stack as an exclusive slice.
§Examples
let mut s = StackUsize::<_, 3>::from([1, 2, 3]);
assert_eq![s.as_mut_slice(), &mut [1, 2, 3]];
Sourcepub const fn clear(&mut self)
pub const fn clear(&mut self)
Clears the stack.
( 1 2 3 -- )
§Examples
let mut s = StackUsize::<_, 8>::from([1, 2, 3, 4]);
s.clear();
assert![s.is_empty()];
Sourcepub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
pub fn push(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
Pushes a new element
to the top of the stack.
( 1 -- 1 2 )
§Errors
Returns NotEnoughSpace
if the stack is full.
§Examples
let mut s = StackUsize::<_, 2>::default();
s.push(1)?;
s.push(2)?;
assert![s.push(3).is_err()];
assert_eq![s.as_slice(), &[1, 2]];
Sourcepub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
Available on crate feature unsafe_ptr
or Clone
only.
pub fn pop(&mut self) -> Result<T, NotEnoughElements> ⓘ
unsafe_ptr
or Clone
only.Pops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackUsize::<_, 2>::from([1, 2]);
assert_eq![2, s.pop()?];
assert_eq![1, s.pop()?];
assert![s.is_empty()];
§Features
It’s depends on T: Clone
, unless the unsafe_ptr
feature is enabled.
Sourcepub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek(&self) -> Result<&T, NotEnoughElements> ⓘ
Peeks the top stack element.
( 1 -- 1 )
Returns a shared reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let s = StackUsize::<_, 2>::from([1, 2]);
assert_eq![s.peek(), Ok(&2)];
Sourcepub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the top stack element.
( 1 -- 1 )
Returns an exclusive reference to the top stack element.
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackUsize::<_, 2>::from([1, 2]);
assert_eq![s.peek_mut(), Ok(&mut 2)];
Sourcepub fn peek_nth(&self, nth: usize) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_nth(&self, nth: usize) -> Result<&T, NotEnoughElements> ⓘ
Peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns a shared reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let s = StackUsize::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth(0), Ok(&5)];
assert_eq![s.peek_nth(4), Ok(&1)];
Sourcepub fn peek_nth_mut(&mut self, nth: usize) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_nth_mut(&mut self, nth: usize) -> Result<&mut T, NotEnoughElements> ⓘ
Mutably peeks the nth
element from the top of the stack.
( 1 -- 1 )
Returns an exclusive reference to the nth
element,
starting from 0 for the top, 1 for the next-of-stack, etc.
§Errors
Returns NotEnoughElements
if the stack has not enough elements.
§Examples
let mut s = StackUsize::<_, 5>::from([1, 2, 3, 4, 5]);
assert_eq![s.peek_nth_mut(0), Ok(&mut 5)];
assert_eq![s.peek_nth_mut(4), Ok(&mut 1)];
Sourcepub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top stack element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackUsize::<_, 2>::from([1, 2]);
s.drop();
assert_eq![s.as_slice(), &[1]];
Sourcepub fn drop_n(&mut self, n: usize) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_n(&mut self, n: usize) -> Result<(), NotEnoughElements> ⓘ
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least n
elements.
§Examples
let mut s = StackUsize::<_, 4>::from([1, 2, 3, 4]);
s.drop_n(3);
assert_eq![s.as_slice(), &[1]];
Sourcepub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the next of stack element.
( 1 2 -- 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackUsize::<_, 2>::from([1, 2]);
s.nip();
assert_eq![s.as_slice(), &[2]];
Sourcepub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn nip2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackUsize::<_, 8>::from([1, 2, 3, 4]);
s.nip2();
assert_eq![s.as_slice(), &[3, 4]];
Sourcepub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two stack elements.
( 1 2 -- 2 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 2 elements.
§Examples
let mut s = StackUsize::<_, 2>::from([1, 2]);
s.swap();
assert_eq![s.as_slice(), &[2, 1]];
Sourcepub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the top two pair stack elements.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 4 elements.
§Examples
let mut s = StackUsize::<_, 4>::from([1, 2, 3, 4]);
s.swap2();
assert_eq![s.as_slice(), &[3, 4, 1, 2]];
Sourcepub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackUsize::<_, 3>::from(['a', 'b', 'c']);
s.rot()?;
assert_eq![s.as_slice(), &['b', 'c', 'a']];
Sourcepub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 3 elements.
§Examples
let mut s = StackUsize::<_, 3>::from(['a', 'b', 'c']);
s.rot_cc()?;
assert_eq![s.as_slice(), &['c', 'a', 'b']];
Sourcepub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackUsize::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Sourcepub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn rot2_cc(&mut self) -> Result<(), NotEnoughElements> ⓘ
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns NotEnoughElements
if the stack doesn’t contain at least 6 elements.
§Examples
let mut s = StackUsize::<_, 6>::from(['a', 'b', 'c', 'd', 'e', 'f']);
s.rot2()?;
assert_eq![s.as_slice(), &['c', 'd', 'e', 'f', 'a', 'b']];
Source§impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
impl<T: Clone, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
Sourcepub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns DataNotEnough::Elements
if the stack is empty or
DataNotEnough::Space
if the stack is full.
§Examples
let mut s = StackUsize::<_, 2>::from([1]);
s.dup()?;
assert_eq![&[1, 1], s.as_slice()];
Sourcepub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackUsize::<_, 5>::from([1, 2]);
s.dup2()?;
assert_eq![&[1, 2, 1, 2], s.as_slice()];
Sourcepub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackUsize::<_, 3>::from([1, 2]);
s.over()?;
assert_eq![&[1, 2, 1], s.as_slice()];
Sourcepub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackUsize::<_, 6>::from([1, 2, 3, 4]);
s.over2()?;
assert_eq![&[1, 2, 3, 4, 1, 2], s.as_slice()];
Sourcepub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 2 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 1 extra element.
§Examples
let mut s = StackUsize::<_, 3>::from([1, 2]);
s.tuck()?;
assert_eq![&[2, 1, 2], s.as_slice()];
Sourcepub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck2(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns DataNotEnough::Elements
if the stack doesn’t have at least 4 elements,
or DataNotEnough::Space
if it doesn’t have enough space for 2 extra elements.
§Examples
let mut s = StackUsize::<_, 6>::from([1, 2, 3, 4]);
s.tuck2()?;
assert_eq![&[3, 4, 1, 2, 3, 4], s.as_slice()];
Sourcepub fn to_vec(&self) -> Vec<T> ⓘ
Available on crate feature alloc
only.
pub fn to_vec(&self) -> Vec<T> ⓘ
alloc
only.Returns the stacked elements as a vector.
§Examples
let mut s = StackUsize::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_vec(), vec![1, 2, 3, 4, 5]];
Sourcepub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
pub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
Returns some LEN
stacked elements as an array, or None
if the stack
is empty, or there are not at least LEN
elements.
This is a non alloc
alternative method to to_vec
.
§Panics
Panics if the new LEN
sized array can’t be allocated.
§Examples
let mut s = StackUsize::<_, 5>::from([1, 2]);
s.push(3)?;
s.push(4)?;
s.push(5)?;
assert_eq![s.to_array::<5>(), Some([1, 2, 3, 4, 5])];
§Features
Makes use of the unsafe_array
feature if enabled.
Source§impl<T, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
impl<T, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
Sourcepub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
pub fn extend<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
Extends the stack from an iterator.
§Errors
Returns NotEnoughSpace
if the stack becomes full before the iterator finishes.
§Examples
let mut s = StackUsize::<_, 5>::default();
s.extend([1, 2, 3]);
assert_eq![s.as_slice(), &[1, 2, 3]];
s.extend([4, 5, 6, 7, 8]);
assert_eq![s.as_slice(), &[1, 2, 3, 4, 5]];
Source§impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
impl<T: Default, const CAP: usize, S: Storage> Stack<T, CAP, usize, S>
Sourcepub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_replace_default(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the top of stack element, replacing the underlying data with the default value.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the stack is empty.
§Examples
let mut s = StackUsize::<_, 2>::from([1, 2]);
s.drop_replace_default();
assert_eq![s.as_slice(), &[1]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
§Chainable const
impl<T: Copy, const CAP: usize> Stack<T, CAP, u8, Bare>
§Chainable const
T: Copy
Every method is const and returns Own
<Self, V>
.
Sourcepub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
pub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU8<i32, 16> = StackU8::own_new(0).s_const_unwrap().s;
Sourcepub const fn own_clear(self) -> Own<Self, ()>
pub const fn own_clear(self) -> Own<Self, ()>
Clears the stack in compile-time.
( 1 2 3 -- )
§Examples
const S: StackU8<i32, 3> = StackU8::from_array_copy([1, 2, 3]).own_clear().s;
assert![S.is_empty()];
Sourcepub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
pub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
Pushes a new element
to the top of the stack in compile-time.
( 1 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughSpace
>
if the stack is full.
§Examples
const S: StackU8<i32, 2> = StackU8::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s
.own_push(2).v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 2]];
assert![S.own_push(3).v.is_err_and(|e| matches![e, NotEnoughSpace])];
Sourcepub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
pub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
Sourcepub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
Pops the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackU8<i32, 3>, Result<i32, NotEnoughElements>> =
StackU8::from_array_copy([1, 2, 3]).own_pop();
S.s_assert(|s| s.as_slice() == &[1, 2]).v_assert_eq(&Ok(3));
Sourcepub const fn own_pop_unchecked(self) -> Own<Self, T>
pub const fn own_pop_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
Peeks the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackU8<i32, 3>, Result<i32, NotEnoughElements>> =
StackU8::from_array_copy([1, 2, 3]).own_peek();
S.s_assert(|s| s.as_slice() == &[1, 2, 3]).v_assert_eq(&Ok(3));
Sourcepub const fn own_peek_unchecked(self) -> Own<Self, T>
pub const fn own_peek_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top stack element in compile-time.
( 1 2 -- 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: StackU8<i32, 2> = StackU8::from_array_copy([1, 2])
.own_drop().v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
const T: StackU8<i32, 2> = StackU8::own_new(0).s_const_unwrap().s
.own_drop().v_assert_err().s;
assert![T.is_empty()];
Sourcepub const fn own_drop_unchecked(self) -> Own<Self, ()>
pub const fn own_drop_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_drop_n(self, n: u8) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop_n(self, n: u8) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least n
elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([1, 2, 3, 4])
.own_drop_n(3).v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
Sourcepub const fn own_drop_n_unchecked(self, n: u8) -> Own<Self, ()>
pub const fn own_drop_n_unchecked(self, n: u8) -> Own<Self, ()>
Sourcepub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the next of stack element in compile-time.
( 1 2 -- 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackU8<i32, 2> = StackU8::from_array_copy([1, 2])
.own_nip().v_assert_ok().s;
assert_eq![S.as_slice(), &[2]];
const T: StackU8<i32, 2> = StackU8::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s.own_nip().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_nip_unchecked(self) -> Own<Self, ()>
pub const fn own_nip_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([1, 2, 3, 4])
.own_nip2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4]];
Sourcepub const fn own_nip2_unchecked(self) -> Own<Self, ()>
pub const fn own_nip2_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two stack elements in compile-time.
( 1 2 -- 2 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackU8<i32, 2> = StackU8::from_array_copy([1, 2])
.own_swap().v_assert_ok().s;
assert_eq![S.as_slice(), &[2, 1]];
const T: StackU8<i32, 1> = StackU8::from_array_copy([1])
.own_swap().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_swap_unchecked(self) -> Own<Self, ()>
pub const fn own_swap_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two pair stack elements in compile-time.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([1, 2, 3, 4])
.own_swap2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
const T: StackU8<i32, 3> = StackU8::from_array_copy([1, 2, 3])
.own_swap2().v_assert_err().s;
assert_eq![T.as_slice(), &[1, 2, 3]];
Sourcepub const fn own_swap2_unchecked(self) -> Own<Self, ()>
pub const fn own_swap2_unchecked(self) -> Own<Self, ()>
Swaps the top two pair stack elements in compile-time, unchecked version.
( 1 2 3 4 -- 3 4 1 2 )
§Panics
Panics if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([1, 2, 3, 4])
.own_swap2_unchecked().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
Sourcepub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 3])
.own_rot().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, clockwise, unchecked version.
( 1 2 3 -- 2 3 1 )
§Panics
Panics if the stack doesn’t contain at least 6 elements. if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 3])
.own_rot_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 3])
.own_rot_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, counter-clockwise, unchecked version.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 3])
.own_rot_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, counter-clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack is empty or
Own<self,
DataNotEnough::Space
>
if the stack is full.
§Examples
const S: StackU8<i32, 3> = StackU8::own_new(0).s_const_unwrap().s
.own_push(1).s.own_dup().v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 1]];
Sourcepub const fn own_dup_unchecked(self) -> Own<Self, ()>
pub const fn own_dup_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 6> = StackU8::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_dup2_unchecked(self) -> Own<Self, ()>
pub const fn own_dup2_unchecked(self) -> Own<Self, ()>
Duplicates the top stack pair of elements, unchecked version.
( 1 2 -- 1 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 6> = StackU8::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over_unchecked(self) -> Own<Self, ()>
pub const fn own_over_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_over2_unchecked(self) -> Own<Self, ()>
pub const fn own_over2_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck_unchecked(self) -> Own<Self, ()>
Duplicates the top element before the next of stack element, unchecked version.
( 1 2 -- 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackU8<i32, 4> = StackU8::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Sourcepub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
Duplicates the top pair of elements before the next of stack pair of elements, unchecked version.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU8<i32, 7> = StackU8::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
§Chainable const
impl<T: Copy, const CAP: usize> Stack<T, CAP, u16, Bare>
§Chainable const
T: Copy
Every method is const and returns Own
<Self, V>
.
Sourcepub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
pub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
u16::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU16<i32, 16> = StackU16::own_new(0).s_const_unwrap().s;
Sourcepub const fn own_clear(self) -> Own<Self, ()>
pub const fn own_clear(self) -> Own<Self, ()>
Clears the stack in compile-time.
( 1 2 3 -- )
§Examples
const S: StackU16<i32, 3> = StackU16::from_array_copy([1, 2, 3]).own_clear().s;
assert![S.is_empty()];
Sourcepub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
pub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
Pushes a new element
to the top of the stack in compile-time.
( 1 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughSpace
>
if the stack is full.
§Examples
const S: StackU16<i32, 2> = StackU16::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s
.own_push(2).v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 2]];
assert![S.own_push(3).v.is_err_and(|e| matches![e, NotEnoughSpace])];
Sourcepub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
pub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
Sourcepub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
Pops the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackU16<i32, 3>, Result<i32, NotEnoughElements>> =
StackU16::from_array_copy([1, 2, 3]).own_pop();
S.s_assert(|s| s.as_slice() == &[1, 2]).v_assert_eq(&Ok(3));
Sourcepub const fn own_pop_unchecked(self) -> Own<Self, T>
pub const fn own_pop_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
Peeks the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackU16<i32, 3>, Result<i32, NotEnoughElements>> =
StackU16::from_array_copy([1, 2, 3]).own_peek();
S.s_assert(|s| s.as_slice() == &[1, 2, 3]).v_assert_eq(&Ok(3));
Sourcepub const fn own_peek_unchecked(self) -> Own<Self, T>
pub const fn own_peek_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top stack element in compile-time.
( 1 2 -- 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: StackU16<i32, 2> = StackU16::from_array_copy([1, 2])
.own_drop().v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
const T: StackU16<i32, 2> = StackU16::own_new(0).s_const_unwrap().s
.own_drop().v_assert_err().s;
assert![T.is_empty()];
Sourcepub const fn own_drop_unchecked(self) -> Own<Self, ()>
pub const fn own_drop_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_drop_n(
self,
n: u16,
) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop_n( self, n: u16, ) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least n
elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([1, 2, 3, 4])
.own_drop_n(3).v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
Sourcepub const fn own_drop_n_unchecked(self, n: u16) -> Own<Self, ()>
pub const fn own_drop_n_unchecked(self, n: u16) -> Own<Self, ()>
Sourcepub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the next of stack element in compile-time.
( 1 2 -- 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackU16<i32, 2> = StackU16::from_array_copy([1, 2])
.own_nip().v_assert_ok().s;
assert_eq![S.as_slice(), &[2]];
const T: StackU16<i32, 2> = StackU16::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s.own_nip().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_nip_unchecked(self) -> Own<Self, ()>
pub const fn own_nip_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([1, 2, 3, 4])
.own_nip2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4]];
Sourcepub const fn own_nip2_unchecked(self) -> Own<Self, ()>
pub const fn own_nip2_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two stack elements in compile-time.
( 1 2 -- 2 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackU16<i32, 2> = StackU16::from_array_copy([1, 2])
.own_swap().v_assert_ok().s;
assert_eq![S.as_slice(), &[2, 1]];
const T: StackU16<i32, 1> = StackU16::from_array_copy([1])
.own_swap().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_swap_unchecked(self) -> Own<Self, ()>
pub const fn own_swap_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two pair stack elements in compile-time.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([1, 2, 3, 4])
.own_swap2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
const T: StackU16<i32, 3> = StackU16::from_array_copy([1, 2, 3])
.own_swap2().v_assert_err().s;
assert_eq![T.as_slice(), &[1, 2, 3]];
Sourcepub const fn own_swap2_unchecked(self) -> Own<Self, ()>
pub const fn own_swap2_unchecked(self) -> Own<Self, ()>
Swaps the top two pair stack elements in compile-time, unchecked version.
( 1 2 3 4 -- 3 4 1 2 )
§Panics
Panics if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([1, 2, 3, 4])
.own_swap2_unchecked().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
Sourcepub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 3])
.own_rot().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, clockwise, unchecked version.
( 1 2 3 -- 2 3 1 )
§Panics
Panics if the stack doesn’t contain at least 6 elements. if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 3])
.own_rot_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 3])
.own_rot_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, counter-clockwise, unchecked version.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 3])
.own_rot_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, counter-clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack is empty or
Own<self,
DataNotEnough::Space
>
if the stack is full.
§Examples
const S: StackU16<i32, 3> = StackU16::own_new(0).s_const_unwrap().s
.own_push(1).s.own_dup().v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 1]];
Sourcepub const fn own_dup_unchecked(self) -> Own<Self, ()>
pub const fn own_dup_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 6> = StackU16::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_dup2_unchecked(self) -> Own<Self, ()>
pub const fn own_dup2_unchecked(self) -> Own<Self, ()>
Duplicates the top stack pair of elements, unchecked version.
( 1 2 -- 1 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 6> = StackU16::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over_unchecked(self) -> Own<Self, ()>
pub const fn own_over_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_over2_unchecked(self) -> Own<Self, ()>
pub const fn own_over2_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck_unchecked(self) -> Own<Self, ()>
Duplicates the top element before the next of stack element, unchecked version.
( 1 2 -- 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackU16<i32, 4> = StackU16::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Sourcepub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
Duplicates the top pair of elements before the next of stack pair of elements, unchecked version.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU16<i32, 7> = StackU16::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
§Chainable const
impl<T: Copy, const CAP: usize> Stack<T, CAP, u32, Bare>
§Chainable const
T: Copy
Every method is const and returns Own
<Self, V>
.
Sourcepub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
pub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
u32::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackU32<i32, 16> = StackU32::own_new(0).s_const_unwrap().s;
Sourcepub const fn own_clear(self) -> Own<Self, ()>
pub const fn own_clear(self) -> Own<Self, ()>
Clears the stack in compile-time.
( 1 2 3 -- )
§Examples
const S: StackU32<i32, 3> = StackU32::from_array_copy([1, 2, 3]).own_clear().s;
assert![S.is_empty()];
Sourcepub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
pub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
Pushes a new element
to the top of the stack in compile-time.
( 1 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughSpace
>
if the stack is full.
§Examples
const S: StackU32<i32, 2> = StackU32::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s
.own_push(2).v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 2]];
assert![S.own_push(3).v.is_err_and(|e| matches![e, NotEnoughSpace])];
Sourcepub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
pub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
Sourcepub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
Pops the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackU32<i32, 3>, Result<i32, NotEnoughElements>> =
StackU32::from_array_copy([1, 2, 3]).own_pop();
S.s_assert(|s| s.as_slice() == &[1, 2]).v_assert_eq(&Ok(3));
Sourcepub const fn own_pop_unchecked(self) -> Own<Self, T>
pub const fn own_pop_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
Peeks the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackU32<i32, 3>, Result<i32, NotEnoughElements>> =
StackU32::from_array_copy([1, 2, 3]).own_peek();
S.s_assert(|s| s.as_slice() == &[1, 2, 3]).v_assert_eq(&Ok(3));
Sourcepub const fn own_peek_unchecked(self) -> Own<Self, T>
pub const fn own_peek_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top stack element in compile-time.
( 1 2 -- 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: StackU32<i32, 2> = StackU32::from_array_copy([1, 2])
.own_drop().v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
const T: StackU32<i32, 2> = StackU32::own_new(0).s_const_unwrap().s
.own_drop().v_assert_err().s;
assert![T.is_empty()];
Sourcepub const fn own_drop_unchecked(self) -> Own<Self, ()>
pub const fn own_drop_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_drop_n(
self,
n: u32,
) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop_n( self, n: u32, ) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least n
elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([1, 2, 3, 4])
.own_drop_n(3).v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
Sourcepub const fn own_drop_n_unchecked(self, n: u32) -> Own<Self, ()>
pub const fn own_drop_n_unchecked(self, n: u32) -> Own<Self, ()>
Sourcepub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the next of stack element in compile-time.
( 1 2 -- 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackU32<i32, 2> = StackU32::from_array_copy([1, 2])
.own_nip().v_assert_ok().s;
assert_eq![S.as_slice(), &[2]];
const T: StackU32<i32, 2> = StackU32::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s.own_nip().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_nip_unchecked(self) -> Own<Self, ()>
pub const fn own_nip_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([1, 2, 3, 4])
.own_nip2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4]];
Sourcepub const fn own_nip2_unchecked(self) -> Own<Self, ()>
pub const fn own_nip2_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two stack elements in compile-time.
( 1 2 -- 2 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackU32<i32, 2> = StackU32::from_array_copy([1, 2])
.own_swap().v_assert_ok().s;
assert_eq![S.as_slice(), &[2, 1]];
const T: StackU32<i32, 1> = StackU32::from_array_copy([1])
.own_swap().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_swap_unchecked(self) -> Own<Self, ()>
pub const fn own_swap_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two pair stack elements in compile-time.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([1, 2, 3, 4])
.own_swap2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
const T: StackU32<i32, 3> = StackU32::from_array_copy([1, 2, 3])
.own_swap2().v_assert_err().s;
assert_eq![T.as_slice(), &[1, 2, 3]];
Sourcepub const fn own_swap2_unchecked(self) -> Own<Self, ()>
pub const fn own_swap2_unchecked(self) -> Own<Self, ()>
Swaps the top two pair stack elements in compile-time, unchecked version.
( 1 2 3 4 -- 3 4 1 2 )
§Panics
Panics if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([1, 2, 3, 4])
.own_swap2_unchecked().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
Sourcepub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 3])
.own_rot().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, clockwise, unchecked version.
( 1 2 3 -- 2 3 1 )
§Panics
Panics if the stack doesn’t contain at least 6 elements. if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 3])
.own_rot_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 3])
.own_rot_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, counter-clockwise, unchecked version.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 3])
.own_rot_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, counter-clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack is empty or
Own<self,
DataNotEnough::Space
>
if the stack is full.
§Examples
const S: StackU32<i32, 3> = StackU32::own_new(0).s_const_unwrap().s
.own_push(1).s.own_dup().v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 1]];
Sourcepub const fn own_dup_unchecked(self) -> Own<Self, ()>
pub const fn own_dup_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 6> = StackU32::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_dup2_unchecked(self) -> Own<Self, ()>
pub const fn own_dup2_unchecked(self) -> Own<Self, ()>
Duplicates the top stack pair of elements, unchecked version.
( 1 2 -- 1 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 6> = StackU32::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over_unchecked(self) -> Own<Self, ()>
pub const fn own_over_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_over2_unchecked(self) -> Own<Self, ()>
pub const fn own_over2_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck_unchecked(self) -> Own<Self, ()>
Duplicates the top element before the next of stack element, unchecked version.
( 1 2 -- 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackU32<i32, 4> = StackU32::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Sourcepub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
Duplicates the top pair of elements before the next of stack pair of elements, unchecked version.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackU32<i32, 7> = StackU32::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Source§impl<T: Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
§Chainable const
impl<T: Copy, const CAP: usize> Stack<T, CAP, usize, Bare>
§Chainable const
T: Copy
Every method is const and returns Own
<Self, V>
.
Sourcepub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
pub const fn own_new(element: T) -> Own<Result<Self, MismatchedCapacity>, ()>
Returns an empty stack, allocated in the stack,
copying element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
usize::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: StackUsize<i32, 16> = StackUsize::own_new(0).s_const_unwrap().s;
Sourcepub const fn own_clear(self) -> Own<Self, ()>
pub const fn own_clear(self) -> Own<Self, ()>
Clears the stack in compile-time.
( 1 2 3 -- )
§Examples
const S: StackUsize<i32, 3> = StackUsize::from_array_copy([1, 2, 3]).own_clear().s;
assert![S.is_empty()];
Sourcepub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
pub const fn own_push(self, element: T) -> Own<Self, Result<(), NotEnoughSpace>>
Pushes a new element
to the top of the stack in compile-time.
( 1 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughSpace
>
if the stack is full.
§Examples
const S: StackUsize<i32, 2> = StackUsize::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s
.own_push(2).v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 2]];
assert![S.own_push(3).v.is_err_and(|e| matches![e, NotEnoughSpace])];
Sourcepub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
pub const fn own_push_unchecked(self, element: T) -> Own<Self, ()>
Sourcepub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_pop(self) -> Own<Self, Result<T, NotEnoughElements>>
Pops the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackUsize<i32, 3>, Result<i32, NotEnoughElements>> =
StackUsize::from_array_copy([1, 2, 3]).own_pop();
S.s_assert(|s| s.as_slice() == &[1, 2]).v_assert_eq(&Ok(3));
Sourcepub const fn own_pop_unchecked(self) -> Own<Self, T>
pub const fn own_pop_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
pub const fn own_peek(self) -> Own<Self, Result<T, NotEnoughElements>>
Peeks the top stack element in compile-time.
( 1 2 3 -- 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: Own<StackUsize<i32, 3>, Result<i32, NotEnoughElements>> =
StackUsize::from_array_copy([1, 2, 3]).own_peek();
S.s_assert(|s| s.as_slice() == &[1, 2, 3]).v_assert_eq(&Ok(3));
Sourcepub const fn own_peek_unchecked(self) -> Own<Self, T>
pub const fn own_peek_unchecked(self) -> Own<Self, T>
Sourcepub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top stack element in compile-time.
( 1 2 -- 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack is empty.
§Examples
const S: StackUsize<i32, 2> = StackUsize::from_array_copy([1, 2])
.own_drop().v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
const T: StackUsize<i32, 2> = StackUsize::own_new(0).s_const_unwrap().s
.own_drop().v_assert_err().s;
assert![T.is_empty()];
Sourcepub const fn own_drop_unchecked(self) -> Own<Self, ()>
pub const fn own_drop_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_drop_n(
self,
n: usize,
) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_drop_n( self, n: usize, ) -> Own<Self, Result<(), NotEnoughElements>>
Drops the top n
stack elements.
( 1 2 3 4 -- 1 )
for n == 3
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least n
elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([1, 2, 3, 4])
.own_drop_n(3).v_assert_ok().s;
assert_eq![S.as_slice(), &[1]];
Sourcepub const fn own_drop_n_unchecked(self, n: usize) -> Own<Self, ()>
pub const fn own_drop_n_unchecked(self, n: usize) -> Own<Self, ()>
Sourcepub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the next of stack element in compile-time.
( 1 2 -- 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackUsize<i32, 2> = StackUsize::from_array_copy([1, 2])
.own_nip().v_assert_ok().s;
assert_eq![S.as_slice(), &[2]];
const T: StackUsize<i32, 2> = StackUsize::own_new(0).s_const_unwrap().s
.own_push(1).v_assert_ok().s.own_nip().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_nip_unchecked(self) -> Own<Self, ()>
pub const fn own_nip_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_nip2(self) -> Own<Self, Result<(), NotEnoughElements>>
Drops the pair of next stack elements.
( 1 2 3 4 -- 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([1, 2, 3, 4])
.own_nip2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4]];
Sourcepub const fn own_nip2_unchecked(self) -> Own<Self, ()>
pub const fn own_nip2_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two stack elements in compile-time.
( 1 2 -- 2 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 2 elements.
§Examples
const S: StackUsize<i32, 2> = StackUsize::from_array_copy([1, 2])
.own_swap().v_assert_ok().s;
assert_eq![S.as_slice(), &[2, 1]];
const T: StackUsize<i32, 1> = StackUsize::from_array_copy([1])
.own_swap().v_assert_err().s;
assert_eq![T.as_slice(), &[1]];
Sourcepub const fn own_swap_unchecked(self) -> Own<Self, ()>
pub const fn own_swap_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_swap2(self) -> Own<Self, Result<(), NotEnoughElements>>
Swaps the top two pair stack elements in compile-time.
( 1 2 3 4 -- 3 4 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([1, 2, 3, 4])
.own_swap2().v_assert_ok().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
const T: StackUsize<i32, 3> = StackUsize::from_array_copy([1, 2, 3])
.own_swap2().v_assert_err().s;
assert_eq![T.as_slice(), &[1, 2, 3]];
Sourcepub const fn own_swap2_unchecked(self) -> Own<Self, ()>
pub const fn own_swap2_unchecked(self) -> Own<Self, ()>
Swaps the top two pair stack elements in compile-time, unchecked version.
( 1 2 3 4 -- 3 4 1 2 )
§Panics
Panics if the stack doesn’t contain at least 4 elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([1, 2, 3, 4])
.own_swap2_unchecked().s;
assert_eq![S.as_slice(), &[3, 4, 1, 2]];
Sourcepub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, clockwise.
( 1 2 3 -- 2 3 1 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 3])
.own_rot().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, clockwise, unchecked version.
( 1 2 3 -- 2 3 1 )
§Panics
Panics if the stack doesn’t contain at least 6 elements. if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 3])
.own_rot_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 3, 1]];
Sourcepub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top three stack elements, counter-clockwise.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 3])
.own_rot_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot_cc_unchecked(self) -> Own<Self, ()>
Rotates the top three stack elements, counter-clockwise, unchecked version.
( 1 2 3 -- 3 1 2 )
§Errors
Returns Own<S,
NotEnoughElements
>
if the stack doesn’t contain at least 3 elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 3])
.own_rot_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 1, 2]];
Sourcepub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, clockwise, two times.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 3 4 5 6 1 2 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 5, 6, 1, 2]];
Sourcepub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
pub const fn own_rot2_cc(self) -> Own<Self, Result<(), NotEnoughElements>>
Rotates the top six stack elements, counter-clockwise, two times.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Errors
Returns Own<self,
NotEnoughElements
>
if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
pub const fn own_rot2_cc_unchecked(self) -> Own<Self, ()>
Rotates the top six stack elements, counter-clockwise, two times, unchecked version.
( 1 2 3 4 5 6 -- 5 6 1 2 3 4 )
§Panics
Panics if the stack doesn’t contain at least 6 elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 5, 6])
.own_rot2_cc_unchecked().s;
assert_eq![S.as_slice(), &[0, 5, 6, 1, 2, 3, 4]];
Sourcepub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack element.
( 1 -- 1 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack is empty or
Own<self,
DataNotEnough::Space
>
if the stack is full.
§Examples
const S: StackUsize<i32, 3> = StackUsize::own_new(0).s_const_unwrap().s
.own_push(1).s.own_dup().v_assert_ok().s;
assert_eq![S.as_slice(), &[1, 1]];
Sourcepub const fn own_dup_unchecked(self) -> Own<Self, ()>
pub const fn own_dup_unchecked(self) -> Own<Self, ()>
Sourcepub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_dup2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top stack pair of elements.
( 1 2 -- 1 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 6> = StackUsize::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_dup2_unchecked(self) -> Own<Self, ()>
pub const fn own_dup2_unchecked(self) -> Own<Self, ()>
Duplicates the top stack pair of elements, unchecked version.
( 1 2 -- 1 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 6> = StackUsize::from_array_copy([0, 1, 2, 0, 0, 0])
.own_drop_n(3).s.own_dup2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1, 2]];
Sourcepub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over_unchecked(self) -> Own<Self, ()>
pub const fn own_over_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack element to the top.
( 1 2 -- 1 2 1 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_over_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 1]];
Sourcepub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_over2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_over2_unchecked(self) -> Own<Self, ()>
pub const fn own_over2_unchecked(self) -> Own<Self, ()>
Duplicates the next of stack pair of elements to the top.
( 1 2 3 4 -- 1 2 3 4 1 2 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_over2_unchecked().s;
assert_eq![S.as_slice(), &[0, 1, 2, 3, 4, 1, 2]];
Sourcepub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top element before the next of stack element.
( 1 2 -- 2 1 2 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 2 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck().v_assert_ok().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck_unchecked(self) -> Own<Self, ()>
Duplicates the top element before the next of stack element, unchecked version.
( 1 2 -- 2 1 2 )
§Panics
Panics if the stack doesn’t have at least 2 elements, or if it doesn’t have enough space for 1 extra elements.
§Examples
const S: StackUsize<i32, 4> = StackUsize::from_array_copy([0, 1, 2, 0])
.own_drop().s.own_tuck_unchecked().s;
assert_eq![S.as_slice(), &[0, 2, 1, 2]];
Sourcepub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
pub const fn own_tuck2(self) -> Own<Self, Result<(), DataNotEnough>>
Duplicates the top pair of elements before the next of stack pair of elements.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Errors
Returns Own<self,
DataNotEnough::Elements
>
if the stack doesn’t have at least 4 elements,
or Own<self,
DataNotEnough::Space
>
if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Sourcepub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
pub const fn own_tuck2_unchecked(self) -> Own<Self, ()>
Duplicates the top pair of elements before the next of stack pair of elements, unchecked version.
( 1 2 3 4 -- 3 4 1 2 3 4 )
§Panics
Panics if the stack doesn’t have at least 4 elements, or if it doesn’t have enough space for 2 extra elements.
§Examples
const S: StackUsize<i32, 7> = StackUsize::from_array_copy([0, 1, 2, 3, 4, 0, 0])
.own_drop_n(2).s.own_tuck2_unchecked().s;
assert_eq![S.as_slice(), &[0, 3, 4, 1, 2, 3, 4]];
Trait Implementations§
Source§impl<T, const CAP: usize, IDX, S: Storage> Archive for Stack<T, CAP, IDX, S>
impl<T, const CAP: usize, IDX, S: Storage> Archive for Stack<T, CAP, IDX, S>
Source§type Archived = ArchivedStack<T, CAP, IDX, S>
type Archived = ArchivedStack<T, CAP, IDX, S>
Source§type Resolver = StackResolver<T, CAP, IDX, S>
type Resolver = StackResolver<T, CAP, IDX, S>
Source§fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize
. Read moreSource§impl<T: ConstDefault, const CAP: usize, IDX: ConstDefault> ConstDefault for Stack<T, CAP, IDX, Bare>
impl<T: ConstDefault, const CAP: usize, IDX: ConstDefault> ConstDefault for Stack<T, CAP, IDX, Bare>
Source§impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, u16, S>
impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, u16, S>
Source§fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is empty, false
if it’s not.Source§fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is full, false
if it’s not.Source§fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
true
if the collection contains the given element
.Source§fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
element
appears in the collection.Source§impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, u32, S>
impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, u32, S>
Source§fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is empty, false
if it’s not.Source§fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is full, false
if it’s not.Source§fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
true
if the collection contains the given element
.Source§fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
element
appears in the collection.Source§impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, u8, S>
impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, u8, S>
Source§fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is empty, false
if it’s not.Source§fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is full, false
if it’s not.Source§fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
true
if the collection contains the given element
.Source§fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
element
appears in the collection.Source§impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, usize, S>
impl<T, const LEN: usize, S: Storage> DataCollection for Stack<T, LEN, usize, S>
Source§fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is empty, false
if it’s not.Source§fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is full, false
if it’s not.Source§fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
true
if the collection contains the given element
.Source§fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
element
appears in the collection.Source§impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, u16, S>
impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, u16, S>
Source§fn stack_pop(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn stack_pop( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
Source§fn stack_push(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn stack_push( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
Source§impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, u32, S>
impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, u32, S>
Source§fn stack_pop(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn stack_pop( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
Source§fn stack_push(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn stack_push( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
Source§impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, u8, S>
impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, u8, S>
Source§fn stack_pop(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn stack_pop( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
Source§fn stack_push(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn stack_push( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
Source§impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, usize, S>
impl<T, const CAP: usize, S: Storage> DataStack for Stack<T, CAP, usize, S>
Source§fn stack_pop(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn stack_pop( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
Source§fn stack_push(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn stack_push( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
Source§impl<T: Default, const CAP: usize, IDX: Default> Default for Stack<T, CAP, IDX, Boxed>
Available on crate feature alloc
only.
impl<T: Default, const CAP: usize, IDX: Default> Default for Stack<T, CAP, IDX, Boxed>
alloc
only.Source§impl<__D: Fallible + ?Sized, T, const CAP: usize, IDX, S: Storage> Deserialize<Stack<T, CAP, IDX, S>, __D> for Archived<Stack<T, CAP, IDX, S>>
impl<__D: Fallible + ?Sized, T, const CAP: usize, IDX, S: Storage> Deserialize<Stack<T, CAP, IDX, S>, __D> for Archived<Stack<T, CAP, IDX, S>>
Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u16, Bare>where
I: IntoIterator<Item = T>,
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u16, Bare>where
I: IntoIterator<Item = T>,
Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u16, Boxed>where
I: IntoIterator<Item = T>,
Available on crate feature alloc
only.
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u16, Boxed>where
I: IntoIterator<Item = T>,
alloc
only.Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u32, Bare>where
I: IntoIterator<Item = T>,
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u32, Bare>where
I: IntoIterator<Item = T>,
Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u32, Boxed>where
I: IntoIterator<Item = T>,
Available on crate feature alloc
only.
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u32, Boxed>where
I: IntoIterator<Item = T>,
alloc
only.Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u8, Bare>where
I: IntoIterator<Item = T>,
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u8, Bare>where
I: IntoIterator<Item = T>,
Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u8, Boxed>where
I: IntoIterator<Item = T>,
Available on crate feature alloc
only.
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, u8, Boxed>where
I: IntoIterator<Item = T>,
alloc
only.Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, usize, Bare>where
I: IntoIterator<Item = T>,
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, usize, Bare>where
I: IntoIterator<Item = T>,
Source§impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, usize, Boxed>where
I: IntoIterator<Item = T>,
Available on crate feature alloc
only.
impl<T: Default, I, const CAP: usize> From<I> for Stack<T, CAP, usize, Boxed>where
I: IntoIterator<Item = T>,
alloc
only.Source§impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, u16, S>
impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, u16, S>
Source§impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, u32, S>
impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, u32, S>
Source§impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, u8, S>
impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, u8, S>
Source§impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, usize, S>
impl<T: Ord, const CAP: usize, S: Storage> Ord for Stack<T, CAP, usize, S>
Source§impl<T: PartialEq, const CAP: usize, IDX: PartialEq, S: Storage> PartialEq for Stack<T, CAP, IDX, S>
impl<T: PartialEq, const CAP: usize, IDX: PartialEq, S: Storage> PartialEq for Stack<T, CAP, IDX, S>
Source§impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, u16, S>
impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, u16, S>
Source§impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, u32, S>
impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, u32, S>
Source§impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, u8, S>
impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, u8, S>
Source§impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, usize, S>
impl<T: PartialOrd, const CAP: usize, S: Storage> PartialOrd for Stack<T, CAP, usize, S>
Source§impl<__S: Fallible + ?Sized, T, const CAP: usize, IDX, S: Storage> Serialize<__S> for Stack<T, CAP, IDX, S>
impl<__S: Fallible + ?Sized, T, const CAP: usize, IDX, S: Storage> Serialize<__S> for Stack<T, CAP, IDX, S>
impl<T: Copy, const CAP: usize, IDX: Copy, S: Storage> Copy for Stack<T, CAP, IDX, S>
impl<T: Eq, const CAP: usize, IDX: Eq, S: Storage> Eq for Stack<T, CAP, IDX, S>
Auto Trait Implementations§
impl<T, const CAP: usize, IDX, S> Freeze for Stack<T, CAP, IDX, S>
impl<T, const CAP: usize, IDX, S> RefUnwindSafe for Stack<T, CAP, IDX, S>
impl<T, const CAP: usize, IDX, S> Send for Stack<T, CAP, IDX, S>
impl<T, const CAP: usize, IDX, S> Sync for Stack<T, CAP, IDX, S>
impl<T, const CAP: usize, IDX, S> Unpin for Stack<T, CAP, IDX, S>
impl<T, const CAP: usize, IDX, S> UnwindSafe for Stack<T, CAP, IDX, S>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive
, it may be
unsized. Read more§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.