-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add borrow impl for Dname<Vec<u8>> #219
Conversation
Thank you for the PR. Those missing Curiously, I added a blanket impl along the lines you mentioned as a starting point to try out a few work-arounds and the compiler just accepted it. The impl in question was
What error did you get? |
oh! i took poor notes and confused myself just the same. the issue actually appears with slightly more permissive bounds: impl<Octs: AsRef<[u8]> + ?Sized> borrow::Borrow<Dname<[u8]>> for Dname<Octs> {
fn borrow(&self) -> &Dname<[u8]> {
self.for_slice()
}
} which rustc rejects with:
thinking about it more, i'm not sure where someone would have a container keyed on thanks for double-checking there, i'm certainly glad to see using just |
Ah yes, that explains it. In fact, I’ve had this case before where the missing |
This impl supports users of `domain` that may use `Dname` as keys in standard library collections, who may want to query those collections with non-owned `Dname`. Include a doc comment testing that a collection of `Dname<Vec<u8>>` can be queried with a `Dname<[u8]>`.
(updated the PR to a more generic |
@partim was there anything else to do with this on my side? i'm not sure if we've accidentally deadlocked waiting for the other to say something 😁 |
Oh, my apologies. I completely forgot about the PR. I’m now wondering if we should perhaps also have |
@iximeow Could you merge main into the branch so we get the CI to go green? |
aha, i hadn't quite realized that CI runs rely on your approval since this is an external PR. and then it's using main's there probably should be an |
Looking good now – thank you for the PR! I’ll add the |
New * Added a new method `FoundSrvs::into_srvs` that converts the value into an iterator over the found SRV records without resolving them further. ([#174], [#214] by [@WhyNotHugo]); this was added in 0.7.2 but missing in 0.8.0) * Added impl of `Borrow<Dname<[u8]>>` and `AsRef<Dname<[u8]>>` for `Dname<_>`. ([#219] by [@iximeow}], [#225]) * Added `Dname::fmt_with_dot` that can be used when wanting to display a domain name with a dot at the end. ([#210]) Bug Fixes * Fixed trait bounds on `FoundSrvs::into_stream` to make it usable again. ([#174], [#214 by [@WhyNotHugo]]; this was fixed in 0.7.2 but missing in 0.8.0) * Fixed scanning of domain names that are just the root label. ([#210]) * Fixed `util::base64::SymbolConverter` to also include the final group in the output if there is padding. ([#212])
This impl supports users of
domain
that may useDname
as keys in standard library collections, who may want to query those collections with non-ownedDname
.Include a doc comment testing that a collection of
Dname<Vec<u8>>
can be queried with aDname<[u8]>
.this comes from talking with @edmonds today, who was trying to do the seemingly-reasonable operation of building a map of
Dname
and associated attributes, then looking entries in that map up from aDname
built from a&[u8]
. unfortunately, i think the best we can do is best-effort implementations ofBorrow
forT: AsRef<[u8]>
that seem "useful enough"; there would need to be another impl for someone who has made a collection keyed onDname<Bytes>
, for example.ideally we'd be able to writeimpl<Octs: AsRef<[u8]>> Borrow<Dname<[u8]>> for Dname<Octs>
, butrustc
(unfortunately, correctly), realizes that that permitsimpl Borrow<Dname<[u8]>> for Dname<[u8]>
, which conflicts with the blanket impl ofBorrow<T> for T
in stdlib. i figured noting that wrinkle is helpful in the doc comment for any future confused souls, but i don't know your appetite for otherBorrow
impls (or this one!) indomain
itself - users could add a newtype in their code and write an appropriateBorrow
impl for any owned octet collections they're using in their containers.edit: turns out the above issue was trying to write an
impl<Octs: AsRef<[u8]> + ?Sized>
, butimpl<Octs: AsRef<[u8]>
alone is accepted by rustc and looks to do the right things.