nimble_host/
err.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/nimble-rust/nimble
 * Licensed under the MIT License. See LICENSE in the project root for license information.
 */

use datagram_chunker::DatagramChunkerError;
use err_rs::{ErrorLevel, ErrorLevelProvider};
use nimble_host_logic::err::HostLogicError;
use nimble_layer::NimbleLayerError;

#[derive(Debug)]
pub enum HostError {
    ConnectionNotFound(u8),
    IoError(std::io::Error),
    NimbleLayerError(NimbleLayerError),
    HostLogicError(HostLogicError),
    DatagramChunkerError(DatagramChunkerError),
}

impl ErrorLevelProvider for HostError {
    fn error_level(&self) -> ErrorLevel {
        match self {
            Self::IoError(_) => ErrorLevel::Warning,
            Self::ConnectionNotFound(_) => ErrorLevel::Warning,
            Self::NimbleLayerError(_) => ErrorLevel::Warning,
            Self::HostLogicError(err) => err.error_level(),
            Self::DatagramChunkerError(err) => err.error_level(),
        }
    }
}

impl From<DatagramChunkerError> for HostError {
    fn from(err: DatagramChunkerError) -> Self {
        Self::DatagramChunkerError(err)
    }
}

impl From<HostLogicError> for HostError {
    fn from(err: HostLogicError) -> Self {
        Self::HostLogicError(err)
    }
}

impl From<NimbleLayerError> for HostError {
    fn from(e: NimbleLayerError) -> Self {
        Self::NimbleLayerError(e)
    }
}

impl From<std::io::Error> for HostError {
    fn from(err: std::io::Error) -> Self {
        Self::IoError(err)
    }
}