use crate::config::Config;
use crate::decode::decode_from_slice;
use crate::error::{DecodeError, Result};
#[derive(Clone, Debug)]
pub struct DefaultOptions { cfg: Config }
impl DefaultOptions {
pub fn new() -> Self { Self { cfg: Config::default() } }
pub fn with_limit(mut self, limit: u64) -> Self { self.cfg.limit = Some(limit as usize); self }
pub fn allow_trailing_bytes(mut self) -> Self { self.cfg.allow_trailing = true; self }
pub fn with_fixint_encoding(mut self) -> Self { self.cfg.use_varint = false; self }
pub fn deserialize<T>(self, data: &[u8]) -> Result<T>
where T: serde::de::DeserializeOwned {
let (val, pos) = decode_from_slice::<T>(data, self.cfg)?;
if !self.cfg.allow_trailing && pos != data.len() { return Err(DecodeError::Message("trailing bytes".into())); }
Ok(val)
}
}
impl Default for DefaultOptions {
fn default() -> Self { Self::new() }
}