Skip to content
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

Make Topic a newtype #29

Merged
merged 1 commit into from
Mar 18, 2021
Merged

Make Topic a newtype #29

merged 1 commit into from
Mar 18, 2021

Conversation

nagisa
Copy link
Collaborator

@nagisa nagisa commented Mar 17, 2021

Turns out having anything with any sort of lifetime in stream/sink
chains will trigger nasty issues such as
rust-lang/rust#79648 which is pretty difficult
to figure out how to work around.

Making Topic a newtype erases the lifetime from the type, making it
significantly easier to work with in thsoe contexts.

@nagisa nagisa requested a review from rnarubin March 17, 2021 21:59
src/topic.rs Outdated
@@ -0,0 +1,21 @@
/// A message queue topic name to which messages can be published
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Topic(pub &'static str);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be a Cow<'static, str> while we're at it. Topic choice could be dynamic

Copy link
Collaborator Author

@nagisa nagisa Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC @maroux was against the idea of there being topics that can differ based on message contents, but I'll let them to chime in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the field private which should make it possible to extend this to Cow in a backwards compatible manner in the future.

Turns out having anything with any sort of lifetime in stream/sink
chains will trigger nasty issues such as
rust-lang/rust#79648 which is pretty difficult
to figure out how to work around.

Making `Topic` a newtype erases the lifetime from the type, making it
significantly easier to work with in thsoe contexts.
Copy link
Collaborator

@rnarubin rnarubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, making the internals private is a reasonable compromise. There are other potential uses where a topic could be a return type like list_topics or get_subscription_properties or whatever, so I don't want to cut off options if avoidable

@nagisa nagisa merged commit 3748aab into v4.x Mar 18, 2021
@nagisa nagisa deleted the nagisa/topic branch March 18, 2021 19:41
rnarubin pushed a commit to rnarubin/hedwig-rust that referenced this pull request Mar 29, 2021
Turns out having anything with any sort of lifetime in stream/sink
chains will trigger nasty issues such as
rust-lang/rust#79648 which is pretty difficult
to figure out how to work around.

Making `Topic` a newtype erases the lifetime from the type, making it
significantly easier to work with in thsoe contexts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants