spki: add AlgorithmIdentifierRef::to_owned method#796
Closed
baloo wants to merge 2 commits intoRustCrypto:masterfrom
Closed
spki: add AlgorithmIdentifierRef::to_owned method#796baloo wants to merge 2 commits intoRustCrypto:masterfrom
AlgorithmIdentifierRef::to_owned method#796baloo wants to merge 2 commits intoRustCrypto:masterfrom
Conversation
Member
|
Perhaps we can define some traits for this, since we can't use It would be nice to ensure there's always a reciprocal operation ala |
Member
Author
|
I'm pretty bad at naming things, but any opinion? pub trait DerBorrow {
type Borrowed<'b>
where
Self: 'b;
fn der_borrow<'a>(&'a self) -> Self::Borrowed<'a>;
}
pub trait DerToOwned<'a> {
type DerOwned: DerBorrow<Borrowed<'a> = Self>
where
Self: 'a;
fn to_der_owned(&self) -> Self::DerOwned;
}
impl<'a> DerToOwned<'a> for AlgorithmIdentifierRef<'a> {
type DerOwned = AlgorithmIdentifierOwned;
fn to_der_owned(&self) -> Self::DerOwned {
AlgorithmIdentifier {
oid: self.oid,
parameters: self.parameters.map(|p| p.into()),
}
}
}
impl DerBorrow for AlgorithmIdentifierOwned {
type Borrowed<'a> = AlgorithmIdentifierRef<'a>;
fn der_borrow<'a>(&'a self) -> AlgorithmIdentifierRef<'a> {
AlgorithmIdentifier {
oid: self.oid,
parameters: self.parameters.as_ref().map(AnyRef::from),
}
}
}Compiler seems happy. |
Member
|
That looks okay naming aside. Let me think about that for a bit. |
Member
|
Naming wise, for starters, the "borrowed" types are owned |
Member
Author
pub trait OwnedToRef {
type Borrowed<'b>
where
Self: 'b;
fn to_ref<'a>(&'a self) -> Self::Borrowed<'a>;
}
pub trait RefToOwned<'a> {
type Owned: OwnedToRef<Borrowed<'a> = Self>
where
Self: 'a;
fn to_owned(&self) -> Self::Owned;
} |
Member
|
Looking better… maybe |
tarcieri
pushed a commit
that referenced
this pull request
Dec 17, 2022
This introduces the two new traits to go from a ref object to an owned object as discussed in #796
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.