1use thiserror::Error;
6
7use fidl_next_codec::{DecodeError, EncodeError};
8
9#[derive(Debug)]
11pub struct UnknownStrictEnumMemberError(i128);
12
13impl UnknownStrictEnumMemberError {
14 pub fn new(unknown_value: i128) -> Self {
16 Self(unknown_value)
17 }
18}
19
20impl core::fmt::Display for UnknownStrictEnumMemberError {
21 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
22 write!(f, "Strict enum doesn't have a member with value: {}", self.0)
23 }
24}
25
26impl core::error::Error for UnknownStrictEnumMemberError {}
27
28#[derive(Error, Clone, Debug)]
30pub enum Error<
31 #[cfg(feature = "fuchsia")] E = <zx::Channel as fidl_next_protocol::Transport>::Error,
32 #[cfg(not(feature = "fuchsia"))] E,
33> {
34 #[error("encoding error: {0}")]
36 Encode(#[from] EncodeError),
37 #[error("decoding error: {0}")]
39 Decode(#[from] DecodeError),
40 #[error("transport error: {0}")]
42 Transport(E),
43 #[error("the transport was closed")]
45 Closed,
46}
47
48impl<E> From<Option<E>> for Error<E> {
49 fn from(value: Option<E>) -> Self {
50 if let Some(e) = value {
51 Self::Transport(e)
52 } else {
53 Self::Closed
54 }
55 }
56}