From 17d5bd90e922a16cefbc526f54ee9450aaab2062 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 14 Dec 2021 11:56:05 +0100 Subject: [PATCH] Use &str or Cow<'a, str> in place of String --- src/common.rs | 32 ++++++++++----------- src/contact.rs | 19 ++++++------ src/contact/create.rs | 8 +++--- src/contact/info.rs | 6 ++-- src/contact/update.rs | 14 ++++----- src/domain.rs | 10 ++++--- src/domain/create.rs | 40 +++++++++++++------------- src/domain/info.rs | 17 +++++------ src/domain/transfer.rs | 4 +-- src/domain/update.rs | 10 +++---- src/extensions/namestore.rs | 54 ++++++++++++++++++----------------- src/extensions/rgp/report.rs | 4 +-- src/extensions/rgp/request.rs | 22 +++++++------- src/host/create.rs | 2 +- src/host/info.rs | 4 +-- src/host/update.rs | 6 ++-- src/message/ack.rs | 12 ++++---- src/message/poll.rs | 14 ++++----- 18 files changed, 138 insertions(+), 140 deletions(-) diff --git a/src/common.rs b/src/common.rs index bd43687..4e97627 100644 --- a/src/common.rs +++ b/src/common.rs @@ -81,45 +81,45 @@ pub struct Services<'a> { /// The <hostAddr> types domain or host transactions #[derive(Serialize, Deserialize, Debug)] -pub struct HostAddr { +pub struct HostAddr<'a> { #[serde(rename = "ip")] - pub ip_version: Option, + pub ip_version: Option>, #[serde(rename = "$value")] - pub address: String, + pub address: Cow<'a, str>, } -impl HostAddr { +impl<'a> HostAddr<'a> { /// Creates a 'v4' type HostAddr (mostly useful when you don't want to include an 'ip' attr in the XML) - pub fn new(ip_version: &str, address: &str) -> HostAddr { - HostAddr { - ip_version: Some(ip_version.to_string()), - address: address.to_string(), + pub fn new(ip_version: &'a str, address: &'a str) -> Self { + Self { + ip_version: Some(ip_version.into()), + address: address.into(), } } /// Creates a 'v4' type HostAddr - pub fn new_v4(address: &str) -> HostAddr { + pub fn new_v4(address: &'a str) -> HostAddr { HostAddr { - ip_version: Some("v4".to_string()), - address: address.to_string(), + ip_version: Some("v4".into()), + address: address.into(), } } /// Creates a 'v6' type HostAddr - pub fn new_v6(address: &str) -> HostAddr { + pub fn new_v6(address: &'a str) -> HostAddr { HostAddr { - ip_version: Some("v6".to_string()), - address: address.to_string(), + ip_version: Some("v6".into()), + address: address.into(), } } } /// The <status> type on contact transactions #[derive(Serialize, Deserialize, Debug)] -pub struct ObjectStatus { +pub struct ObjectStatus<'a> { /// The status name, represented by the 's' attr on <status> tags #[serde(rename = "s")] - pub status: String, + pub status: Cow<'a, str>, } /// This type contains a single DER-encoded X.509 certificate. diff --git a/src/contact.rs b/src/contact.rs index 9473725..5f79e4b 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::str::FromStr; use serde::{Deserialize, Serialize}; @@ -50,27 +51,27 @@ impl<'a> ContactAuthInfo<'a> { /// The data for <voice> and <fax> types on domain transactions #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct Phone { +pub struct Phone<'a> { /// The inner text on the <voice> and <fax> tags #[serde(rename = "$value")] - pub number: String, + pub number: Cow<'a, str>, /// The value of the 'x' attr on <voice> and <fax> tags #[serde(rename = "x")] - pub extension: Option, + pub extension: Option>, } -impl Phone { +impl<'a> Phone<'a> { /// Creates a new Phone instance with a given phone number - pub fn new(number: &str) -> Phone { - Phone { + pub fn new(number: &'a str) -> Self { + Self { extension: None, - number: number.to_string(), + number: number.into(), } } /// Sets the extension value of the Phone type - pub fn set_extension(&mut self, ext: &str) { - self.extension = Some(ext.to_string()); + pub fn set_extension(&mut self, ext: &'a str) { + self.extension = Some(ext.into()); } } diff --git a/src/contact/create.rs b/src/contact/create.rs index 540e7ab..7057b5e 100644 --- a/src/contact/create.rs +++ b/src/contact/create.rs @@ -28,10 +28,10 @@ pub struct Contact<'a> { postal_info: PostalInfo<'a>, /// Contact <voice> tag #[serde(rename = "contact:voice")] - voice: Phone, + voice: Phone<'a>, /// Contact <fax> tag, #[serde(rename = "contact:fax")] - fax: Option, + fax: Option>, /// Contact <email> tag #[serde(rename = "contact:email")] email: StringValue<'a>, @@ -53,7 +53,7 @@ impl<'a> ContactCreate<'a> { id: &'a str, email: &'a str, postal_info: PostalInfo<'a>, - voice: Phone, + voice: Phone<'a>, auth_password: &'a str, ) -> Self { Self { @@ -70,7 +70,7 @@ impl<'a> ContactCreate<'a> { } /// Sets the <fax> data for the request - pub fn set_fax(&mut self, fax: Phone) { + pub fn set_fax(&mut self, fax: Phone<'a>) { self.contact.fax = Some(fax); } } diff --git a/src/contact/info.rs b/src/contact/info.rs index 84d5e16..1b7fd3b 100644 --- a/src/contact/info.rs +++ b/src/contact/info.rs @@ -59,14 +59,14 @@ pub struct ContactInfoData<'a> { pub roid: StringValue<'a>, /// The list of contact statuses #[serde(rename = "status")] - pub statuses: Vec, + pub statuses: Vec>, /// The postal info for the contact #[serde(rename = "postalInfo")] pub postal_info: PostalInfo<'a>, /// The voice data for the contact - pub voice: Phone, + pub voice: Phone<'a>, /// The fax data for the contact - pub fax: Option, + pub fax: Option>, /// The email for the contact pub email: StringValue<'a>, /// The epp user to whom the contact belongs diff --git a/src/contact/update.rs b/src/contact/update.rs index b80be59..dd95d91 100644 --- a/src/contact/update.rs +++ b/src/contact/update.rs @@ -30,7 +30,7 @@ impl<'a> ContactUpdate<'a> { &mut self, email: &'a str, postal_info: PostalInfo<'a>, - voice: Phone, + voice: Phone<'a>, auth_password: &'a str, ) { self.contact.change_info = Some(ContactChangeInfo { @@ -43,7 +43,7 @@ impl<'a> ContactUpdate<'a> { } /// Sets the data for the <fax> tag under <chg> for the contact update request - pub fn set_fax(&mut self, fax: Phone) { + pub fn set_fax(&mut self, fax: Phone<'a>) { if let Some(info) = &mut self.contact.change_info { info.fax = Some(fax) } @@ -66,9 +66,9 @@ pub struct ContactChangeInfo<'a> { #[serde(rename = "contact:postalInfo")] postal_info: Option>, #[serde(rename = "contact:voice")] - voice: Option, + voice: Option>, #[serde(rename = "contact:fax")] - fax: Option, + fax: Option>, #[serde(rename = "contact:email")] email: Option>, #[serde(rename = "contact:authInfo")] @@ -79,7 +79,7 @@ pub struct ContactChangeInfo<'a> { #[derive(Serialize, Debug)] pub struct StatusList<'a> { #[serde(rename = "contact:status")] - status: &'a [ObjectStatus], + status: &'a [ObjectStatus<'a>], } /// Type for elements under the contact <update> tag @@ -126,11 +126,11 @@ mod tests { object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323"); let add_statuses = &[ObjectStatus { - status: "clientTransferProhibited".to_string(), + status: "clientTransferProhibited".into(), }]; object.add(add_statuses); let remove_statuses = &[ObjectStatus { - status: "clientDeleteProhibited".to_string(), + status: "clientDeleteProhibited".into(), }]; object.remove(remove_statuses); diff --git a/src/domain.rs b/src/domain.rs index 6408712..48a0238 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use serde::{Deserialize, Serialize}; use crate::common::{HostAddr, StringValue}; @@ -20,7 +22,7 @@ pub struct HostAttr<'a> { pub name: StringValue<'a>, /// The <hostAddr> tags #[serde(rename = "domain:hostAddr", alias = "hostAddr")] - pub addresses: Option>, + pub addresses: Option>>, } /// The list of <hostAttr> types for domain transactions. Typically under an <ns> tag @@ -50,13 +52,13 @@ pub enum HostList<'a> { /// The <contact> type on domain creation and update requests #[derive(Serialize, Deserialize, Debug)] -pub struct DomainContact { +pub struct DomainContact<'a> { /// The contact id #[serde(rename = "$value")] - pub id: String, + pub id: Cow<'a, str>, /// The contact type attr (usually admin, billing, or tech in most registries) #[serde(rename = "type")] - pub contact_type: String, + pub contact_type: Cow<'a, str>, } /// The <period> type for registration, renewal or transfer on domain transactions diff --git a/src/domain/create.rs b/src/domain/create.rs index bc66b24..251d60a 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<&'a [DomainContact]>, + pub contacts: Option<&'a [DomainContact<'a>]>, /// 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<&'a [DomainContact]>, + contacts: Option<&'a [DomainContact<'a>]>, ) -> Self { Self { domain: DomainCreateRequestData { @@ -115,16 +115,16 @@ mod tests { let contacts = &[ DomainContact { - contact_type: "admin".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "admin".into(), + id: "eppdev-contact-3".into(), }, DomainContact { - contact_type: "tech".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "tech".into(), + id: "eppdev-contact-3".into(), }, DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "billing".into(), + id: "eppdev-contact-3".into(), }, ]; @@ -150,16 +150,16 @@ mod tests { let contacts = &[ DomainContact { - contact_type: "admin".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "admin".into(), + id: "eppdev-contact-3".into(), }, DomainContact { - contact_type: "tech".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "tech".into(), + id: "eppdev-contact-3".into(), }, DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "billing".into(), + id: "eppdev-contact-3".into(), }, ]; @@ -186,16 +186,16 @@ mod tests { let contacts = &[ DomainContact { - contact_type: "admin".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "admin".into(), + id: "eppdev-contact-3".into(), }, DomainContact { - contact_type: "tech".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "tech".into(), + id: "eppdev-contact-3".into(), }, DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-3".to_string(), + contact_type: "billing".into(), + id: "eppdev-contact-3".into(), }, ]; diff --git a/src/domain/info.rs b/src/domain/info.rs index b80e46b..d68c46d 100644 --- a/src/domain/info.rs +++ b/src/domain/info.rs @@ -17,10 +17,7 @@ impl<'a> DomainInfo<'a> { Self { info: DomainInfoRequestData { xmlns: XMLNS, - domain: Domain { - hosts: "all".to_string(), - name: name.to_string(), - }, + domain: Domain { hosts: "all", name }, auth_info: auth_password.map(|password| DomainAuthInfo { password: password.into(), }), @@ -33,12 +30,12 @@ impl<'a> DomainInfo<'a> { /// Type for data under the <name> element tag for the domain <info> tag #[derive(Serialize, Debug)] -pub struct Domain { +pub struct Domain<'a> { /// The hosts attribute. Default value is "all" - hosts: String, + hosts: &'a str, /// The name of the domain #[serde(rename = "$value")] - name: String, + name: &'a str, } /// Type for <name> element under the domain <info> tag @@ -49,7 +46,7 @@ pub struct DomainInfoRequestData<'a> { xmlns: &'a str, /// The data for the domain to be queried #[serde(rename = "domain:name")] - domain: Domain, + domain: Domain<'a>, /// The auth info for the domain #[serde(rename = "domain:authInfo")] auth_info: Option>, @@ -85,12 +82,12 @@ pub struct DomainInfoResponseData { pub roid: StringValue<'static>, /// The list of domain statuses #[serde(rename = "status")] - pub statuses: Option>, + pub statuses: Option>>, /// The domain registrant pub registrant: Option>, /// The list of domain contacts #[serde(rename = "contact")] - pub contacts: Option>, + pub contacts: Option>>, /// The list of domain nameservers #[serde(rename = "ns")] pub ns: Option, diff --git a/src/domain/transfer.rs b/src/domain/transfer.rs index ee18044..b97ad38 100644 --- a/src/domain/transfer.rs +++ b/src/domain/transfer.rs @@ -50,7 +50,7 @@ impl<'a> DomainTransfer<'a> { auth_info: Option>, ) -> Self { Self { - operation: operation.to_string(), + operation, domain: DomainTransferReqData { xmlns: XMLNS, name: name.into(), @@ -88,7 +88,7 @@ pub struct DomainTransfer<'a> { /// The transfer operation to perform indicated by the 'op' attr /// The values are one of transfer or query #[serde(rename = "op")] - operation: String, + operation: &'a str, /// The data under the <transfer> tag in the transfer request #[serde(rename = "domain:transfer")] domain: DomainTransferReqData<'a>, diff --git a/src/domain/update.rs b/src/domain/update.rs index 1d57ffa..a2c9c3d 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<&'a [DomainContact]>, + pub contacts: Option<&'a [DomainContact<'a>]>, /// The list of statuses to add to or remove from the domain #[serde(rename = "domain:status")] - pub statuses: Option<&'a [ObjectStatus]>, + pub statuses: Option<&'a [ObjectStatus<'a>]>, } /// Type for elements under the <update> tag for domain update @@ -113,7 +113,7 @@ mod tests { let mut object = DomainUpdate::new("eppdev.com"); let statuses = &[ObjectStatus { - status: "clientDeleteProhibited".to_string(), + status: "clientDeleteProhibited".into(), }]; let add = DomainAddRemove { @@ -123,8 +123,8 @@ mod tests { }; let contacts = &[DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-2".to_string(), + contact_type: "billing".into(), + id: "eppdev-contact-2".into(), }]; let remove = DomainAddRemove { diff --git a/src/extensions/namestore.rs b/src/extensions/namestore.rs index eafcb2b..96b54e6 100644 --- a/src/extensions/namestore.rs +++ b/src/extensions/namestore.rs @@ -1,5 +1,7 @@ //! Types for EPP namestore request and responses +use std::borrow::Cow; + use serde::{Deserialize, Serialize}; use crate::{ @@ -23,62 +25,62 @@ pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1"; // Contact -impl<'a> Transaction for ContactCheck<'a> {} -impl<'a> Transaction for ContactCreate<'a> {} -impl<'a> Transaction for ContactDelete<'a> {} -impl<'a> Transaction for ContactInfo<'a> {} -impl<'a> Transaction for ContactUpdate<'a> {} +impl<'a> Transaction> for ContactCheck<'a> {} +impl<'a> Transaction> for ContactCreate<'a> {} +impl<'a> Transaction> for ContactDelete<'a> {} +impl<'a> Transaction> for ContactInfo<'a> {} +impl<'a> Transaction> for ContactUpdate<'a> {} // Domain -impl<'a> Transaction for DomainCheck<'a> {} -impl<'a> Transaction for DomainCreate<'a> {} -impl<'a> Transaction for DomainDelete<'a> {} -impl<'a> Transaction for DomainInfo<'a> {} -impl<'a> Transaction for DomainRenew<'a> {} -impl<'a> Transaction for DomainTransfer<'a> {} -impl<'a> Transaction for DomainUpdate<'a> {} +impl<'a> Transaction> for DomainCheck<'a> {} +impl<'a> Transaction> for DomainCreate<'a> {} +impl<'a> Transaction> for DomainDelete<'a> {} +impl<'a> Transaction> for DomainInfo<'a> {} +impl<'a> Transaction> for DomainRenew<'a> {} +impl<'a> Transaction> for DomainTransfer<'a> {} +impl<'a> Transaction> for DomainUpdate<'a> {} // Host -impl<'a> Transaction for HostCheck<'a> {} -impl<'a> Transaction for HostCreate<'a> {} -impl<'a> Transaction for HostDelete<'a> {} -impl<'a> Transaction for HostInfo<'a> {} -impl<'a> Transaction for HostUpdate<'a> {} +impl<'a> Transaction> for HostCheck<'a> {} +impl<'a> Transaction> for HostCreate<'a> {} +impl<'a> Transaction> for HostDelete<'a> {} +impl<'a> Transaction> for HostInfo<'a> {} +impl<'a> Transaction> for HostUpdate<'a> {} -impl NameStore { +impl<'a> NameStore<'a> { /// Create a new RGP restore report request pub fn new(subproduct: &str) -> NameStore { NameStore { data: NameStoreData { - xmlns: XMLNS.to_string(), + xmlns: XMLNS.into(), subproduct: subproduct.to_owned().into(), }, } } } -impl Extension for NameStore { - type Response = NameStore; +impl<'a> Extension for NameStore<'a> { + type Response = NameStore<'static>; } #[derive(Debug, Deserialize, Serialize)] #[serde(rename = "namestoreExt:namestoreExt")] -pub struct NameStore { +pub struct NameStore<'a> { #[serde(rename = "namestoreExt:namestoreExt", alias = "namestoreExt")] - pub data: NameStoreData, + pub data: NameStoreData<'a>, } #[derive(Serialize, Deserialize, Debug)] /// Type for EPP XML <namestoreExt> extension -pub struct NameStoreData { +pub struct NameStoreData<'a> { /// XML namespace for the RGP restore extension #[serde(rename = "xmlns:namestoreExt", alias = "xmlns")] - pub xmlns: String, + pub xmlns: Cow<'a, str>, /// The object holding the list of domains to be checked #[serde(rename = "namestoreExt:subProduct", alias = "subProduct")] - pub subproduct: StringValue<'static>, + pub subproduct: StringValue<'a>, } #[cfg(test)] diff --git a/src/extensions/rgp/report.rs b/src/extensions/rgp/report.rs index 9af18ae..6b19a0a 100644 --- a/src/extensions/rgp/report.rs +++ b/src/extensions/rgp/report.rs @@ -26,7 +26,7 @@ impl<'a> RgpRestoreReport<'a> { Self { xmlns: XMLNS, restore: RgpRestoreReportSection { - op: "report".to_string(), + op: "report", report: RgpRestoreReportSectionData { pre_data: pre_data.into(), post_data: post_data.into(), @@ -79,7 +79,7 @@ pub struct RgpRestoreReportSectionData<'a> { #[derive(Serialize, Debug)] pub struct RgpRestoreReportSection<'a> { /// The value of the op attribute for the <restore> tag - op: String, + op: &'a str, /// Data for the <report> tag #[serde(rename = "rgp:report")] report: RgpRestoreReportSectionData<'a>, diff --git a/src/extensions/rgp/request.rs b/src/extensions/rgp/request.rs index bd488f0..a6ed00d 100644 --- a/src/extensions/rgp/request.rs +++ b/src/extensions/rgp/request.rs @@ -9,11 +9,11 @@ use serde::{Deserialize, Serialize}; use super::{Update, XMLNS}; -impl<'a> Transaction> for DomainUpdate<'a> {} +impl<'a> Transaction>> for DomainUpdate<'a> {} -impl<'a> Transaction> for DomainInfo<'a> {} +impl<'a> Transaction>> for DomainInfo<'a> {} -impl Extension for Update { +impl<'a> Extension for Update> { type Response = Update; } @@ -21,29 +21,27 @@ impl Extension for Update { /// Type corresponding to the <restore> tag for an rgp restore request #[derive(Serialize, Debug)] -pub struct RgpRestoreRequestData { +pub struct RgpRestoreRequestData<'a> { /// The value of the op attribute in the <restore> tag - pub op: String, + pub op: &'a str, } #[derive(Serialize, Debug)] /// Type for EPP XML <check> command for domains -pub struct RgpRestoreRequest { +pub struct RgpRestoreRequest<'a> { /// XML namespace for the RGP restore extension #[serde(rename = "xmlns:rgp")] - xmlns: &'static str, + xmlns: &'a str, /// The object holding the list of domains to be checked #[serde(rename = "rgp:restore")] - restore: RgpRestoreRequestData, + restore: RgpRestoreRequestData<'a>, } -impl Default for RgpRestoreRequest { +impl Default for RgpRestoreRequest<'static> { fn default() -> Self { Self { xmlns: XMLNS, - restore: RgpRestoreRequestData { - op: "request".to_string(), - }, + restore: RgpRestoreRequestData { op: "request" }, } } } diff --git a/src/host/create.rs b/src/host/create.rs index ba522a9..ff07f37 100644 --- a/src/host/create.rs +++ b/src/host/create.rs @@ -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<&'a [HostAddr]>, + pub addresses: Option<&'a [HostAddr<'a>]>, } #[derive(Serialize, Debug)] diff --git a/src/host/info.rs b/src/host/info.rs index 4245fb0..53b82cc 100644 --- a/src/host/info.rs +++ b/src/host/info.rs @@ -55,10 +55,10 @@ pub struct HostInfoResponseData { pub roid: StringValue<'static>, /// The list of host statuses #[serde(rename = "status")] - pub statuses: Vec, + pub statuses: Vec>, /// The list of host IP addresses #[serde(rename = "addr")] - pub addresses: Vec, + pub addresses: Vec>, /// The epp user to whom the host belongs #[serde(rename = "clID")] pub client_id: StringValue<'static>, diff --git a/src/host/update.rs b/src/host/update.rs index 807725f..d2e71bd 100644 --- a/src/host/update.rs +++ b/src/host/update.rs @@ -54,10 +54,10 @@ pub struct HostChangeInfo<'a> { pub struct HostAddRemove<'a> { /// The IP addresses to be added to or removed from the host #[serde(rename = "host:addr")] - pub addresses: Option<&'a [HostAddr]>, + pub addresses: Option<&'a [HostAddr<'a>]>, /// The statuses to be added to or removed from the host #[serde(rename = "host:status")] - pub statuses: Option<&'a [ObjectStatus]>, + pub statuses: Option<&'a [ObjectStatus<'a>]>, } /// Type for data under the host <update> tag @@ -107,7 +107,7 @@ mod tests { }; let statuses = &[ObjectStatus { - status: "clientDeleteProhibited".to_string(), + status: "clientDeleteProhibited".into(), }]; let remove = HostAddRemove { diff --git a/src/message/ack.rs b/src/message/ack.rs index 624ece8..90d1c10 100644 --- a/src/message/ack.rs +++ b/src/message/ack.rs @@ -4,28 +4,28 @@ use crate::common::NoExtension; use crate::request::{Command, Transaction}; use serde::Serialize; -impl Transaction for MessageAck {} +impl<'a> Transaction for MessageAck<'a> {} -impl Command for MessageAck { +impl<'a> Command for MessageAck<'a> { type Response = String; const COMMAND: &'static str = "poll"; } #[derive(Serialize, Debug)] /// Type for EPP XML <poll> command for message ack -pub struct MessageAck { +pub struct MessageAck<'a> { /// The type of operation to perform /// The value is "ack" for message acknowledgement - op: String, + op: &'a str, /// The ID of the message to be acknowledged #[serde(rename = "msgID")] message_id: String, } -impl MessageAck { +impl<'a> MessageAck<'a> { pub fn new(message_id: u32) -> Self { Self { - op: "ack".to_string(), + op: "ack", message_id: message_id.to_string(), } } diff --git a/src/message/poll.rs b/src/message/poll.rs index 977281c..c6f31be 100644 --- a/src/message/poll.rs +++ b/src/message/poll.rs @@ -2,9 +2,9 @@ use crate::common::{NoExtension, StringValue}; use crate::request::{Command, Transaction}; use serde::{Deserialize, Serialize}; -impl Transaction for MessagePoll {} +impl<'a> Transaction for MessagePoll<'a> {} -impl Command for MessagePoll { +impl<'a> Command for MessagePoll<'a> { type Response = MessagePollResponse; const COMMAND: &'static str = "poll"; } @@ -13,17 +13,15 @@ impl Command for MessagePoll { #[derive(Serialize, Debug)] /// Type for EPP XML <poll> command for message poll -pub struct MessagePoll { +pub struct MessagePoll<'a> { /// The type of operation to perform /// The value is "req" for message polling - op: String, + op: &'a str, } -impl Default for MessagePoll { +impl Default for MessagePoll<'static> { fn default() -> Self { - Self { - op: "req".to_owned(), - } + Self { op: "req" } } }