feature request: Add `impl TryFrom<Arc<str>> for Regex`
Hi, thanks for the amazing crate!
As the internal pattern is an Arc<str>, is it possible to add impl From<Regex> for Arc<str> and impl From<&Regex> for Arc<str> implementation? It is useful when doing conversions between types.
Well, it certainly can't be From<Arc<str>>. I would be open to a impl TryFrom<Arc<str>> for Regex though, since that's consistent with existing TryFrom<&str> and TryFrom<String> impls.
I don't see why there should be an impl From<&Regex> for Arc<str> though. There is already a Regex::as_str, and implementing From<&Regex> for the various string types seems a little weird to me. I'm unclear on the use case.
As the internal pattern is an
Arc<str>
The internal representation should have absolutely nothing to do with this. If you're mentioning this because you think it makes the conversion cheaper, then that is almost certainly not true in any meaningful sense.
Well, it certainly can't be
From<Arc<str>>. I would be open to aimpl TryFrom<Arc<str>> for Regexthough, since that's consistent with existingTryFrom<&str>andTryFrom<String>impls.I don't see why there should be an
impl From<&Regex> for Arc<str>though. There is already aRegex::as_str, and implementingFrom<&Regex>for the various string types seems a little weird to me. I'm unclear on the use case.As the internal pattern is an
Arc<str>The internal representation should have absolutely nothing to do with this. If you're mentioning this because you think it makes the conversion cheaper, then that is almost certainly not true in any meaningful sense.
The use case for impl From<Regex> for Arc<str> and impl From<&Regex> for Arc<str> is FFI, indeed, the current API, users can get the &str, but it will require another allocation to construct a new Arc<str> for FFI
That isn't a compelling enough motivation on its own IMO. That impl would require regex to always internally have an Arc<str>, and this may not always be true. Indeed, it hasn't always been true.
That isn't a compelling enough motivation on its own IMO. That impl would require
regexto always internally have anArc<str>, and this may not always be true. Indeed, it hasn't always been true.
Got it, yes, the internal may change in the future.
I don't get why you closed this? I did say that adding impl TryFrom<Arc<str>> for Regex should be totally fine.
I don't get why you closed this? I did say that adding
impl TryFrom<Arc<str>> for Regexshould be totally fine.
I closed this because impl From<Regex> for Arc<str> will not be added. May be I should change the title of this issue to impl TryFrom<Arc<str>> for Regex?
Ah I see. I think a misread that your request wanted a From<Arc<str>> for Regex impl. My bad. But I think that is a valid thing to want, so I changed the title to reflect that. But I get why you closed this now. Sorry for the misunderstanding!