Struct Slice
#[repr(transparent)]pub struct Slice<K, V> {
pub(crate) entries: [Bucket<K, V>],
}
Expand description
Fields§
§entries: [Bucket<K, V>]
Implementations§
§impl<K, V> Slice<K, V>
impl<K, V> Slice<K, V>
pub fn get_index(&self, index: usize) -> Option<(&K, &V)>
pub fn get_index(&self, index: usize) -> Option<(&K, &V)>
Get a key-value pair by index.
Valid indices are 0 <= index < self.len()
.
pub fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)>
pub fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)>
Get a key-value pair by index, with mutable access to the value.
Valid indices are 0 <= index < self.len()
.
pub fn get_range<R>(&self, range: R) -> Option<&Slice<K, V>>where
R: RangeBounds<usize>,
pub fn get_range<R>(&self, range: R) -> Option<&Slice<K, V>>where
R: RangeBounds<usize>,
Returns a slice of key-value pairs in the given range of indices.
Valid indices are 0 <= index < self.len()
.
pub fn get_range_mut<R>(&mut self, range: R) -> Option<&mut Slice<K, V>>where
R: RangeBounds<usize>,
pub fn get_range_mut<R>(&mut self, range: R) -> Option<&mut Slice<K, V>>where
R: RangeBounds<usize>,
Returns a mutable slice of key-value pairs in the given range of indices.
Valid indices are 0 <= index < self.len()
.
pub fn first_mut(&mut self) -> Option<(&K, &mut V)>
pub fn first_mut(&mut self) -> Option<(&K, &mut V)>
Get the first key-value pair, with mutable access to the value.
pub fn last_mut(&mut self) -> Option<(&K, &mut V)>
pub fn last_mut(&mut self) -> Option<(&K, &mut V)>
Get the last key-value pair, with mutable access to the value.
pub fn split_at(&self, index: usize) -> (&Slice<K, V>, &Slice<K, V>)
pub fn split_at(&self, index: usize) -> (&Slice<K, V>, &Slice<K, V>)
Divides one slice into two at an index.
Panics if index > len
.
pub fn split_at_mut(
&mut self,
index: usize,
) -> (&mut Slice<K, V>, &mut Slice<K, V>)
pub fn split_at_mut( &mut self, index: usize, ) -> (&mut Slice<K, V>, &mut Slice<K, V>)
Divides one mutable slice into two at an index.
Panics if index > len
.
pub fn split_first(&self) -> Option<((&K, &V), &Slice<K, V>)>
pub fn split_first(&self) -> Option<((&K, &V), &Slice<K, V>)>
Returns the first key-value pair and the rest of the slice,
or None
if it is empty.
pub fn split_first_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
pub fn split_first_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
Returns the first key-value pair and the rest of the slice,
with mutable access to the value, or None
if it is empty.
pub fn split_last(&self) -> Option<((&K, &V), &Slice<K, V>)>
pub fn split_last(&self) -> Option<((&K, &V), &Slice<K, V>)>
Returns the last key-value pair and the rest of the slice,
or None
if it is empty.
pub fn split_last_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
pub fn split_last_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
Returns the last key-value pair and the rest of the slice,
with mutable access to the value, or None
if it is empty.
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
Return an iterator over the key-value pairs of the map slice.
pub fn into_keys(self: Box<Slice<K, V>>) -> IntoKeys<K, V> ⓘ
pub fn into_keys(self: Box<Slice<K, V>>) -> IntoKeys<K, V> ⓘ
Return an owning iterator over the keys of the map slice.
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
Return an iterator over mutable references to the the values of the map slice.
pub fn into_values(self: Box<Slice<K, V>>) -> IntoValues<K, V> ⓘ
pub fn into_values(self: Box<Slice<K, V>>) -> IntoValues<K, V> ⓘ
Return an owning iterator over the values of the map slice.
pub fn binary_search_keys(&self, x: &K) -> Result<usize, usize>where
K: Ord,
pub fn binary_search_keys(&self, x: &K) -> Result<usize, usize>where
K: Ord,
Search over a sorted map for a key.
Returns the position where that key is present, or the position where it can be inserted to
maintain the sort. See slice::binary_search
for more details.
Computes in O(log(n)) time, which is notably less scalable than looking the key up in
the map this is a slice from using IndexMap::get_index_of
, but this can also position
missing keys.
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
Search over a sorted map with a comparator function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by
for more details.
Computes in O(log(n)) time.
pub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F, ) -> Result<usize, usize>
Search over a sorted map with an extraction function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by_key
for more details.
Computes in O(log(n)) time.
pub fn partition_point<P>(&self, pred: P) -> usize
pub fn partition_point<P>(&self, pred: P) -> usize
Returns the index of the partition point of a sorted map according to the given predicate (the index of the first element of the second partition).
See slice::partition_point
for more details.
Computes in O(log(n)) time.
pub fn get_disjoint_mut<const N: usize>(
&mut self,
indices: [usize; N],
) -> Result<[(&K, &mut V); N], GetDisjointMutError>
pub fn get_disjoint_mut<const N: usize>( &mut self, indices: [usize; N], ) -> Result<[(&K, &mut V); N], GetDisjointMutError>
Get an array of N
key-value pairs by N
indices
Valid indices are 0 <= index < self.len() and each index needs to be unique.
Trait Implementations§
§impl<K, V> Index<RangeInclusive<usize>> for Slice<K, V>
impl<K, V> Index<RangeInclusive<usize>> for Slice<K, V>
§impl<K, V> Index<RangeToInclusive<usize>> for Slice<K, V>
impl<K, V> Index<RangeToInclusive<usize>> for Slice<K, V>
§impl<K, V> IndexMut<RangeInclusive<usize>> for Slice<K, V>
impl<K, V> IndexMut<RangeInclusive<usize>> for Slice<K, V>
§impl<K, V> IndexMut<RangeToInclusive<usize>> for Slice<K, V>
impl<K, V> IndexMut<RangeToInclusive<usize>> for Slice<K, V>
§impl<'a, K, V> IntoIterator for &'a Slice<K, V>
impl<'a, K, V> IntoIterator for &'a Slice<K, V>
§impl<'a, K, V> IntoIterator for &'a mut Slice<K, V>
impl<'a, K, V> IntoIterator for &'a mut Slice<K, V>
§impl<K, V> IntoIterator for Box<Slice<K, V>>
impl<K, V> IntoIterator for Box<Slice<K, V>>
§impl<K, V> PartialOrd for Slice<K, V>where
K: PartialOrd,
V: PartialOrd,
impl<K, V> PartialOrd for Slice<K, V>where
K: PartialOrd,
V: PartialOrd,
§impl<K, V> Serialize for Slice<K, V>
Serializes a map::Slice
as an ordered sequence.
impl<K, V> Serialize for Slice<K, V>
Serializes a map::Slice
as an ordered sequence.
This behaves like crate::map::serde_seq
for IndexMap
, serializing a sequence
of (key, value)
pairs, rather than as a map that might not preserve order.
§fn serialize<T>(
&self,
serializer: T,
) -> Result<<T as Serializer>::Ok, <T as Serializer>::Error>where
T: Serializer,
fn serialize<T>(
&self,
serializer: T,
) -> Result<<T as Serializer>::Ok, <T as Serializer>::Error>where
T: Serializer,
impl<K, V> Eq for Slice<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for Slice<K, V>
impl<K, V> RefUnwindSafe for Slice<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for Slice<K, V>
impl<K, V> !Sized for Slice<K, V>
impl<K, V> Sync for Slice<K, V>
impl<K, V> Unpin for Slice<K, V>
impl<K, V> UnwindSafe for Slice<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
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
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§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.§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
self
to key
and returns true
if they are equal.§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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
fn equivalent(&self, key: &K) -> bool
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.