Skip to content

Commit

Permalink
der, spki: rename to_owned method
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 RustCrypto#1 is defined in an impl of the trait `RefToOwned` for the type `AnyRef<'a>`
    = note: candidate RustCrypto#2 is defined in an impl of the trait `ToOwned` for the type `T`
help: disambiguate the associated function for candidate RustCrypto#1
    |
748 |                         value: RefToOwned::to_owned(&a),
    |                                ~~~~~~~~~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate RustCrypto#2
    |
748 |                         value: ToOwned::to_owned(&a),
    |                                ~~~~~~~~~~~~~~~~~~~~~
```
  • Loading branch information
baloo committed Jan 3, 2023
1 parent 1f1dd1a commit 40f62eb
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion 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 Down
2 changes: 1 addition & 1 deletion 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 Down
4 changes: 2 additions & 2 deletions der/src/asn1/ia5_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ 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(),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/integer/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ 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 }
}
Expand Down Expand Up @@ -384,8 +384,8 @@ 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 }
}
Expand Down
4 changes: 2 additions & 2 deletions der/src/asn1/printable_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ 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(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions der/src/asn1/teletex_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ 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(),
}
}
}
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
6 changes: 3 additions & 3 deletions der/src/referenced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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_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
4 changes: 2 additions & 2 deletions spki/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ 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(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions spki/src/spki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ 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(),
}
}
}
Expand Down

0 comments on commit 40f62eb

Please sign in to comment.