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

Replace string crate with a handrolled type #44

Merged
merged 3 commits into from
Feb 26, 2024
Merged

Conversation

bkirwi
Copy link
Contributor

@bkirwi bkirwi commented Feb 23, 2024

Addresses: #43

  • The first commit adds a couple of TopicName helpers that make it easier to convert to/from normal string types.
  • The second commit replaces the entire dep with a from-scratch reimplementation.

The second commit involves a small bit of unsafe code. If that's a problem for us, there are options to remove it (at some possible runtime cost) which we could discuss. But maybe it's fine? I'm personally a bit split on it.

Copy link
Owner

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

Thanks, this is really straightforward and seems like a great improvement. Will you just remove string from our deps?

#[derive(Clone, Hash, Ord, PartialOrd, PartialEq, Eq, Default)]
pub struct StrBytes(Bytes);

impl StrBytes {
Copy link
Owner

Choose a reason for hiding this comment

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

Wondering if we also want to provide unchecked constructors, although perhaps it's best to proceed with the entirely safe API first and see if anyone has a need for them later.

@tychedelia
Copy link
Owner

Also @bkirwi It looks like your first commit got clobbered by the second. I'm not seeing the topic name changes in the diff.

@tychedelia tychedelia self-assigned this Feb 23, 2024
@tychedelia tychedelia added the enhancement New feature or request label Feb 23, 2024
@tychedelia tychedelia mentioned this pull request Feb 25, 2024
Copy link
Collaborator

@rukai rukai left a comment

Choose a reason for hiding this comment

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

Thanks a lot, the old string type was causing us all sorts of problems.
I didnt think to replace it!

@bkirwi
Copy link
Contributor Author

bkirwi commented Feb 26, 2024

Will you just remove string from our deps?

string should be removed from the deps here: https://github.com/tychedelia/kafka-protocol-rs/pull/44/files#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542L32

I've checked cargo tree and confirmed that it's no longer present in the transitive deps.

It looks like your first commit got clobbered by the second. I'm not seeing the topic name changes in the diff.

Apologies - this was semi-intentional, and I should have called it out! We get the as_str for free from the Deref implementation. We don't have the From<String> for TopicName, though... StrBytes::from_string(s).into() felt lightweight enough that I didn't bother re-introducing it, but I'd be happy to if y'all prefer.

It looks like I have a merge conflict here... I should be able to address it in the next few days, but feel free to push to the branch if you'd rather push this through sooner!

@tychedelia
Copy link
Owner

string should be removed from the deps here

Ope! Somehow missed that. Apologies.

StrBytes::from_string(s).into() felt lightweight enough that I didn't bother re-introducing it, but I'd be happy to if y'all prefer.

It's not too bad at all, but I definitely think "name".into() would be very ergonomic. If you want to, this can be a follow up (in addition to GroupId which is the other StrBytes type). Thanks again for this contribution!

@tychedelia tychedelia merged commit 9e247ed into tychedelia:main Feb 26, 2024
1 check passed
@thedodd
Copy link
Contributor

thedodd commented Feb 27, 2024

🎉 this is great! It has also been a major ergonomics issue for me as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants