-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support runtime Topic designation (#44)
Previously the Topic type was only constructible from static strings. This works for code-gen messages, but doesn't work if the topic needs to be determined at runtime. This change permits constructing Topics from arbitrary strings
- Loading branch information
Showing
4 changed files
with
48 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "hedwig" | ||
version = "6.3.0" | ||
version = "6.4.0" | ||
authors = [ | ||
"Aniruddha Maru <[email protected]>", | ||
"Simonas Kazlauskas <[email protected]>", | ||
|
@@ -39,6 +39,7 @@ bytes = "1" | |
either = { version = "1", features = ["use_std"], default-features = false } | ||
futures-util = { version = "0.3.17", features = ["std", "sink"], default-features = false } | ||
pin-project = "1" | ||
smallstr = { version = "0.3.0", features = ["union"] } | ||
thiserror = { version = "1", default-features = false } | ||
url = { version = "2", default-features = false } | ||
uuid = { version = "^0.8", features = ["v4"], default-features = false } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,36 @@ | ||
use smallstr::SmallString; | ||
|
||
/// A message queue topic name to which messages can be published | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] | ||
pub struct Topic(&'static str); | ||
// A survey of common topics found lengths between 16 and 35 bytes | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct Topic(SmallString<[u8; 36]>); | ||
|
||
impl Default for Topic { | ||
fn default() -> Self { | ||
Topic(SmallString::new()) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Topic { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
std::fmt::Display::fmt(self.0, f) | ||
std::fmt::Display::fmt(self.0.as_str(), f) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a str> for Topic { | ||
fn from(s: &'a str) -> Topic { | ||
Topic(s.into()) | ||
} | ||
} | ||
|
||
impl From<&'static str> for Topic { | ||
fn from(s: &'static str) -> Topic { | ||
Topic(s) | ||
impl From<String> for Topic { | ||
fn from(s: String) -> Topic { | ||
Topic(s.into()) | ||
} | ||
} | ||
|
||
impl AsRef<str> for Topic { | ||
fn as_ref(&self) -> &str { | ||
self.0 | ||
self.0.as_ref() | ||
} | ||
} |