Warn when not using Self

This commit is contained in:
Dirkjan Ochtman 2023-04-14 10:14:57 +02:00
parent 5371ba573a
commit c0e58dec04
9 changed files with 87 additions and 86 deletions

View File

@ -29,7 +29,7 @@ impl<'xml> FromXml<'xml> for NoExtension {
} }
impl Extension for NoExtension { impl Extension for NoExtension {
type Response = NoExtension; type Response = Self;
} }
/// The `<option>` type in EPP XML login requests /// The `<option>` type in EPP XML login requests

View File

@ -302,18 +302,18 @@ impl<'xml> FromXml<'xml> for Status {
} }
*into = Some(match attr.value { *into = Some(match attr.value {
"clientDeleteProhibited" => Status::ClientDeleteProhibited, "clientDeleteProhibited" => Self::ClientDeleteProhibited,
"serverDeleteProhibited" => Status::ServerDeleteProhibited, "serverDeleteProhibited" => Self::ServerDeleteProhibited,
"clientTransferProhibited" => Status::ClientTransferProhibited, "clientTransferProhibited" => Self::ClientTransferProhibited,
"serverTransferProhibited" => Status::ServerTransferProhibited, "serverTransferProhibited" => Self::ServerTransferProhibited,
"clientUpdateProhibited" => Status::ClientUpdateProhibited, "clientUpdateProhibited" => Self::ClientUpdateProhibited,
"serverUpdateProhibited" => Status::ServerUpdateProhibited, "serverUpdateProhibited" => Self::ServerUpdateProhibited,
"linked" => Status::Linked, "linked" => Self::Linked,
"ok" => Status::Ok, "ok" => Self::Ok,
"pendingCreate" => Status::PendingCreate, "pendingCreate" => Self::PendingCreate,
"pendingDelete" => Status::PendingDelete, "pendingDelete" => Self::PendingDelete,
"pendingTransfer" => Status::PendingTransfer, "pendingTransfer" => Self::PendingTransfer,
"pendingUpdate" => Status::PendingUpdate, "pendingUpdate" => Self::PendingUpdate,
val => return Err(Error::UnexpectedValue(format!("invalid status {val:?}"))), val => return Err(Error::UnexpectedValue(format!("invalid status {val:?}"))),
}); });
@ -321,6 +321,6 @@ impl<'xml> FromXml<'xml> for Status {
Ok(()) Ok(())
} }
type Accumulator = Option<Status>; type Accumulator = Option<Self>;
const KIND: instant_xml::Kind = instant_xml::Kind::Element; const KIND: instant_xml::Kind = instant_xml::Kind::Element;
} }

View File

@ -172,7 +172,7 @@ impl Period {
fn new(length: u8, unit: char) -> Result<Self, Error> { fn new(length: u8, unit: char) -> Result<Self, Error> {
match length { match length {
1..=99 => Ok(Period { length, unit }), 1..=99 => Ok(Self { length, unit }),
0 | 100.. => Err(Error::Other( 0 | 100.. => Err(Error::Other(
"Period length must be greater than 0 and less than 100".into(), "Period length must be greater than 0 and less than 100".into(),
)), )),
@ -316,23 +316,23 @@ impl<'xml> FromXml<'xml> for Status {
} }
*into = Some(match attr.value { *into = Some(match attr.value {
"clientDeleteProhibited" => Status::ClientDeleteProhibited, "clientDeleteProhibited" => Self::ClientDeleteProhibited,
"serverDeleteProhibited" => Status::ServerDeleteProhibited, "serverDeleteProhibited" => Self::ServerDeleteProhibited,
"clientHold" => Status::ClientHold, "clientHold" => Self::ClientHold,
"serverHold" => Status::ServerHold, "serverHold" => Self::ServerHold,
"clientRenewProhibited" => Status::ClientRenewProhibited, "clientRenewProhibited" => Self::ClientRenewProhibited,
"serverRenewProhibited" => Status::ServerRenewProhibited, "serverRenewProhibited" => Self::ServerRenewProhibited,
"clientTransferProhibited" => Status::ClientTransferProhibited, "clientTransferProhibited" => Self::ClientTransferProhibited,
"serverTransferProhibited" => Status::ServerTransferProhibited, "serverTransferProhibited" => Self::ServerTransferProhibited,
"clientUpdateProhibited" => Status::ClientUpdateProhibited, "clientUpdateProhibited" => Self::ClientUpdateProhibited,
"serverUpdateProhibited" => Status::ServerUpdateProhibited, "serverUpdateProhibited" => Self::ServerUpdateProhibited,
"inactive" => Status::Inactive, "inactive" => Self::Inactive,
"ok" => Status::Ok, "ok" => Self::Ok,
"pendingCreate" => Status::PendingCreate, "pendingCreate" => Self::PendingCreate,
"pendingDelete" => Status::PendingDelete, "pendingDelete" => Self::PendingDelete,
"pendingRenew" => Status::PendingRenew, "pendingRenew" => Self::PendingRenew,
"pendingTransfer" => Status::PendingTransfer, "pendingTransfer" => Self::PendingTransfer,
"pendingUpdate" => Status::PendingUpdate, "pendingUpdate" => Self::PendingUpdate,
val => return Err(Error::UnexpectedValue(format!("invalid status {val:?}"))), val => return Err(Error::UnexpectedValue(format!("invalid status {val:?}"))),
}); });
@ -340,6 +340,6 @@ impl<'xml> FromXml<'xml> for Status {
Ok(()) Ok(())
} }
type Accumulator = Option<Status>; type Accumulator = Option<Self>;
const KIND: instant_xml::Kind = instant_xml::Kind::Element; const KIND: instant_xml::Kind = instant_xml::Kind::Element;
} }

View File

@ -25,13 +25,13 @@ impl StdError for Error {}
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Error::Command(e) => { Self::Command(e) => {
write!(f, "command error: {}", e.result.message) write!(f, "command error: {}", e.result.message)
} }
Error::Io(e) => write!(f, "I/O error: {e}"), Self::Io(e) => write!(f, "I/O error: {e}"),
Error::Timeout => write!(f, "timeout"), Self::Timeout => write!(f, "timeout"),
Error::Xml(e) => write!(f, "(de)serialization error: {e}"), Self::Xml(e) => write!(f, "(de)serialization error: {e}"),
Error::Other(e) => write!(f, "error: {e}"), Self::Other(e) => write!(f, "error: {e}"),
} }
} }
} }

