Skip to content

Commit 953ad23

Browse files
authored
der, spki: rename to_owned method (RustCrypto#835)
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), | ~~~~~~~~~~~~~~~~~~~~~ ```
1 parent 1f1dd1a commit 953ad23

13 files changed

+45
-45
lines changed

der/src/asn1/any.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ mod allocating {
277277

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

288288
impl OwnedToRef for Any {
289289
type Borrowed<'a> = AnyRef<'a>;
290-
fn to_ref(&self) -> Self::Borrowed<'_> {
290+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
291291
self.into()
292292
}
293293
}
294294

295295
impl Any {
296296
/// Is this value an ASN.1 `NULL` value?
297297
pub fn is_null(&self) -> bool {
298-
self.to_ref() == AnyRef::NULL
298+
self.owned_to_ref() == AnyRef::NULL
299299
}
300300
}
301301
}

der/src/asn1/bit_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ mod allocating {
379379

380380
impl<'a> RefToOwned<'a> for BitStringRef<'a> {
381381
type Owned = BitString;
382-
fn to_owned(&self) -> Self::Owned {
382+
fn ref_to_owned(&self) -> Self::Owned {
383383
BitString {
384384
unused_bits: self.unused_bits,
385385
bit_length: self.bit_length,
@@ -390,7 +390,7 @@ mod allocating {
390390

391391
impl OwnedToRef for BitString {
392392
type Borrowed<'a> = BitStringRef<'a>;
393-
fn to_ref(&self) -> Self::Borrowed<'_> {
393+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
394394
self.into()
395395
}
396396
}

der/src/asn1/ia5_string.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,18 @@ mod allocation {
150150

151151
impl<'a> RefToOwned<'a> for Ia5StringRef<'a> {
152152
type Owned = Ia5String;
153-
fn to_owned(&self) -> Self::Owned {
153+
fn ref_to_owned(&self) -> Self::Owned {
154154
Ia5String {
155-
inner: self.inner.to_owned(),
155+
inner: self.inner.ref_to_owned(),
156156
}
157157
}
158158
}
159159

160160
impl OwnedToRef for Ia5String {
161161
type Borrowed<'a> = Ia5StringRef<'a>;
162-
fn to_ref(&self) -> Self::Borrowed<'_> {
162+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
163163
Ia5StringRef {
164-
inner: self.inner.to_ref(),
164+
inner: self.inner.owned_to_ref(),
165165
}
166166
}
167167
}

der/src/asn1/integer/bigint.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,17 @@ mod allocating {
277277

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

283283
Int { inner }
284284
}
285285
}
286286

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

292292
IntRef { inner }
293293
}
@@ -384,17 +384,17 @@ mod allocating {
384384

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

390390
Uint { inner }
391391
}
392392
}
393393

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

399399
UintRef { inner }
400400
}

der/src/asn1/printable_string.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,18 @@ mod allocation {
221221

222222
impl<'a> RefToOwned<'a> for PrintableStringRef<'a> {
223223
type Owned = PrintableString;
224-
fn to_owned(&self) -> Self::Owned {
224+
fn ref_to_owned(&self) -> Self::Owned {
225225
PrintableString {
226-
inner: self.inner.to_owned(),
226+
inner: self.inner.ref_to_owned(),
227227
}
228228
}
229229
}
230230

231231
impl OwnedToRef for PrintableString {
232232
type Borrowed<'a> = PrintableStringRef<'a>;
233-
fn to_ref(&self) -> Self::Borrowed<'_> {
233+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
234234
PrintableStringRef {
235-
inner: self.inner.to_ref(),
235+
inner: self.inner.owned_to_ref(),
236236
}
237237
}
238238
}

der/src/asn1/teletex_string.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,18 @@ mod allocation {
179179

180180
impl<'a> RefToOwned<'a> for TeletexStringRef<'a> {
181181
type Owned = TeletexString;
182-
fn to_owned(&self) -> Self::Owned {
182+
fn ref_to_owned(&self) -> Self::Owned {
183183
TeletexString {
184-
inner: self.inner.to_owned(),
184+
inner: self.inner.ref_to_owned(),
185185
}
186186
}
187187
}
188188

189189
impl OwnedToRef for TeletexString {
190190
type Borrowed<'a> = TeletexStringRef<'a>;
191-
fn to_ref(&self) -> Self::Borrowed<'_> {
191+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
192192
TeletexStringRef {
193-
inner: self.inner.to_ref(),
193+
inner: self.inner.owned_to_ref(),
194194
}
195195
}
196196
}

der/src/bytes_owned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl From<StrRef<'_>> for BytesOwned {
9797

9898
impl OwnedToRef for BytesOwned {
9999
type Borrowed<'a> = BytesRef<'a>;
100-
fn to_ref(&self) -> Self::Borrowed<'_> {
100+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
101101
BytesRef {
102102
length: self.length,
103103
inner: self.inner.as_ref(),

der/src/bytes_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ mod allocating {
145145

146146
impl<'a> RefToOwned<'a> for BytesRef<'a> {
147147
type Owned = BytesOwned;
148-
fn to_owned(&self) -> Self::Owned {
148+
fn ref_to_owned(&self) -> Self::Owned {
149149
BytesOwned::from(*self)
150150
}
151151
}

der/src/referenced.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub trait OwnedToRef {
88
Self: 'a;
99

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

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

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

2727
impl<T> OwnedToRef for Option<T>
@@ -30,8 +30,8 @@ where
3030
{
3131
type Borrowed<'a> = Option<T::Borrowed<'a>> where T: 'a;
3232

33-
fn to_ref(&self) -> Self::Borrowed<'_> {
34-
self.as_ref().map(|o| o.to_ref())
33+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
34+
self.as_ref().map(|o| o.owned_to_ref())
3535
}
3636
}
3737

@@ -41,7 +41,7 @@ where
4141
T::Owned: OwnedToRef,
4242
{
4343
type Owned = Option<T::Owned>;
44-
fn to_owned(&self) -> Self::Owned {
45-
self.as_ref().map(|o| o.to_owned())
44+
fn ref_to_owned(&self) -> Self::Owned {
45+
self.as_ref().map(|o| o.ref_to_owned())
4646
}
4747
}

der/src/str_owned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl From<StrRef<'_>> for StrOwned {
9696

9797
impl OwnedToRef for StrOwned {
9898
type Borrowed<'a> = StrRef<'a>;
99-
fn to_ref(&self) -> Self::Borrowed<'_> {
99+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
100100
StrRef {
101101
length: self.length,
102102
inner: self.inner.as_ref(),

der/src/str_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod allocating {
8585

8686
impl<'a> RefToOwned<'a> for StrRef<'a> {
8787
type Owned = StrOwned;
88-
fn to_owned(&self) -> Self::Owned {
88+
fn ref_to_owned(&self) -> Self::Owned {
8989
StrOwned::from(*self)
9090
}
9191
}

spki/src/algorithm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,20 @@ mod allocating {
171171

172172
impl<'a> RefToOwned<'a> for AlgorithmIdentifierRef<'a> {
173173
type Owned = AlgorithmIdentifierOwned;
174-
fn to_owned(&self) -> Self::Owned {
174+
fn ref_to_owned(&self) -> Self::Owned {
175175
AlgorithmIdentifier {
176176
oid: self.oid,
177-
parameters: self.parameters.to_owned(),
177+
parameters: self.parameters.ref_to_owned(),
178178
}
179179
}
180180
}
181181

182182
impl OwnedToRef for AlgorithmIdentifierOwned {
183183
type Borrowed<'a> = AlgorithmIdentifierRef<'a>;
184-
fn to_ref(&self) -> Self::Borrowed<'_> {
184+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
185185
AlgorithmIdentifier {
186186
oid: self.oid,
187-
parameters: self.parameters.to_ref(),
187+
parameters: self.parameters.owned_to_ref(),
188188
}
189189
}
190190
}

spki/src/spki.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,20 @@ mod allocating {
193193

194194
impl<'a> RefToOwned<'a> for SubjectPublicKeyInfoRef<'a> {
195195
type Owned = SubjectPublicKeyInfoOwned;
196-
fn to_owned(&self) -> Self::Owned {
196+
fn ref_to_owned(&self) -> Self::Owned {
197197
SubjectPublicKeyInfo {
198-
algorithm: self.algorithm.to_owned(),
199-
subject_public_key: self.subject_public_key.to_owned(),
198+
algorithm: self.algorithm.ref_to_owned(),
199+
subject_public_key: self.subject_public_key.ref_to_owned(),
200200
}
201201
}
202202
}
203203

204204
impl OwnedToRef for SubjectPublicKeyInfoOwned {
205205
type Borrowed<'a> = SubjectPublicKeyInfoRef<'a>;
206-
fn to_ref(&self) -> Self::Borrowed<'_> {
206+
fn owned_to_ref(&self) -> Self::Borrowed<'_> {
207207
SubjectPublicKeyInfo {
208-
algorithm: self.algorithm.to_ref(),
209-
subject_public_key: self.subject_public_key.to_ref(),
208+
algorithm: self.algorithm.owned_to_ref(),
209+
subject_public_key: self.subject_public_key.owned_to_ref(),
210210
}
211211
}
212212
}

0 commit comments

Comments
 (0)