Skip to content

Commit

Permalink
der, spki: rename to_owned method (#835)
Browse files Browse the repository at this point in the history
The naming of the `to_owned` method was a bit unfortunate as it
triggered conflicts with the `alloc::borrow::ToOwned` method. When used,
this would make for compiler messages asking things like:

```
error[E0034]: multiple applicable items in scope
   --> certval/src/validator/name_constraints_set.rs:748:34
    |
748 |                         value: a.to_owned(),
    |                                  ^^^^^^^^ multiple `to_owned` found
    |
    = note: candidate #1 is defined in an impl of the trait `RefToOwned` for the type `AnyRef<'a>`
    = note: candidate #2 is defined in an impl of the trait `ToOwned` for the type `T`
help: disambiguate the associated function for candidate #1
    |
748 |                         value: RefToOwned::to_owned(&a),
    |                                ~~~~~~~~~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
    |
748 |                         value: ToOwned::to_owned(&a),
    |                                ~~~~~~~~~~~~~~~~~~~~~
```
  • Loading branch information
baloo authored Jan 3, 2023
1 parent 1f1dd1a commit 953ad23
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
6 changes: 3 additions & 3 deletions der/src/asn1/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for AnyRef<'a> {
type Owned = Any;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
Any {
tag: self.tag(),
value: BytesOwned::from(self.value),
Expand All @@ -287,15 +287,15 @@ mod allocating {

impl OwnedToRef for Any {
type Borrowed<'a> = AnyRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
self.into()
}
}

impl Any {
/// Is this value an ASN.1 `NULL` value?
pub fn is_null(&self) -> bool {
self.to_ref() == AnyRef::NULL
self.owned_to_ref() == AnyRef::NULL
}
}
}
4 changes: 2 additions & 2 deletions der/src/asn1/bit_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for BitStringRef<'a> {
type Owned = BitString;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
BitString {
unused_bits: self.unused_bits,
bit_length: self.bit_length,
Expand All @@ -390,7 +390,7 @@ mod allocating {

impl OwnedToRef for BitString {
type Borrowed<'a> = BitStringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
self.into()
}
}
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/ia5_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ mod allocation {

impl<'a> RefToOwned<'a> for Ia5StringRef<'a> {
type Owned = Ia5String;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
Ia5String {
inner: self.inner.to_owned(),
inner: self.inner.ref_to_owned(),
}
}
}

impl OwnedToRef for Ia5String {
type Borrowed<'a> = Ia5StringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
Ia5StringRef {
inner: self.inner.to_ref(),
inner: self.inner.owned_to_ref(),
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions der/src/asn1/integer/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,17 @@ mod allocating {

impl<'a> RefToOwned<'a> for IntRef<'a> {
type Owned = Int;
fn to_owned(&self) -> Self::Owned {
let inner = self.inner.to_owned();
fn ref_to_owned(&self) -> Self::Owned {
let inner = self.inner.ref_to_owned();

Int { inner }
}
}

impl OwnedToRef for Int {
type Borrowed<'a> = IntRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.to_ref();
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.owned_to_ref();

IntRef { inner }
}
Expand Down Expand Up @@ -384,17 +384,17 @@ mod allocating {

impl<'a> RefToOwned<'a> for UintRef<'a> {
type Owned = Uint;
fn to_owned(&self) -> Self::Owned {
let inner = self.inner.to_owned();
fn ref_to_owned(&self) -> Self::Owned {
let inner = self.inner.ref_to_owned();

Uint { inner }
}
}

impl OwnedToRef for Uint {
type Borrowed<'a> = UintRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.to_ref();
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
let inner = self.inner.owned_to_ref();

UintRef { inner }
}
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/printable_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,18 @@ mod allocation {

impl<'a> RefToOwned<'a> for PrintableStringRef<'a> {
type Owned = PrintableString;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
PrintableString {
inner: self.inner.to_owned(),
inner: self.inner.ref_to_owned(),
}
}
}

impl OwnedToRef for PrintableString {
type Borrowed<'a> = PrintableStringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
PrintableStringRef {
inner: self.inner.to_ref(),
inner: self.inner.owned_to_ref(),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/teletex_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ mod allocation {

impl<'a> RefToOwned<'a> for TeletexStringRef<'a> {
type Owned = TeletexString;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
TeletexString {
inner: self.inner.to_owned(),
inner: self.inner.ref_to_owned(),
}
}
}

impl OwnedToRef for TeletexString {
type Borrowed<'a> = TeletexStringRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
TeletexStringRef {
inner: self.inner.to_ref(),
inner: self.inner.owned_to_ref(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion der/src/bytes_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl From<StrRef<'_>> for BytesOwned {

impl OwnedToRef for BytesOwned {
type Borrowed<'a> = BytesRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
BytesRef {
length: self.length,
inner: self.inner.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion der/src/bytes_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for BytesRef<'a> {
type Owned = BytesOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
BytesOwned::from(*self)
}
}
Expand Down
12 changes: 6 additions & 6 deletions der/src/referenced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub trait OwnedToRef {
Self: 'a;

/// Creates a new object referencing back to the self for storage
fn to_ref(&self) -> Self::Borrowed<'_>;
fn owned_to_ref(&self) -> Self::Borrowed<'_>;
}

/// A trait for cloning a referenced structure and getting owned objects
Expand All @@ -21,7 +21,7 @@ pub trait RefToOwned<'a> {
Self: 'a;

/// Creates a new object taking ownership of the data
fn to_owned(&self) -> Self::Owned;
fn ref_to_owned(&self) -> Self::Owned;
}

impl<T> OwnedToRef for Option<T>
Expand All @@ -30,8 +30,8 @@ where
{
type Borrowed<'a> = Option<T::Borrowed<'a>> where T: 'a;

fn to_ref(&self) -> Self::Borrowed<'_> {
self.as_ref().map(|o| o.to_ref())
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
self.as_ref().map(|o| o.owned_to_ref())
}
}

Expand All @@ -41,7 +41,7 @@ where
T::Owned: OwnedToRef,
{
type Owned = Option<T::Owned>;
fn to_owned(&self) -> Self::Owned {
self.as_ref().map(|o| o.to_owned())
fn ref_to_owned(&self) -> Self::Owned {
self.as_ref().map(|o| o.ref_to_owned())
}
}
2 changes: 1 addition & 1 deletion der/src/str_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl From<StrRef<'_>> for StrOwned {

impl OwnedToRef for StrOwned {
type Borrowed<'a> = StrRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
StrRef {
length: self.length,
inner: self.inner.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion der/src/str_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod allocating {

impl<'a> RefToOwned<'a> for StrRef<'a> {
type Owned = StrOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
StrOwned::from(*self)
}
}
Expand Down
8 changes: 4 additions & 4 deletions spki/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@ mod allocating {

impl<'a> RefToOwned<'a> for AlgorithmIdentifierRef<'a> {
type Owned = AlgorithmIdentifierOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
AlgorithmIdentifier {
oid: self.oid,
parameters: self.parameters.to_owned(),
parameters: self.parameters.ref_to_owned(),
}
}
}

impl OwnedToRef for AlgorithmIdentifierOwned {
type Borrowed<'a> = AlgorithmIdentifierRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
AlgorithmIdentifier {
oid: self.oid,
parameters: self.parameters.to_ref(),
parameters: self.parameters.owned_to_ref(),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions spki/src/spki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ mod allocating {

impl<'a> RefToOwned<'a> for SubjectPublicKeyInfoRef<'a> {
type Owned = SubjectPublicKeyInfoOwned;
fn to_owned(&self) -> Self::Owned {
fn ref_to_owned(&self) -> Self::Owned {
SubjectPublicKeyInfo {
algorithm: self.algorithm.to_owned(),
subject_public_key: self.subject_public_key.to_owned(),
algorithm: self.algorithm.ref_to_owned(),
subject_public_key: self.subject_public_key.ref_to_owned(),
}
}
}

impl OwnedToRef for SubjectPublicKeyInfoOwned {
type Borrowed<'a> = SubjectPublicKeyInfoRef<'a>;
fn to_ref(&self) -> Self::Borrowed<'_> {
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
SubjectPublicKeyInfo {
algorithm: self.algorithm.to_ref(),
subject_public_key: self.subject_public_key.to_ref(),
algorithm: self.algorithm.owned_to_ref(),
subject_public_key: self.subject_public_key.owned_to_ref(),
}
}
}
Expand Down

0 comments on commit 953ad23

Please sign in to comment.