-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Swap From<Cow<'static, str>>
with From<Cow<'_, str>>
for IString
#70
base: main
Are you sure you want to change the base?
Conversation
I'm not sure about it but I think Cow static is the most common case and the other one only an exception. Maybe we could treat it as such and create from_osstr_lossy instead that would take an osstr in argument? I don't know, I need to double check if that makes any logical sense but I'm not at home at the moment If we go the other way around we should probably also add Into-Cow because I read lot of APIs allow using that type as parameter. |
I can also just do
No clue, never used it. Having owned variant being bound by some reference lifetime sounds really annoying, it is like the worst of both refs and owneds worlds. In |
They use the Cow ref in regex apparently: https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
Yeah I know... I'm just less keen with Cow because it seemed like the right case where we should prefer the static one and not the ref one. After all, the whole point of IString is to be a fancier version of the original AttrValue made by @ranile which in turn was a fancy version of Cow static str as it was originally used in Yew.
I'm surprised by this to be honest. It was done as part of #10. I think @ranile will have more feedback on this. |
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.
In doubt I'm not blocking it if you think it's the right way
It's been too long for me to remember the details. With Yew, |
To put you into the context, we have a dilemma:
Your comment about "being able to infer the lifetime in Yew uses correctly", honestly I did not understand what exactly you mean lol |
Thanks for the context! I would prefer the 2nd option but with a helper function to add back the previous implementation with the optimization. My thought process is: API that is not optimized in one case is better than one that fails with a horrible error message. Achieving that without losing functionality is best. Worth mentioning, I don't really have a strong opinion either way. I'll leave the final decision up to you and @cecton
That sounds like something to raise with rustc folks. It's good to have this addressed (or at least documented, even if it's in the GH issues) upstream
That was more of "if this change doesn't break build in Yew (because of the heavy dependency and assumption of |
No, I believe this PR is an API expansion - not a breaking change, only allowing more
Not sure if there is already some way to have old behavior, which looked like this: match cow {
Cow::Borrowed(static_str) => IString::Static(static_str),
Cow::Owned(owned_string) => owned_string.into(),
} I also discussed other way around with #57, where you do not add a method for optimized case, but rather add method for unoptimized "always clone" case, leaving |
I read lot of APIs use |
There is automatic |
I just tested to be sure but it seems it compiles: impl From<Cow<'_, str>> for IString {
fn from(cow: Cow<'_, str>) -> Self {
match cow {
Cow::Borrowed(s) => s.into(),
Cow::Owned(s) => s.into(),
}
}
}
impl Into<Cow<'static, str>> for IString {
fn into(self) -> Cow<'static, str> { todo!() }
} |
I thought it was other way around, i.e. impl Into<Cow<'static, str>> for IString {
fn into(self) -> Cow<'static, str> {
match self {
IString::Static(s) => Cow::Borrowed(s),
IString::Rc(s) => Cow::Owned(s.to_string()),
}
}
} impl From<IString> for Cow<'static, str> {
fn from(s: IString) -> Cow<'static, str> {
match s {
IString::Static(s) => Cow::Borrowed(s),
IString::Rc(s) => Cow::Owned(s.to_string()),
}
}
} This would be about having a conversion path into |
Same as #67.
Reason being
OsStr::to_string_lossy
returnsCow<'_, str>
for whatever reason, preventing.into()
the very same way having onlyFrom<&'static str>
did - with the confusing errors that point to wrong places and do not describe anything much useful.