#![cfg_attr(docsrs, doc(cfg(feature = "cbor-serde")))]
#![cfg(feature = "cbor-serde")]
pub extern crate ciborium as original;
use serde::ser::Serialize;
use serde::de::DeserializeOwned;
use singlefile::FileFormat;
use thiserror::Error;
use std::io::{Read, Write};
#[derive(Debug, Error)]
pub enum CborError {
#[error(transparent)]
SerializeError(#[from] ciborium::ser::Error<std::io::Error>),
#[error(transparent)]
DeserializeError(#[from] ciborium::de::Error<std::io::Error>)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Cbor;
impl<T> FileFormat<T> for Cbor
where T: Serialize + DeserializeOwned {
type FormatError = CborError;
fn from_reader<R: Read>(&self, reader: R) -> Result<T, Self::FormatError> {
ciborium::de::from_reader(reader).map_err(From::from)
}
fn to_writer<W: Write>(&self, writer: W, value: &T) -> Result<(), Self::FormatError> {
ciborium::ser::into_writer(value, writer).map_err(From::from)
}
}
#[cfg_attr(docsrs, doc(cfg(feature = "compression")))]
#[cfg(feature = "compression")]
pub type CompressedCbor<C> = crate::compression::Compressed<C, Cbor>;