1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::std::fmt;

/**
An error encountered while streaming a value.

Errors don't capture details of failures, that responsibility is left
to the stream to surface.
*/
#[derive(Debug)]
pub struct Error(());

impl Error {
    /**
    Create a new error.

    More detailed diagnostic information will need to be stored elsewhere.
    */
    #[inline(always)]
    pub fn new() -> Self {
        Error(())
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "failed to stream data")
    }
}

#[cfg(feature = "std")]
mod std_support {
    use super::*;

    use crate::std::error;

    impl error::Error for Error {}
}

/**
A streaming result with a generic failure.

More detailed diagnostic information will need to be stored elsewhere.
*/
#[inline(always)]
pub fn error<T>() -> crate::Result<T> {
    Err(Error::new())
}