Add conversions between borrowed/owned data

This commit is contained in:
Uwe Klotz 2023-01-15 11:05:02 +01:00 committed by Alex
parent cff5d8fc6b
commit 751f5ca06f
3 changed files with 18 additions and 7 deletions

View file

@ -59,7 +59,16 @@ impl<'a> FrameID<'a> {
Ok(())
}
pub(super) fn into_owned(self) -> FrameID<'static> {
/// Obtains a borrowed instance
pub fn as_borrowed(&'a self) -> Self {
match self {
Self::Valid(inner) => Self::Valid(Cow::Borrowed(inner)),
Self::Outdated(inner) => Self::Outdated(Cow::Borrowed(inner)),
}
}
/// Obtains an owned instance
pub fn into_owned(self) -> FrameID<'static> {
match self {
Self::Valid(inner) => FrameID::Valid(Cow::Owned(inner.into_owned())),
Self::Outdated(inner) => FrameID::Outdated(Cow::Owned(inner.into_owned())),

View file

@ -35,17 +35,19 @@ pub enum AtomIdent<'a> {
}
impl<'a> AtomIdent<'a> {
pub(crate) fn as_borrowed(&'a self) -> Self {
/// Obtains a borrowed instance
pub fn as_borrowed(&'a self) -> Self {
match self {
Self::Fourcc(fourcc) => AtomIdent::Fourcc(*fourcc),
Self::Freeform { mean, name } => AtomIdent::Freeform {
Self::Fourcc(fourcc) => Self::Fourcc(*fourcc),
Self::Freeform { mean, name } => Self::Freeform {
mean: Cow::Borrowed(&mean),
name: Cow::Borrowed(&name),
},
}
}
pub(crate) fn into_owned(self) -> AtomIdent<'static> {
/// Obtains an owned instance
pub fn into_owned(self) -> AtomIdent<'static> {
match self {
Self::Fourcc(fourcc) => AtomIdent::Fourcc(fourcc),
Self::Freeform { mean, name } => AtomIdent::Freeform {

View file

@ -109,8 +109,8 @@ impl<'a> Atom<'a> {
}
/// Returns the atom's [`AtomIdent`]
pub fn ident(&self) -> AtomIdent<'_> {
self.ident.as_borrowed()
pub fn ident(&self) -> &AtomIdent<'_> {
&self.ident
}
/// Returns the atom's [`AtomData`]