diff --git a/src/common.rs b/src/common.rs index 24604e4..bd43687 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,6 +1,6 @@ //! Common data types included in EPP Requests and Responses -use std::fmt::Display; +use std::{borrow::Cow, fmt::Display}; use serde::{Deserialize, Serialize}; @@ -11,23 +11,23 @@ pub(crate) const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0"; /// Wraps String for easier serialization to and from values that are inner text /// for tags rather than attributes #[derive(Default, Serialize, Deserialize, Debug, PartialEq, Clone)] -pub struct StringValue(String); +pub struct StringValue<'a>(Cow<'a, str>); -impl Display for StringValue { +impl Display for StringValue<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } -impl From<&str> for StringValue { - fn from(s: &str) -> Self { - Self(s.to_owned()) +impl<'a> From<&'a str> for StringValue<'a> { + fn from(s: &'a str) -> Self { + Self(s.into()) } } -impl From for StringValue { +impl From for StringValue<'static> { fn from(s: String) -> Self { - Self(s) + Self(s.into()) } } @@ -42,17 +42,17 @@ impl Extension for NoExtension { /// The