Skip to content

Commit 3fb883b

Browse files
authored
der: document RefToOwned and OwnedToRef (#1498)
1 parent 074edb4 commit 3fb883b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

der/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@
291291
//! # }
292292
//! ```
293293
//!
294+
//! ## Owned vs Borrowed
295+
//!
296+
//! This crate exposes owned and borrowed objects for representing the same structure.
297+
//!
298+
//! [`RefToOwned`] and [`OwnedToRef`] are provided to convert objects from one to the other.
299+
//!
294300
//! # See also
295301
//! For more information about ASN.1 DER we recommend the following guides:
296302
//!
@@ -322,6 +328,8 @@
322328
//! [`UintRef`]: asn1::UintRef
323329
//! [`UtcTime`]: asn1::UtcTime
324330
//! [`Utf8StringRef`]: asn1::Utf8StringRef
331+
//! [`RefToOwned`]: referenced::RefToOwned
332+
//! [`OwnedToRef`]: referenced::OwnedToRef
325333
326334
#[cfg(feature = "alloc")]
327335
#[allow(unused_imports)]

der/src/referenced.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
//! A module for working with referenced data.
22
33
/// A trait for borrowing data from an owned struct
4+
///
5+
/// This converts an object owning the data to one that will borrowing the content.
6+
/// The newly created object lifetime will be tied to the object owning the data.
7+
///
8+
/// This is similar to [`alloc::borrow::Borrow`] or [`core::convert::AsRef`] but this returns
9+
/// an owned structure that references directly the backing slices instead of borrowing
10+
/// the whole structure.
411
pub trait OwnedToRef {
512
/// The resulting type referencing back to Self
613
type Borrowed<'a>
@@ -13,7 +20,10 @@ pub trait OwnedToRef {
1320

1421
/// A trait for cloning a referenced structure and getting owned objects
1522
///
16-
/// This is the pendant to [`OwnedToRef`]
23+
/// This is the pendant to [`OwnedToRef`].
24+
///
25+
/// This converts an object borrowing data to one that will copy the data over and
26+
/// own the content.
1727
pub trait RefToOwned<'a> {
1828
/// The resulting type after obtaining ownership.
1929
type Owned: OwnedToRef<Borrowed<'a> = Self>

spki/src/spki.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ use crate::{fingerprint, FingerprintBytes};
2121
use der::pem::PemLabel;
2222

2323
/// [`SubjectPublicKeyInfo`] with [`AnyRef`] algorithm parameters, and [`BitStringRef`] params.
24+
///
25+
/// This is the borrowing-pendant to [`SubjectPublicKeyInfoOwned`].
2426
pub type SubjectPublicKeyInfoRef<'a> = SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>;
2527

2628
/// [`SubjectPublicKeyInfo`] with [`Any`] algorithm parameters, and [`BitString`] params.
29+
///
30+
/// This is the owning-pendant to [`SubjectPublicKeyInfoRef`].
2731
#[cfg(feature = "alloc")]
2832
pub type SubjectPublicKeyInfoOwned = SubjectPublicKeyInfo<Any, BitString>;
2933

0 commit comments

Comments
 (0)