From bbf2f63aa6e8534f179e3f2e17c68e4ec9f896bc Mon Sep 17 00:00:00 2001 From: sunny-g Date: Tue, 5 Mar 2024 19:37:19 -0600 Subject: [PATCH 1/2] additional useful derives/impls --- async-nats/src/lib.rs | 4 ++-- async-nats/src/subject.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/async-nats/src/lib.rs b/async-nats/src/lib.rs index 669e259ff..360b0615e 100644 --- a/async-nats/src/lib.rs +++ b/async-nats/src/lib.rs @@ -264,7 +264,7 @@ pub use status::StatusCode; /// Information sent by the server back to this client /// during initial connection, and possibly again later. -#[derive(Debug, Deserialize, Default, Clone, Eq, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Default, Clone, Eq, PartialEq)] pub struct ServerInfo { /// The unique identifier of the NATS server. #[serde(default)] @@ -1293,7 +1293,7 @@ impl std::fmt::Display for ServerError { } /// Info to construct a CONNECT message. -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct ConnectInfo { /// Turns on +OK protocol acknowledgments. pub verbose: bool, diff --git a/async-nats/src/subject.rs b/async-nats/src/subject.rs index 864b5cd40..7fb086b47 100644 --- a/async-nats/src/subject.rs +++ b/async-nats/src/subject.rs @@ -2,10 +2,10 @@ use bytes::Bytes; use serde::{Deserialize, Serialize}; use std::fmt; use std::ops::Deref; -use std::str::{from_utf8, Utf8Error}; +use std::str::{from_utf8, FromStr, Utf8Error}; /// A `Subject` is an immutable string type that guarantees valid UTF-8 contents. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Subject { bytes: Bytes, } @@ -105,6 +105,14 @@ impl From for Subject { } } +impl FromStr for Subject { + type Err = Utf8Error; + + fn from_str(s: &str) -> Result { + Ok(Self::from(s)) + } +} + impl AsRef for Subject { fn as_ref(&self) -> &str { self From 2870b44a61709c0ab75e176b1a594bfc1dcc7b68 Mon Sep 17 00:00:00 2001 From: sunny-g Date: Thu, 14 Mar 2024 18:53:55 -0500 Subject: [PATCH 2/2] add hash to connectinfo, protocol --- async-nats/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/async-nats/src/lib.rs b/async-nats/src/lib.rs index 360b0615e..730beabba 100644 --- a/async-nats/src/lib.rs +++ b/async-nats/src/lib.rs @@ -1293,7 +1293,7 @@ impl std::fmt::Display for ServerError { } /// Info to construct a CONNECT message. -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct ConnectInfo { /// Turns on +OK protocol acknowledgments. pub verbose: bool, @@ -1354,7 +1354,7 @@ pub struct ConnectInfo { } /// Protocol version used by the client. -#[derive(Serialize_repr, Deserialize_repr, PartialEq, Eq, Debug, Clone, Copy)] +#[derive(Serialize_repr, Deserialize_repr, PartialEq, Eq, Hash, Debug, Clone, Copy)] #[repr(u8)] pub enum Protocol { /// Original protocol.