#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
use bounded_static_derive::ToStatic;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::{
core::{AString, NString8, Vec1},
error::ValidationError,
};
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToStatic)]
pub struct EntryValue<'a> {
pub entry: Entry<'a>,
pub value: NString8<'a>,
}
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToStatic)]
pub struct Entry<'a>(AString<'a>);
impl<'a> Entry<'a> {
pub fn inner(&self) -> &AString<'a> {
&self.0
}
}
impl<'a> TryFrom<AString<'a>> for Entry<'a> {
type Error = ValidationError;
fn try_from(value: AString<'a>) -> Result<Self, Self::Error> {
Ok(Self(value))
}
}
impl AsRef<[u8]> for Entry<'_> {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToStatic)]
pub enum GetMetadataOption {
MaxSize(u32),
Depth(Depth),
}
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToStatic)]
pub enum Depth {
Null,
One,
Infinity,
}
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToStatic)]
pub enum MetadataCode {
LongEntries(u32),
MaxSize(u32),
TooMany,
NoPrivate,
}
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToStatic)]
pub enum MetadataResponse<'a> {
WithValues(Vec1<EntryValue<'a>>),
WithoutValues(Vec1<Entry<'a>>),
}