sheave_core/messages/amf/
invalid_string.rs

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
use std::{
    error::Error,
    fmt::{
        Display,
        Formatter,
        Result as FormatResult
    },
    io::{
        Error as IOError,
        ErrorKind
    },
    string::FromUtf8Error
};

/// An error that some string data is invalid for UTF-8.
#[derive(Debug)]
pub struct InvalidString(FromUtf8Error);

impl InvalidString {
    /// Constructs this error.
    pub fn new(e: FromUtf8Error) -> Self {
        Self(e)
    }
}

impl Display for InvalidString {
    fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
        Display::fmt(&self.0, f)
    }
}

impl Error for InvalidString {}

/// A utility function of constructing an `InvalidString` error.
pub fn invalid_string(e: FromUtf8Error) -> IOError {
    IOError::new(
        ErrorKind::InvalidData,
        InvalidString(e)
    )
}