# error.rs - source
Source of the Rust file `maplibre/src/error.rs`.
Keywords: rust, rustlang, rust-lang

     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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57

    //! Errors which can happen in various parts of the library.

    use lyon::tessellation::TessellationError;
    use std::fmt;
    use std::fmt::Formatter;
    use std::sync::mpsc::SendError;

    #[derive(Debug)]
    pub enum RenderError {
        Surface(wgpu::SurfaceError),
    }

    impl fmt::Display for RenderError {
        fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
            match self {
                RenderError::Surface(e) => write!(f, "{}", e),
            }
        }
    }

    impl RenderError {
        pub fn should_exit(&self) -> bool {
            match self {
                RenderError::Surface(e) => match e {
                    wgpu::SurfaceError::OutOfMemory => true,
                    _ => false,
                },
            }
        }
    }

    /// Enumeration of errors which can happen during the operation of the library.
    #[derive(Debug)]
    pub enum Error {
        Schedule,
        Network(String),
        Tesselation(TessellationError),
        Render(RenderError),
    }

    impl From<wgpu::SurfaceError> for Error {
        fn from(e: wgpu::SurfaceError) -> Self {
            Error::Render(RenderError::Surface(e))
        }
    }

    impl From<TessellationError> for Error {
        fn from(e: TessellationError) -> Self {
            Error::Tesselation(e)
        }
    }

    impl<T> From<SendError<T>> for Error {
        fn from(_e: SendError<T>) -> Self {
            Error::Schedule
        }
    }