pub mod toml {
use crate::{Context, Parse};
pub use ::toml::value::{Date, Datetime, Offset, Time};
pub use ::toml::{Spanned, Table, Value, value::Array as Vec};
#[cfg(feature = "parse-impl")]
pub use ::toml::{de, map, ser, value};
use serde::{Deserialize, Serialize};
pub struct Toml<T>(std::marker::PhantomData<T>);
impl<T: for<'a> Deserialize<'a>> Parse for Toml<T> {
type Output = T;
fn parse_borrowed(x: &str) -> crate::Result<Self::Output> {
parse(x)
}
}
#[inline(always)]
pub fn parse<'a, T: Deserialize<'a>>(x: &'a str) -> crate::Result<T> {
::toml::from_str(x).with_context(|| {
format!(
"failed to parse input as toml into {}",
std::any::type_name::<T>()
)
})
}
#[inline(always)]
pub fn read<T: for<'a> Deserialize<'a>>(x: impl std::io::Read) -> crate::Result<T> {
Toml::<T>::parse_read(x)
}
#[cfg(feature = "coroutine")]
pub async fn co_read<T: for<'a> Deserialize<'a>>(
x: impl tokio::io::AsyncRead + Unpin,
) -> crate::Result<T> {
crate::co_read::<Toml<T>>(x).await
}
pub fn stringify<T: ?Sized + Serialize>(x: &T) -> crate::Result<String> {
use crate::Context;
crate::check!(
toml::to_string(x),
"failed to serialize {} to toml",
std::any::type_name::<T>()
)
}
pub fn stringify_pretty<T: ?Sized + Serialize>(x: &T) -> crate::Result<String> {
use crate::Context;
crate::check!(
toml::to_string_pretty(x),
"failed to serialize {} to toml",
std::any::type_name::<T>()
)
}
}
#[cfg_attr(any(docsrs, feature = "nightly"), doc(cfg(feature = "toml")))]
pub use ::toml::toml;