From f7d76adef3194e17ad7790da6e1e661b612de319 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 22 Feb 2022 17:49:02 +0100 Subject: [PATCH] Implement AsRef for StringValue --- src/common.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/common.rs b/src/common.rs index bbc09c9..d8be54c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,5 +1,6 @@ //! Common data types included in EPP Requests and Responses +use std::ops::Deref; use std::{borrow::Cow, fmt::Display, net::IpAddr}; use serde::ser::SerializeSeq; @@ -14,6 +15,20 @@ pub(crate) const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0"; #[derive(Default, Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct StringValue<'a>(Cow<'a, str>); +impl Deref for StringValue<'_> { + type Target = str; + + fn deref(&self) -> &Self::Target { + self.0.as_ref() + } +} + +impl<'a> AsRef for StringValue<'a> { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + impl Display for StringValue<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0)