ldap_client_proto/
result_code.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[non_exhaustive]
5pub enum ResultCode {
6 Success,
7 OperationsError,
8 ProtocolError,
9 TimeLimitExceeded,
10 SizeLimitExceeded,
11 CompareFalse,
12 CompareTrue,
13 AuthMethodNotSupported,
14 StrongerAuthRequired,
15 Referral,
16 AdminLimitExceeded,
17 SaslBindInProgress,
18 NoSuchAttribute,
19 UndefinedAttributeType,
20 InappropriateMatching,
21 ConstraintViolation,
22 AttributeOrValueExists,
23 InvalidAttributeSyntax,
24 NoSuchObject,
25 InvalidDnSyntax,
26 InvalidCredentials,
27 InsufficientAccessRights,
28 Busy,
29 Unavailable,
30 UnwillingToPerform,
31 NotAllowedOnNonLeaf,
32 EntryAlreadyExists,
33 Other,
34 Unknown(i32),
35}
36
37impl ResultCode {
38 pub fn from_i64(code: i64) -> Self {
39 let Ok(code) = i32::try_from(code) else {
40 return Self::Unknown(i32::MAX);
41 };
42 match code {
43 0 => Self::Success,
44 1 => Self::OperationsError,
45 2 => Self::ProtocolError,
46 3 => Self::TimeLimitExceeded,
47 4 => Self::SizeLimitExceeded,
48 5 => Self::CompareFalse,
49 6 => Self::CompareTrue,
50 7 => Self::AuthMethodNotSupported,
51 8 => Self::StrongerAuthRequired,
52 10 => Self::Referral,
53 11 => Self::AdminLimitExceeded,
54 14 => Self::SaslBindInProgress,
55 16 => Self::NoSuchAttribute,
56 17 => Self::UndefinedAttributeType,
57 18 => Self::InappropriateMatching,
58 19 => Self::ConstraintViolation,
59 20 => Self::AttributeOrValueExists,
60 21 => Self::InvalidAttributeSyntax,
61 32 => Self::NoSuchObject,
62 34 => Self::InvalidDnSyntax,
63 49 => Self::InvalidCredentials,
64 50 => Self::InsufficientAccessRights,
65 51 => Self::Busy,
66 52 => Self::Unavailable,
67 53 => Self::UnwillingToPerform,
68 66 => Self::NotAllowedOnNonLeaf,
69 68 => Self::EntryAlreadyExists,
70 80 => Self::Other,
71 n => Self::Unknown(n),
72 }
73 }
74
75 pub fn is_success(&self) -> bool {
76 matches!(self, Self::Success | Self::CompareFalse | Self::CompareTrue)
77 }
78
79 pub fn is_credential_error(&self) -> bool {
80 matches!(
81 self,
82 Self::InvalidCredentials
83 | Self::InsufficientAccessRights
84 | Self::AuthMethodNotSupported
85 | Self::StrongerAuthRequired
86 )
87 }
88
89 pub fn is_transient(&self) -> bool {
90 matches!(
91 self,
92 Self::Busy | Self::Unavailable | Self::AdminLimitExceeded | Self::Other
93 )
94 }
95
96 pub fn is_referral(&self) -> bool {
97 matches!(self, Self::Referral)
98 }
99
100 pub fn is_configuration_error(&self) -> bool {
101 matches!(
102 self,
103 Self::InvalidDnSyntax
104 | Self::NoSuchObject
105 | Self::UndefinedAttributeType
106 | Self::InappropriateMatching
107 )
108 }
109}
110
111impl std::fmt::Display for ResultCode {
112 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113 write!(f, "{self:?}")
114 }
115}