Skip to content

spki: add AlgorithmIdentifierRef::to_owned method - #796

Closed
baloo wants to merge 2 commits into
RustCrypto:masterfrom
baloo:baloo/spki/algorithm-identifer.owned
Closed

spki: add AlgorithmIdentifierRef::to_owned method#796
baloo wants to merge 2 commits into
RustCrypto:masterfrom
baloo:baloo/spki/algorithm-identifer.owned

Conversation

@baloo

Copy link
Copy Markdown
Member

No description provided.

@tarcieri

Copy link
Copy Markdown
Member

Perhaps we can define some traits for this, since we can't use std::borrow::ToOwned (since this isn't a reference conversion).

It would be nice to ensure there's always a reciprocal operation ala std::borrow::Borrow.

@baloo

Copy link
Copy Markdown
MemberAuthor

I'm pretty bad at naming things, but any opinion?

pubtraitDerBorrow{typeBorrowed<'b>whereSelf:'b;fnder_borrow<'a>(&'aself) -> Self::Borrowed<'a>;}pubtraitDerToOwned<'a>{typeDerOwned:DerBorrow<Borrowed<'a> = Self>whereSelf:'a;fnto_der_owned(&self) -> Self::DerOwned;}impl<'a>DerToOwned<'a>forAlgorithmIdentifierRef<'a>{typeDerOwned = AlgorithmIdentifierOwned;fnto_der_owned(&self) -> Self::DerOwned{AlgorithmIdentifier{oid:self.oid,parameters:self.parameters.map(|p| p.into()),}}}implDerBorrowforAlgorithmIdentifierOwned{typeBorrowed<'a> = AlgorithmIdentifierRef<'a>;fnder_borrow<'a>(&'aself) -> AlgorithmIdentifierRef<'a>{AlgorithmIdentifier{oid:self.oid,parameters:self.parameters.as_ref().map(AnyRef::from),}}}

Compiler seems happy.

@tarcieri

Copy link
Copy Markdown
Member

That looks okay naming aside. Let me think about that for a bit.

@tarcieri

Copy link
Copy Markdown
Member

Naming wise, for starters, the "borrowed" types are owned *Ref types, so perhaps ToRef instead of ToBorrowed?

@baloo

baloo commented Dec 14, 2022

Copy link
Copy Markdown
MemberAuthor
pubtraitOwnedToRef{typeBorrowed<'b>whereSelf:'b;fnto_ref<'a>(&'aself) -> Self::Borrowed<'a>;}pubtraitRefToOwned<'a>{typeOwned:OwnedToRef<Borrowed<'a> = Self>whereSelf:'a;fnto_owned(&self) -> Self::Owned;}

@tarcieri

Copy link
Copy Markdown
Member

Looking better… maybe RefToOwned and OwnedToRef?

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
@baloo
baloo deleted the baloo/spki/algorithm-identifer.owned branch December 18, 2022 03:18
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@baloo@tarcieri