Debian Codegraph @

third_party/rust/minidump-writer/src/serializers.rs

raw
1 //! Functions used by Serde to serialize types that we don't own (and thus can't implement
2 //! [Serialize] for)
3
4 use serde::Serializer;
5 /// Useful for types that implement [Error][std::error::Error] and don't need any special
6 /// treatment.
7 pub fn serialize_generic_error<S: Serializer, E: std::error::Error>(
8 error: &E,
9 serializer: S,
10 ) -> Result<S::Ok, S::Error> {
11 // I guess we'll have to see if it's more useful to store the debug representation of a
12 // foreign error type or something else (like maybe iterating its error chain into a
13 // list?)
14 let dbg = format!("{error:#?}");
15 serializer.serialize_str(&dbg)
16 }
17 /// Serialize [std::io::Error]
18 pub fn serialize_io_error<S: Serializer>(
19 error: &std::io::Error,
20 serializer: S,
21 ) -> Result<S::Ok, S::Error> {
22 serialize_generic_error(error, serializer)
23 }
24 /// Serialize [scroll::Error]
25 pub fn serialize_scroll_error<S: Serializer>(
26 error: &scroll::Error,
27 serializer: S,
28 ) -> Result<S::Ok, S::Error> {
29 serialize_generic_error(error, serializer)
30 }