View File

@ -51,7 +51,7 @@ impl GMonthDay {
return Err("Day value within GMonthDay is to big for specified month".to_string()); return Err("Day value within GMonthDay is to big for specified month".to_string());
} }
Ok(GMonthDay { Ok(Self {
month, month,
day, day,
timezone, timezone,

View File

@ -50,7 +50,7 @@ impl<'xml> FromXml<'xml> for ServiceMenu {
None => return Ok(()), None => return Ok(()),
}; };
*into = Some(ServiceMenu { *into = Some(Self {
options: Options { options: Options {
version: flattened.version.into(), version: flattened.version.into(),
lang: flattened.lang.into(), lang: flattened.lang.into(),

View File

@ -104,16 +104,16 @@ impl<'xml> FromXml<'xml> for Status {
} }
*into = Some(match attr.value { *into = Some(match attr.value {
"clientDeleteProhibited" => Status::ClientDeleteProhibited, "clientDeleteProhibited" => Self::ClientDeleteProhibited,
"serverDeleteProhibited" => Status::ServerDeleteProhibited, "serverDeleteProhibited" => Self::ServerDeleteProhibited,
"clientUpdateProhibited" => Status::ClientUpdateProhibited, "clientUpdateProhibited" => Self::ClientUpdateProhibited,
"serverUpdateProhibited" => Status::ServerUpdateProhibited, "serverUpdateProhibited" => Self::ServerUpdateProhibited,
"linked" => Status::Linked, "linked" => Self::Linked,
"ok" => Status::Ok, "ok" => Self::Ok,
"pendingCreate" => Status::PendingCreate, "pendingCreate" => Self::PendingCreate,
"pendingDelete" => Status::PendingDelete, "pendingDelete" => Self::PendingDelete,
"pendingTransfer" => Status::PendingTransfer, "pendingTransfer" => Self::PendingTransfer,
"pendingUpdate" => Status::PendingUpdate, "pendingUpdate" => Self::PendingUpdate,
val => return Err(Error::UnexpectedValue(format!("invalid status {val:?}"))), val => return Err(Error::UnexpectedValue(format!("invalid status {val:?}"))),
}); });
@ -121,7 +121,7 @@ impl<'xml> FromXml<'xml> for Status {
Ok(()) Ok(())
} }
type Accumulator = Option<Status>; type Accumulator = Option<Self>;
const KIND: instant_xml::Kind = instant_xml::Kind::Element; const KIND: instant_xml::Kind = instant_xml::Kind::Element;
} }

View File

@ -33,6 +33,7 @@
//! on that type for more information. //! on that type for more information.
#![warn(unreachable_pub)] #![warn(unreachable_pub)]
#![warn(clippy::use_self)]
pub mod client; pub mod client;
pub mod common; pub mod common;

View File

@ -86,40 +86,40 @@ pub enum ResultCode {
impl ResultCode { impl ResultCode {
pub fn from_u16(code: u16) -> Option<Self> { pub fn from_u16(code: u16) -> Option<Self> {
match code { match code {
1000 => Some(ResultCode::CommandCompletedSuccessfully), 1000 => Some(Self::CommandCompletedSuccessfully),
1001 => Some(ResultCode::CommandCompletedSuccessfullyActionPending), 1001 => Some(Self::CommandCompletedSuccessfullyActionPending),
1300 => Some(ResultCode::CommandCompletedSuccessfullyNoMessages), 1300 => Some(Self::CommandCompletedSuccessfullyNoMessages),
1301 => Some(ResultCode::CommandCompletedSuccessfullyAckToDequeue), 1301 => Some(Self::CommandCompletedSuccessfullyAckToDequeue),
1500 => Some(ResultCode::CommandCompletedSuccessfullyEndingSession), 1500 => Some(Self::CommandCompletedSuccessfullyEndingSession),
2000 => Some(ResultCode::UnknownCommand), 2000 => Some(Self::UnknownCommand),
2001 => Some(ResultCode::CommandSyntaxError), 2001 => Some(Self::CommandSyntaxError),
2002 => Some(ResultCode::CommandUseError), 2002 => Some(Self::CommandUseError),
2003 => Some(ResultCode::RequiredParameterMissing), 2003 => Some(Self::RequiredParameterMissing),
2004 => Some(ResultCode::ParameterValueRangeError), 2004 => Some(Self::ParameterValueRangeError),
2005 => Some(ResultCode::ParameterValueSyntaxError), 2005 => Some(Self::ParameterValueSyntaxError),
2100 => Some(ResultCode::UnimplementedProtocolVersion), 2100 => Some(Self::UnimplementedProtocolVersion),
2101 => Some(ResultCode::UnimplementedCommand), 2101 => Some(Self::UnimplementedCommand),
2102 => Some(ResultCode::UnimplementedOption), 2102 => Some(Self::UnimplementedOption),
2103 => Some(ResultCode::UnimplementedExtension), 2103 => Some(Self::UnimplementedExtension),
2104 => Some(ResultCode::BillingFailure), 2104 => Some(Self::BillingFailure),
2105 => Some(ResultCode::ObjectIsNotEligibleForRenewal), 2105 => Some(Self::ObjectIsNotEligibleForRenewal),
2106 => Some(ResultCode::ObjectIsNotEligibleForTransfer), 2106 => Some(Self::ObjectIsNotEligibleForTransfer),
2200 => Some(ResultCode::AuthenticationError), 2200 => Some(Self::AuthenticationError),
2201 => Some(ResultCode::AuthorizationError), 2201 => Some(Self::AuthorizationError),
2202 => Some(ResultCode::InvalidAuthorizationInformation), 2202 => Some(Self::InvalidAuthorizationInformation),
2300 => Some(ResultCode::ObjectPendingTransfer), 2300 => Some(Self::ObjectPendingTransfer),
2301 => Some(ResultCode::ObjectNotPendingTransfer), 2301 => Some(Self::ObjectNotPendingTransfer),
2302 => Some(ResultCode::ObjectExists), 2302 => Some(Self::ObjectExists),
2303 => Some(ResultCode::ObjectDoesNotExist), 2303 => Some(Self::ObjectDoesNotExist),
2304 => Some(ResultCode::ObjectStatusProhibitsOperation), 2304 => Some(Self::ObjectStatusProhibitsOperation),
2305 => Some(ResultCode::ObjectAssociationProhibitsOperation), 2305 => Some(Self::ObjectAssociationProhibitsOperation),
2306 => Some(ResultCode::ParameterValuePolicyError), 2306 => Some(Self::ParameterValuePolicyError),
2307 => Some(ResultCode::UnimplementedObjectService), 2307 => Some(Self::UnimplementedObjectService),
2308 => Some(ResultCode::DataManagementPolicyViolation), 2308 => Some(Self::DataManagementPolicyViolation),
2400 => Some(ResultCode::CommandFailed), 2400 => Some(Self::CommandFailed),
2500 => Some(ResultCode::CommandFailedServerClosingConnection), 2500 => Some(Self::CommandFailedServerClosingConnection),
2501 => Some(ResultCode::AuthenticationErrorServerClosingConnection), 2501 => Some(Self::AuthenticationErrorServerClosingConnection),
2502 => Some(ResultCode::SessionLimitExceededServerClosingConnection), 2502 => Some(Self::SessionLimitExceededServerClosingConnection),
_ => None, _ => None,
} }
} }
@ -153,7 +153,7 @@ impl<'xml> FromXml<'xml> for ResultCode {
let mut value = None; let mut value = None;
u16::deserialize(&mut value, field, deserializer)?; u16::deserialize(&mut value, field, deserializer)?;
if let Some(value) = value { if let Some(value) = value {
*into = match ResultCode::from_u16(value) { *into = match Self::from_u16(value) {
Some(value) => Some(value), Some(value) => Some(value),
None => { None => {
return Err(instant_xml::Error::UnexpectedValue(format!( return Err(instant_xml::Error::UnexpectedValue(format!(