nimble_host/
err.rs

1/*
2 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/nimble-rust/nimble
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 */
5
6use datagram_chunker::DatagramChunkerError;
7use err_rs::{ErrorLevel, ErrorLevelProvider};
8use nimble_host_logic::err::HostLogicError;
9use nimble_layer::NimbleLayerError;
10
11#[derive(Debug)]
12pub enum HostError {
13    ConnectionNotFound(u8),
14    IoError(std::io::Error),
15    NimbleLayerError(NimbleLayerError),
16    HostLogicError(HostLogicError),
17    DatagramChunkerError(DatagramChunkerError),
18}
19
20impl ErrorLevelProvider for HostError {
21    fn error_level(&self) -> ErrorLevel {
22        match self {
23            Self::IoError(_) => ErrorLevel::Warning,
24            Self::ConnectionNotFound(_) => ErrorLevel::Warning,
25            Self::NimbleLayerError(_) => ErrorLevel::Warning,
26            Self::HostLogicError(err) => err.error_level(),
27            Self::DatagramChunkerError(err) => err.error_level(),
28        }
29    }
30}
31
32impl From<DatagramChunkerError> for HostError {
33    fn from(err: DatagramChunkerError) -> Self {
34        Self::DatagramChunkerError(err)
35    }
36}
37
38impl From<HostLogicError> for HostError {
39    fn from(err: HostLogicError) -> Self {
40        Self::HostLogicError(err)
41    }
42}
43
44impl From<NimbleLayerError> for HostError {
45    fn from(e: NimbleLayerError) -> Self {
46        Self::NimbleLayerError(e)
47    }
48}
49
50impl From<std::io::Error> for HostError {
51    fn from(err: std::io::Error) -> Self {
52        Self::IoError(err)
53    }
54}