From 751f5ca06ffd51570f8094fd6fee603cb04f71ff Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sun, 15 Jan 2023 11:05:02 +0100 Subject: [PATCH] Add conversions between borrowed/owned data --- src/id3/v2/frame/id.rs | 11 ++++++++++- src/mp4/atom_info.rs | 10 ++++++---- src/mp4/ilst/atom.rs | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/id3/v2/frame/id.rs b/src/id3/v2/frame/id.rs index c243eeea..2331acfb 100644 --- a/src/id3/v2/frame/id.rs +++ b/src/id3/v2/frame/id.rs @@ -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())), diff --git a/src/mp4/atom_info.rs b/src/mp4/atom_info.rs index ac51c048..071996e8 100644 --- a/src/mp4/atom_info.rs +++ b/src/mp4/atom_info.rs @@ -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 { diff --git a/src/mp4/ilst/atom.rs b/src/mp4/ilst/atom.rs index a080230b..0a1d4165 100644 --- a/src/mp4/ilst/atom.rs +++ b/src/mp4/ilst/atom.rs @@ -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`]