diff --git a/src/protocol/frame/utf8.rs b/src/protocol/frame/utf8.rs index 9166d979..cd4de58f 100644 --- a/src/protocol/frame/utf8.rs +++ b/src/protocol/frame/utf8.rs @@ -24,12 +24,44 @@ impl Utf8Bytes { impl std::ops::Deref for Utf8Bytes { type Target = str; + /// ``` + /// use tungstenite::protocol::frame::Utf8Bytes; + /// + /// /// Example fn that takes a str slice + /// fn a(s: &str) {} + /// + /// let data = Utf8Bytes::from_static("foo123"); + /// + /// // auto-deref as arg + /// a(&data); + /// + /// // deref to str methods + /// assert_eq!(data.len(), 6); + /// ``` #[inline] fn deref(&self) -> &Self::Target { self.as_str() } } +impl PartialEq for Utf8Bytes +where + for<'a> &'a str: PartialEq, +{ + /// ``` + /// use tungstenite::protocol::frame::Utf8Bytes; + /// let payload = Utf8Bytes::from_static("foo123"); + /// assert_eq!(payload, "foo123"); + /// assert_eq!(payload, "foo123".to_string()); + /// assert_eq!(payload, &"foo123".to_string()); + /// assert_eq!(payload, std::borrow::Cow::from("foo123")); + /// ``` + #[inline] + fn eq(&self, other: &T) -> bool { + self.as_str() == *other + } +} + impl Display for Utf8Bytes { #[inline] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {