#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[allow(clippy::exhaustive_structs, clippy::single_char_lifetime_names)]
pub struct Indexed<'value, Value> {
pub index: usize,
pub value: &'value Value,
}
#[allow(clippy::needless_pass_by_value)]
#[inline(always)]
#[must_use]
pub const fn index<Value>(indexed: Indexed<'_, Value>) -> usize {
indexed.index
}
#[allow(clippy::needless_pass_by_value)]
#[inline(always)]
#[must_use]
pub const fn value<Value>(indexed: Indexed<'_, Value>) -> &Value {
indexed.value
}
#[allow(clippy::needless_pass_by_value)]
#[inline(always)]
#[must_use]
pub fn clone_value<Value: Clone>(indexed: Indexed<'_, Value>) -> Value {
indexed.value.clone()
}
#[allow(clippy::needless_pass_by_value)]
#[inline(always)]
#[must_use]
pub const fn copy_value<Value: Copy>(indexed: Indexed<'_, Value>) -> Value {
*indexed.value
}
pub trait OptionIndexed<'value> {
type Value;
#[must_use]
fn index(&self) -> Option<usize>;
#[must_use]
fn value(&self) -> Option<&'value Self::Value>;
}
impl<'value, Value> OptionIndexed<'value> for Option<Indexed<'value, Value>> {
type Value = Value;
#[inline(always)]
#[must_use]
fn index(&self) -> Option<usize> {
self.as_ref().map(|i| i.index)
}
#[inline(always)]
#[must_use]
fn value(&self) -> Option<&'value Self::Value> {
self.as_ref().map(|i| i.value)
}
}