use std::fmt;
pub const DEFAULT_DEPTH_LIMIT: usize = 128;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
#[non_exhaustive]
pub enum SizeHints {
All,
#[default]
Sequences,
}
impl SizeHints {
pub(crate) const fn value_writes_len(self) -> bool {
matches!(self, Self::All)
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Cfg<const WITH_IDENTS: bool> {
depth_limit: usize,
size_hints: SizeHints,
}
impl<const WITH_IDENTS: bool> Cfg<WITH_IDENTS> {
pub const DEFAULT_DEPTH_LIMIT: usize = DEFAULT_DEPTH_LIMIT;
pub const fn new() -> Self {
Self { depth_limit: DEFAULT_DEPTH_LIMIT, size_hints: SizeHints::Sequences }
}
pub const fn with_idents(&self) -> bool {
WITH_IDENTS
}
pub const fn with_depth_limit(self, depth_limit: usize) -> Self {
Self { depth_limit, ..self }
}
pub const fn with_size_hints(self, size_hints: SizeHints) -> Self {
Self { size_hints, ..self }
}
pub const fn depth_limit(&self) -> usize {
self.depth_limit
}
pub const fn size_hints(&self) -> SizeHints {
self.size_hints
}
}
impl<const WITH_IDENTS: bool> Default for Cfg<WITH_IDENTS> {
fn default() -> Self {
Self::new()
}
}
impl<const WITH_IDENTS: bool> fmt::Debug for Cfg<WITH_IDENTS> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Cfg")
.field("with_idents", &WITH_IDENTS)
.field("depth_limit", &self.depth_limit)
.field("size_hints", &self.size_hints)
.finish()
}
}
pub type Full = Cfg<true>;
pub type Slim = Cfg<false>;