Replace Vec with slice where possible
This commit is contained in:
parent
d4f4949cd8
commit
99701608a2
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ObjectStatus>) {
|
||||
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<ObjectStatus>) {
|
||||
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<ObjectStatus>,
|
||||
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<StatusList>,
|
||||
add_statuses: Option<StatusList<'a>>,
|
||||
#[serde(rename = "contact:rem")]
|
||||
remove_statuses: Option<StatusList>,
|
||||
remove_statuses: Option<StatusList<'a>>,
|
||||
#[serde(rename = "contact:chg")]
|
||||
change_info: Option<ContactChangeInfo<'a>>,
|
||||
}
|
||||
|
@ -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);
|
||||
|
|
|
@ -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<HostAttr<'a>>,
|
||||
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<StringValue<'a>>,
|
||||
pub hosts: &'a [StringValue<'a>],
|
||||
}
|
||||
|
||||
/// Enum that can accept one type which corresponds to either the <hostObj> or <hostAttr>
|
||||
|
|
|
@ -36,7 +36,7 @@ pub struct DomainCreateRequestData<'a> {
|
|||
pub registrant: Option<StringValue<'a>>,
|
||||
/// The list of contacts for the domain
|
||||
#[serde(rename = "domain:contact")]
|
||||
pub contacts: Option<Vec<DomainContact>>,
|
||||
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<HostList<'a>>,
|
||||
registrant_id: Option<&'a str>,
|
||||
auth_password: &'a str,
|
||||
contacts: Option<Vec<DomainContact>>,
|
||||
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,8 +199,7 @@ mod tests {
|
|||
},
|
||||
];
|
||||
|
||||
let host_attr = HostList::HostAttrList(HostAttrList {
|
||||
hosts: vec![
|
||||
let hosts = &[
|
||||
HostAttr {
|
||||
name: "ns1.eppdev-1.com".into(),
|
||||
addresses: None,
|
||||
|
@ -215,13 +211,12 @@ mod tests {
|
|||
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),
|
||||
|
|
|
@ -64,10 +64,10 @@ pub struct DomainAddRemove<'a> {
|
|||
pub ns: Option<HostList<'a>>,
|
||||
/// The list of contacts to add to or remove from the domain
|
||||
#[serde(rename = "domain:contact")]
|
||||
pub contacts: Option<Vec<DomainContact>>,
|
||||
pub contacts: Option<&'a [DomainContact]>,
|
||||
/// The list of statuses to add to or remove from the domain
|
||||
#[serde(rename = "domain:status")]
|
||||
pub statuses: Option<Vec<ObjectStatus>>,
|
||||
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,
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ impl<'a> Command for HostCreate<'a> {
|
|||
}
|
||||
|
||||
impl<'a> HostCreate<'a> {
|
||||
pub fn new(host: &'a str, addresses: Vec<HostAddr>) -> 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<Vec<HostAddr>>,
|
||||
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"),
|
||||
];
|
||||
|
|
|
@ -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<Vec<HostAddr>>,
|
||||
pub addresses: Option<&'a [HostAddr]>,
|
||||
/// The statuses to be added to or removed from the host
|
||||
#[serde(rename = "host:status")]
|
||||
pub statuses: Option<Vec<ObjectStatus>>,
|
||||
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<HostAddRemove>,
|
||||
add: Option<HostAddRemove<'a>>,
|
||||
/// The IP addresses and statuses to be removed from the host
|
||||
#[serde(rename = "host:rem")]
|
||||
remove: Option<HostAddRemove>,
|
||||
remove: Option<HostAddRemove<'a>>,
|
||||
/// The host details that need to be updated
|
||||
#[serde(rename = "host:chg")]
|
||||
change_info: Option<HostChangeInfo<'a>>,
|
||||
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue