Implement AsRef<str> for StringValue

This commit is contained in:
Dirkjan Ochtman 2022-02-22 17:49:02 +01:00 committed by masalachai
parent cdbf0a2e65
commit f7d76adef3
1 changed files with 15 additions and 0 deletions

View File

@ -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<str> 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)