cyclonedds_sys/
dds_error.rs1use std::{error::Error, fmt};
18
19use crate::dds_return_t;
20
21#[derive(Debug, PartialEq, Clone)]
22pub enum DDSError {
23 DdsOk,
24 DdsError,
25 Unsupported,
26 BadParameter,
27 PreconditionNotMet,
28 OutOfResources,
29 NotEnabled,
30 ImmutablePolicy,
31 InconsistentPolicy,
32 AlreadyDeleted,
33 Timeout,
34 NoData,
35 IllegalOperation,
36 NotAllowedBySecurity,
37}
38
39impl Error for DDSError {}
40
41impl fmt::Display for DDSError {
42 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43 match self {
44 DDSError::DdsOk => write!(f, "OK"),
45 DDSError::DdsError => write!(f, "Unspecified Error"),
46 DDSError::Unsupported => write!(f, "Unsupported"),
47 DDSError::BadParameter => write!(f, "Bad parameter"),
48 DDSError::PreconditionNotMet => write!(f, "Preconditions not met"),
49 DDSError::OutOfResources => write!(f, "Out of resources"),
50 DDSError::NotEnabled => write!(f, "Not enabled"),
51 DDSError::ImmutablePolicy => write!(f, "Immutable policy"),
52 DDSError::InconsistentPolicy => write!(f, "Inconsistent polocy"),
53 DDSError::AlreadyDeleted => write!(f, "Already deleted"),
54 DDSError::Timeout => write!(f, "Timeout"),
55 DDSError::NoData => write!(f, "No Data"),
56 DDSError::IllegalOperation => write!(f, "Illegal operation"),
57 DDSError::NotAllowedBySecurity => write!(f, "Not allowed by security"),
58 }
59 }
60}
61
62impl From<dds_return_t> for DDSError {
66 fn from(entity: dds_return_t) -> Self {
67 match Some(entity) {
68 Some(0) => DDSError::DdsOk,
69 Some(-1) => DDSError::DdsError,
70 Some(-2) => DDSError::Unsupported,
71 Some(-3) => DDSError::BadParameter,
72 Some(-4) => DDSError::PreconditionNotMet,
73 Some(-5) => DDSError::OutOfResources,
74 Some(-6) => DDSError::NotEnabled,
75 Some(-7) => DDSError::ImmutablePolicy,
76 Some(-8) => DDSError::InconsistentPolicy,
77 Some(-9) => DDSError::AlreadyDeleted,
78 Some(-10) => DDSError::Timeout,
79 Some(-11) => DDSError::NoData,
80 Some(-12) => DDSError::IllegalOperation,
81 Some(-13) => DDSError::NotAllowedBySecurity,
82 Some(x) if x > 0 => DDSError::DdsOk,
83 Some(x) if x < -13 => DDSError::DdsError,
84 None => DDSError::DdsError,
85 _ => DDSError::DdsError,
86 }
87 }
88}