mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 06:32:33 +00:00
Add conversions between borrowed/owned data
This commit is contained in:
parent
cff5d8fc6b
commit
751f5ca06f
3 changed files with 18 additions and 7 deletions
|
@ -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())),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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`]
|
||||
|
|
Loading…
Reference in a new issue