-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add Cow helpers for IString #10
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
Conversation
This is helpful in cases like passing the IString to a function which takes a Cow without needing to clone the content
The Clippy failure is unrelated. It's likely that the derived implementation of PartialEq that clippy is highlighting is wrong |
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.
I'm just seeing this now but it's nice! You should have ping me.
You can disable the lint for the impl of Eq at crate level I think it's not relevant here. We don't want to enforce the user to implement Eq on all their types otherwise they won't be able to store f32
and f64
in an IArray
assert_eq!(Rc::strong_count(&rc_s), 2); | ||
// this assert exists to ensure the cow lives after the strong_count asset | ||
assert_eq!(cow, "foo"); | ||
|
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.
impl From<Cow<'static, str>> for IString { | ||
fn from(cow: Cow<'static, str>) -> Self { | ||
match cow { | ||
Cow::Borrowed(s) => IString::Static(s), | ||
Cow::Owned(s) => s.into(), | ||
} | ||
} | ||
} |
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.
I think you forgot to write a test for this. It's not super important but it makes sure that someone does not remove it by mistake
I'm going to merge this. The test can be added later |
This PR adds:
IString::as_cow
impl From<Cow<'static, str>> for IString