-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support runtime Topic designation #44
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 } | ||
|
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]>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did run into this problem, since I am creating topic names dynamically - but worked around it by leaking the strings and then using a hashmap to cache the mapping from (site id, prio) -> &'static str There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess there's a reasonable bound on that combination, so that's not the worst. But we can do better! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this saying we can support any string up to 36Bytes? I wonder if any of our topics exceed that? Or is this similar to a stackvec and will falback to heap allocation if we exceed that threshold? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's backed by SmallVec, which yeah does the fallback to heap |
||
|
||
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() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular line is what I think needs to change for me to send messages across various projects. Though you might be wanting to address that in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, different PR