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

Extend string types #293

Merged
merged 7 commits into from
Nov 13, 2022
Merged

Extend string types #293

merged 7 commits into from
Nov 13, 2022

Conversation

maspe36
Copy link
Collaborator

@maspe36 maspe36 commented Nov 11, 2022

Implemented Extend<char>, Extend<&'a char>, FromIterator<char>, and FromIterator<&'a char> for String and WString.

Of note here is that with this change, String and WString now have interior mutability so they are no longer able to implement Sync safely.

Original Issue: #246

@esteve esteve requested a review from a team November 11, 2022 06:20
Copy link
Contributor

@nnmm nnmm left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! I left a comment.

rosidl_runtime_rs/src/string.rs Outdated Show resolved Hide resolved
rosidl_runtime_rs/src/string.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@nnmm nnmm left a comment

Choose a reason for hiding this comment

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

LGTM, just some small changes to tidy up are remaining.

@@ -224,6 +225,42 @@ macro_rules! string_impl {
}
}

impl From<&std::string::String> for $string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the existing From<&str> impl is more general, I think this impl isn't necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So in *self = Self::from(&s);, &s is actually of type &String and From isn't implemented for that type. So I removed this impl by just using Self::from(s.as_str()) in the Extend impl

Copy link
Contributor

Choose a reason for hiding this comment

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

That's correct, though using Self::from(&s) should work too due to Deref coercion.

rosidl_runtime_rs/src/string.rs Outdated Show resolved Hide resolved
rosidl_runtime_rs/src/string.rs Outdated Show resolved Hide resolved
rosidl_runtime_rs/src/string.rs Outdated Show resolved Hide resolved
@@ -126,21 +126,6 @@ macro_rules! string_impl {
) -> bool;
}

impl Default for $string {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alphabetizing the trait impl's

Copy link
Contributor

@nnmm nnmm left a comment

Choose a reason for hiding this comment

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

Thanks for making these changes!

@maspe36
Copy link
Collaborator Author

maspe36 commented Nov 13, 2022

Thanks for making these changes!

Thanks for all the guidance :)

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