sval/
result.rs

1use crate::std::fmt;
2
3/**
4An error encountered while streaming a value.
5
6Errors don't capture details of failures, that responsibility is left
7to the stream to surface.
8*/
9#[derive(Debug)]
10pub struct Error(());
11
12impl Error {
13    /**
14    Create a new error.
15
16    More detailed diagnostic information will need to be stored elsewhere.
17    */
18    #[inline(always)]
19    pub fn new() -> Self {
20        Error(())
21    }
22}
23
24impl fmt::Display for Error {
25    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26        write!(f, "failed to stream data")
27    }
28}
29
30#[cfg(feature = "std")]
31mod std_support {
32    use super::*;
33
34    use crate::std::error;
35
36    impl error::Error for Error {}
37}
38
39/**
40A streaming result with a generic failure.
41
42More detailed diagnostic information will need to be stored elsewhere.
43*/
44#[inline(always)]
45pub fn error<T>() -> crate::Result<T> {
46    Err(Error::new())
47}