webpki icon indicating copy to clipboard operation
webpki copied to clipboard

Add as_str to DNSName

Open Rantanen opened this issue 4 years ago • 3 comments

There already exists AsRef<str> implementation for DNSName, but given there is also as_ref() -> DNSNameRef, trying to get a &str with dns_name.as_ref() ends up picking the wrong implementation.

The AsRef::<str>::as_ref(&source) alternative works, but isn't that pretty!

The as_str() is somewhat idiomatic solution to this (see String::as_str() for an example).

(The AsRef::<str>::... is a suitable workaround, which I've already unleashed upon my codebase so I don't really need this PR to land if there's a reason to reject it.)

Pull requests must explicitly indicate who owns the copyright to the code being contributed and that the code is being licensed under the same terms as the existing webpki code.

I don't believe the changes are significant enough to be covered by copyright, but to avoid any doubt, if they were, I'd be the owner and I'll license them under the same terms as the exiting webpki code.

Rantanen avatar May 30 '20 08:05 Rantanen

Sorry for the slow response. I agree that the situation with AsRef is unfortunate. I'll be updating PR #125 soon to try to merge DnsName and DnsNameRef into one type. As part of that, we should try to solve the AsRef problem.

briansmith avatar Dec 30 '20 07:12 briansmith

Note: I renamed the "master" branch to "main". Sorry for the inconvenience. This PR has had its base branch updated to "main" but you'll need to deal with the change in your local repo yourself.

briansmith avatar Jan 14 '21 01:01 briansmith

This is a one line change (plus the comment), it might be better to just implement the change directly in #125 if there's a larger rework. :)

Rantanen avatar Jan 14 '21 07:01 Rantanen