use std::error::Error;
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq)]
#[must_use = "the error contains the input that was not inserted"]
pub struct TryInsertError<K, O, V> {
key: K,
order: O,
value: V,
}
impl<K, O, V> TryInsertError<K, O, V> {
#[inline]
pub(super) const fn new(key: K, order: O, value: V) -> Self {
Self { key, order, value }
}
#[must_use = "the key is part of the rejected input"]
#[inline]
pub const fn key(&self) -> &K {
&self.key
}
#[must_use = "the ordered key is part of the rejected input"]
#[inline]
pub const fn order(&self) -> &O {
&self.order
}
#[must_use = "the value is part of the rejected input"]
#[inline]
pub const fn value(&self) -> &V {
&self.value
}
#[must_use = "the returned components are the complete rejected input"]
#[inline]
pub fn into_parts(self) -> (K, O, V) {
(self.key, self.order, self.value)
}
}
impl<K, O, V> fmt::Display for TryInsertError<K, O, V> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("primary key is already present")
}
}
impl<K, O, V> Error for TryInsertError<K, O, V>
where
K: fmt::Debug,
O: fmt::Debug,
V: fmt::Debug,
{
}