From 9aae46dd5d026af2974e2462417540d069dca6b4 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 27 Feb 2023 17:21:23 +0100 Subject: [PATCH] Move module.rs files into module/mod.rs This style puts the root modules closer to the contained modules, which better aligns the on-disk structure with the module hierarchy. --- src/{contact.rs => contact/mod.rs} | 0 src/{domain.rs => domain/mod.rs} | 0 src/extensions/rgp.rs | 4 -- src/host/mod.rs | 69 +++++++++++++++++++++++++++ src/lib.rs | 76 ++---------------------------- 5 files changed, 74 insertions(+), 75 deletions(-) rename src/{contact.rs => contact/mod.rs} (100%) rename src/{domain.rs => domain/mod.rs} (100%) delete mode 100644 src/extensions/rgp.rs create mode 100644 src/host/mod.rs diff --git a/src/contact.rs b/src/contact/mod.rs similarity index 100% rename from src/contact.rs rename to src/contact/mod.rs diff --git a/src/domain.rs b/src/domain/mod.rs similarity index 100% rename from src/domain.rs rename to src/domain/mod.rs diff --git a/src/extensions/rgp.rs b/src/extensions/rgp.rs deleted file mode 100644 index 43a9349..0000000 --- a/src/extensions/rgp.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod report; -pub mod request; - -pub const XMLNS: &str = "urn:ietf:params:xml:ns:rgp-1.0"; diff --git a/src/host/mod.rs b/src/host/mod.rs new file mode 100644 index 0000000..8f22761 --- /dev/null +++ b/src/host/mod.rs @@ -0,0 +1,69 @@ +use std::borrow::Cow; +use std::fmt; +use std::net::IpAddr; + +use instant_xml::{FromXml, Serializer, ToXml}; + +pub mod check; +pub use check::HostCheck; + +pub mod create; +pub use create::HostCreate; + +pub mod delete; +pub use delete::HostDelete; + +pub mod info; +pub use info::HostInfo; + +pub mod update; +pub use update::HostUpdate; + +pub const XMLNS: &str = "urn:ietf:params:xml:ns:host-1.0"; + +/// The <status> type on contact transactions +#[derive(Debug, FromXml, ToXml)] +#[xml(rename = "status", ns(XMLNS))] +pub struct Status<'a> { + /// The status name, represented by the 's' attr on <status> tags + #[xml(attribute, rename = "s")] + pub status: Cow<'a, str>, +} + +/// The <hostAddr> types domain or host transactions +#[derive(Debug, FromXml, ToXml)] +#[xml(rename = "addr", ns(XMLNS))] +pub(crate) struct HostAddr<'a> { + #[xml(attribute, rename = "ip")] + pub ip_version: Option>, + #[xml(direct)] + pub address: Cow<'a, str>, +} + +impl From<&IpAddr> for HostAddr<'static> { + fn from(addr: &IpAddr) -> Self { + Self { + ip_version: Some(match addr { + IpAddr::V4(_) => "v4".into(), + IpAddr::V6(_) => "v6".into(), + }), + address: addr.to_string().into(), + } + } +} + +pub(crate) fn serialize_host_addrs_option, W: fmt::Write + ?Sized>( + addrs: &Option, + serializer: &mut Serializer<'_, W>, +) -> Result<(), instant_xml::Error> { + let addrs = match addrs { + Some(addrs) => addrs.as_ref(), + None => return Ok(()), + }; + + for addr in addrs { + HostAddr::from(addr).serialize(None, serializer)?; + } + + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index 7dcc511..7f5e986 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,6 +101,7 @@ pub mod contact; pub mod domain; mod error; pub mod hello; +pub mod host; pub mod login; pub mod logout; pub mod request; @@ -111,78 +112,11 @@ pub mod extensions { pub mod consolidate; pub mod low_balance; pub mod namestore; - pub mod rgp; -} + pub mod rgp { + pub mod report; + pub mod request; -pub mod host { - use std::borrow::Cow; - use std::fmt; - use std::net::IpAddr; - - use instant_xml::{FromXml, Serializer, ToXml}; - - pub mod check; - pub use check::HostCheck; - - pub mod create; - pub use create::HostCreate; - - pub mod delete; - pub use delete::HostDelete; - - pub mod info; - pub use info::HostInfo; - - pub mod update; - pub use update::HostUpdate; - - pub const XMLNS: &str = "urn:ietf:params:xml:ns:host-1.0"; - - /// The <status> type on contact transactions - #[derive(Debug, FromXml, ToXml)] - #[xml(rename = "status", ns(XMLNS))] - pub struct Status<'a> { - /// The status name, represented by the 's' attr on <status> tags - #[xml(attribute, rename = "s")] - pub status: Cow<'a, str>, - } - - /// The <hostAddr> types domain or host transactions - #[derive(Debug, FromXml, ToXml)] - #[xml(rename = "addr", ns(XMLNS))] - pub(crate) struct HostAddr<'a> { - #[xml(attribute, rename = "ip")] - pub ip_version: Option>, - #[xml(direct)] - pub address: Cow<'a, str>, - } - - impl From<&IpAddr> for HostAddr<'static> { - fn from(addr: &IpAddr) -> Self { - Self { - ip_version: Some(match addr { - IpAddr::V4(_) => "v4".into(), - IpAddr::V6(_) => "v6".into(), - }), - address: addr.to_string().into(), - } - } - } - - pub(crate) fn serialize_host_addrs_option, W: fmt::Write + ?Sized>( - addrs: &Option, - serializer: &mut Serializer<'_, W>, - ) -> Result<(), instant_xml::Error> { - let addrs = match addrs { - Some(addrs) => addrs.as_ref(), - None => return Ok(()), - }; - - for addr in addrs { - HostAddr::from(addr).serialize(None, serializer)?; - } - - Ok(()) + pub const XMLNS: &str = "urn:ietf:params:xml:ns:rgp-1.0"; } }