mod array;
mod error;
mod key;
mod map;
mod pretty;
mod value;
use crate::visit_mut::VisitMut as _;
#[allow(clippy::wildcard_imports)]
use array::*;
#[allow(clippy::wildcard_imports)]
use map::*;
pub use error::Error;
pub use value::ValueSerializer;
#[cfg(feature = "display")]
pub fn to_vec<T>(value: &T) -> Result<Vec<u8>, Error>
where
T: serde_core::ser::Serialize + ?Sized,
{
to_string(value).map(|e| e.into_bytes())
}
#[cfg(feature = "display")]
pub fn to_string<T>(value: &T) -> Result<String, Error>
where
T: serde_core::ser::Serialize + ?Sized,
{
to_document(value).map(|e| e.to_string())
}
#[cfg(feature = "display")]
pub fn to_string_pretty<T>(value: &T) -> Result<String, Error>
where
T: serde_core::ser::Serialize + ?Sized,
{
let mut document = to_document(value)?;
pretty::Pretty::new().visit_document_mut(&mut document);
Ok(document.to_string())
}
pub fn to_document<T>(value: &T) -> Result<crate::DocumentMut, Error>
where
T: serde_core::ser::Serialize + ?Sized,
{
let value = value.serialize(ValueSerializer::new())?;
let item = crate::Item::Value(value);
let root = item
.into_table()
.map_err(|_| Error::UnsupportedType(None))?;
Ok(root.into())
}