diff --git a/src/contact.rs b/src/contact.rs index 33d7273..9473725 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -134,7 +134,12 @@ pub struct PostalInfo<'a> { impl<'a> PostalInfo<'a> { /// Creates a new PostalInfo instance - pub fn new(info_type: &str, name: &'a str, organization: &'a str, address: Address<'a>) -> Self { + pub fn new( + info_type: &str, + name: &'a str, + organization: &'a str, + address: Address<'a>, + ) -> Self { Self { info_type: info_type.to_string(), name: name.into(), diff --git a/src/contact/check.rs b/src/contact/check.rs index d48544b..b66b809 100644 --- a/src/contact/check.rs +++ b/src/contact/check.rs @@ -30,13 +30,11 @@ pub struct ContactCheck<'a> { } impl<'a> ContactCheck<'a> { - pub fn new(contact_ids: &[&'a str]) -> Self { - let contact_ids = contact_ids.iter().map(|&d| d.into()).collect(); - + pub fn new(contact_ids: &'a [&'a str]) -> Self { Self { list: ContactList { xmlns: XMLNS, - contact_ids, + contact_ids: contact_ids.iter().map(|&id| id.into()).collect(), }, } } diff --git a/src/contact/update.rs b/src/contact/update.rs index aa93fda..b80be59 100644 --- a/src/contact/update.rs +++ b/src/contact/update.rs @@ -50,13 +50,13 @@ impl<'a> ContactUpdate<'a> { } /// Sets the data for the <add> tag for the contact update request - pub fn add(&mut self, statuses: Vec) { - self.contact.add_statuses = Some(StatusList { status: statuses }); + pub fn add(&mut self, status: &'a [ObjectStatus]) { + self.contact.add_statuses = Some(StatusList { status }); } /// Sets the data for the <rem> tag for the contact update request - pub fn remove(&mut self, statuses: Vec) { - self.contact.remove_statuses = Some(StatusList { status: statuses }); + pub fn remove(&mut self, status: &'a [ObjectStatus]) { + self.contact.remove_statuses = Some(StatusList { status }); } } @@ -77,9 +77,9 @@ pub struct ContactChangeInfo<'a> { /// Type for list of elements of the <status> tag for contact update request #[derive(Serialize, Debug)] -pub struct StatusList { +pub struct StatusList<'a> { #[serde(rename = "contact:status")] - status: Vec, + status: &'a [ObjectStatus], } /// Type for elements under the contact <update> tag @@ -90,9 +90,9 @@ pub struct ContactUpdateRequestData<'a> { #[serde(rename = "contact:id")] id: StringValue<'a>, #[serde(rename = "contact:add")] - add_statuses: Option, + add_statuses: Option>, #[serde(rename = "contact:rem")] - remove_statuses: Option, + remove_statuses: Option>, #[serde(rename = "contact:chg")] change_info: Option>, } @@ -125,11 +125,11 @@ mod tests { let voice = Phone::new("+33.47237942"); object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323"); - let add_statuses = vec![ObjectStatus { + let add_statuses = &[ObjectStatus { status: "clientTransferProhibited".to_string(), }]; object.add(add_statuses); - let remove_statuses = vec![ObjectStatus { + let remove_statuses = &[ObjectStatus { status: "clientDeleteProhibited".to_string(), }]; object.remove(remove_statuses); diff --git a/src/domain.rs b/src/domain.rs index 32a02fa..6408712 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -28,7 +28,7 @@ pub struct HostAttr<'a> { pub struct HostAttrList<'a> { /// The list of <hostAttr> tags #[serde(rename = "domain:hostAttr", alias = "hostAttr")] - pub hosts: Vec>, + pub hosts: &'a [HostAttr<'a>], } /// The list of <hostObj> types for domain transactions. Typically under an <ns> tag @@ -36,7 +36,7 @@ pub struct HostAttrList<'a> { pub struct HostObjList<'a> { /// The list of <hostObj> tags #[serde(rename = "domain:hostObj", alias = "hostObj")] - pub hosts: Vec>, + pub hosts: &'a [StringValue<'a>], } /// Enum that can accept one type which corresponds to either the <hostObj> or <hostAttr> diff --git a/src/domain/create.rs b/src/domain/create.rs index af085e1..bc66b24 100644 --- a/src/domain/create.rs +++ b/src/domain/create.rs @@ -36,7 +36,7 @@ pub struct DomainCreateRequestData<'a> { pub registrant: Option>, /// The list of contacts for the domain #[serde(rename = "domain:contact")] - pub contacts: Option>, + pub contacts: Option<&'a [DomainContact]>, /// The auth info for the domain #[serde(rename = "domain:authInfo")] pub auth_info: DomainAuthInfo<'a>, @@ -59,7 +59,7 @@ impl<'a> DomainCreate<'a> { ns: Option>, registrant_id: Option<&'a str>, auth_password: &'a str, - contacts: Option>, + contacts: Option<&'a [DomainContact]>, ) -> Self { Self { domain: DomainCreateRequestData { @@ -113,7 +113,7 @@ mod tests { fn command() { let xml = get_xml("request/domain/create.xml").unwrap(); - let contacts = vec![ + let contacts = &[ DomainContact { contact_type: "admin".to_string(), id: "eppdev-contact-3".to_string(), @@ -148,7 +148,7 @@ mod tests { fn command_with_host_obj() { let xml = get_xml("request/domain/create_with_host_obj.xml").unwrap(); - let contacts = vec![ + let contacts = &[ DomainContact { contact_type: "admin".to_string(), id: "eppdev-contact-3".to_string(), @@ -163,14 +163,11 @@ mod tests { }, ]; - let ns = Some(HostList::HostObjList(HostObjList { - hosts: vec!["ns1.test.com".into(), "ns2.test.com".into()], - })); - + let hosts = &["ns1.test.com".into(), "ns2.test.com".into()]; let object = DomainCreate::new( "eppdev-1.com", 1, - ns, + Some(HostList::HostObjList(HostObjList { hosts })), Some("eppdev-contact-3"), "epP4uthd#v", Some(contacts), @@ -187,7 +184,7 @@ mod tests { fn command_with_host_attr() { let xml = get_xml("request/domain/create_with_host_attr.xml").unwrap(); - let contacts = vec![ + let contacts = &[ DomainContact { contact_type: "admin".to_string(), id: "eppdev-contact-3".to_string(), @@ -202,26 +199,24 @@ mod tests { }, ]; - let host_attr = HostList::HostAttrList(HostAttrList { - hosts: vec![ - HostAttr { - name: "ns1.eppdev-1.com".into(), - addresses: None, - }, - HostAttr { - name: "ns2.eppdev-1.com".into(), - addresses: Some(vec![ - HostAddr::new_v4("177.232.12.58"), - HostAddr::new_v6("2404:6800:4001:801::200e"), - ]), - }, - ], - }); + let hosts = &[ + HostAttr { + name: "ns1.eppdev-1.com".into(), + addresses: None, + }, + HostAttr { + name: "ns2.eppdev-1.com".into(), + addresses: Some(vec![ + HostAddr::new_v4("177.232.12.58"), + HostAddr::new_v6("2404:6800:4001:801::200e"), + ]), + }, + ]; let object = DomainCreate::new( "eppdev-2.com", 1, - Some(host_attr), + Some(HostList::HostAttrList(HostAttrList { hosts })), Some("eppdev-contact-3"), "epP4uthd#v", Some(contacts), diff --git a/src/domain/update.rs b/src/domain/update.rs index bae9922..1d57ffa 100644 --- a/src/domain/update.rs +++ b/src/domain/update.rs @@ -64,10 +64,10 @@ pub struct DomainAddRemove<'a> { pub ns: Option>, /// The list of contacts to add to or remove from the domain #[serde(rename = "domain:contact")] - pub contacts: Option>, + pub contacts: Option<&'a [DomainContact]>, /// The list of statuses to add to or remove from the domain #[serde(rename = "domain:status")] - pub statuses: Option>, + pub statuses: Option<&'a [ObjectStatus]>, } /// Type for elements under the <update> tag for domain update @@ -112,20 +112,24 @@ mod tests { let mut object = DomainUpdate::new("eppdev.com"); + let statuses = &[ObjectStatus { + status: "clientDeleteProhibited".to_string(), + }]; + let add = DomainAddRemove { ns: None, contacts: None, - statuses: Some(vec![ObjectStatus { - status: "clientDeleteProhibited".to_string(), - }]), + statuses: Some(statuses), }; + let contacts = &[DomainContact { + contact_type: "billing".to_string(), + id: "eppdev-contact-2".to_string(), + }]; + let remove = DomainAddRemove { ns: None, - contacts: Some(vec![DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-2".to_string(), - }]), + contacts: Some(contacts), statuses: None, }; diff --git a/src/host/create.rs b/src/host/create.rs index 048d557..ba522a9 100644 --- a/src/host/create.rs +++ b/src/host/create.rs @@ -13,7 +13,7 @@ impl<'a> Command for HostCreate<'a> { } impl<'a> HostCreate<'a> { - pub fn new(host: &'a str, addresses: Vec) -> Self { + pub fn new(host: &'a str, addresses: &'a [HostAddr]) -> Self { Self { host: HostCreateRequestData { xmlns: XMLNS, @@ -37,7 +37,7 @@ pub struct HostCreateRequestData<'a> { pub name: StringValue<'a>, /// The list of IP addresses for the host #[serde(rename = "host:addr")] - pub addresses: Option>, + pub addresses: Option<&'a [HostAddr]>, } #[derive(Serialize, Debug)] @@ -79,7 +79,7 @@ mod tests { fn command() { let xml = get_xml("request/host/create.xml").unwrap(); - let addresses = vec![ + let addresses = &[ HostAddr::new("v4", "29.245.122.14"), HostAddr::new("v6", "2404:6800:4001:801::200e"), ]; diff --git a/src/host/update.rs b/src/host/update.rs index f0bd4ae..807725f 100644 --- a/src/host/update.rs +++ b/src/host/update.rs @@ -31,12 +31,12 @@ impl<'a> HostUpdate<'a> { } /// Sets the data for the <add> element of the host update - pub fn add(&mut self, add: HostAddRemove) { + pub fn add(&mut self, add: HostAddRemove<'a>) { self.host.add = Some(add); } /// Sets the data for the <rem> element of the host update - pub fn remove(&mut self, remove: HostAddRemove) { + pub fn remove(&mut self, remove: HostAddRemove<'a>) { self.host.remove = Some(remove); } } @@ -51,13 +51,13 @@ pub struct HostChangeInfo<'a> { /// Type for data under the <add> and <rem> tags #[derive(Serialize, Debug)] -pub struct HostAddRemove { +pub struct HostAddRemove<'a> { /// The IP addresses to be added to or removed from the host #[serde(rename = "host:addr")] - pub addresses: Option>, + pub addresses: Option<&'a [HostAddr]>, /// The statuses to be added to or removed from the host #[serde(rename = "host:status")] - pub statuses: Option>, + pub statuses: Option<&'a [ObjectStatus]>, } /// Type for data under the host <update> tag @@ -71,10 +71,10 @@ pub struct HostUpdateRequestData<'a> { name: StringValue<'a>, /// The IP addresses and statuses to be added to the host #[serde(rename = "host:add")] - add: Option, + add: Option>, /// The IP addresses and statuses to be removed from the host #[serde(rename = "host:rem")] - remove: Option, + remove: Option>, /// The host details that need to be updated #[serde(rename = "host:chg")] change_info: Option>, @@ -99,18 +99,20 @@ mod tests { fn command() { let xml = get_xml("request/host/update.xml").unwrap(); - let addr = vec![HostAddr::new("v6", "2404:6800:4001:801::200e")]; + let addr = &[HostAddr::new("v6", "2404:6800:4001:801::200e")]; let add = HostAddRemove { addresses: Some(addr), statuses: None, }; + let statuses = &[ObjectStatus { + status: "clientDeleteProhibited".to_string(), + }]; + let remove = HostAddRemove { addresses: None, - statuses: Some(vec![ObjectStatus { - status: "clientDeleteProhibited".to_string(), - }]), + statuses: Some(statuses), }; let mut object = HostUpdate::new("host1.eppdev-1.com");