//! Functions used by Serde to serialize types that we don't own (and thus can't implement //! [Serialize] for)
use serde::Serializer;
/// Good for types where the value of the thing doesn't have any programmatic use and /// it mostly just matters than a human can read it pubfn serialize_debug_string<S: Serializer, D: std::fmt::Debug>(
d: &D,
serializer: S,
) -> Result<S::Ok, S::Error> { let dbg = format!("{d:#?}");
serializer.serialize_str(&dbg)
}
/// Useful for types that implement [Error][std::error::Error] and don't need any special /// treatment. pubfn serialize_generic_error<S: Serializer, E: std::error::Error>(
error: &E,
serializer: S,
) -> Result<S::Ok, S::Error> { // I guess we'll have to see if it's more useful to store the debug representation of a // foreign error type or something else (like maybe iterating its error chain into a // list?)
serialize_debug_string(error, serializer)
} /// Serialize [std::io::Error] pubfn serialize_io_error<S: Serializer>(
error: &std::io::Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
} /// Serialize [scroll::Error] pubfn serialize_scroll_error<S: Serializer>(
error: &scroll::Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.