mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 14:57:17 +00:00
ID3v2: Implement Into<Cow<'_, str>>
for FrameId
This makes it possible to use `FrameId`s in `Frame::new`. It's not much less annoying to create frames using constant IDs.
This commit is contained in:
parent
a7af2f777c
commit
5164ba3862
1 changed files with 17 additions and 0 deletions
|
@ -5,6 +5,8 @@ use crate::tag::item::ItemKey;
|
|||
use crate::tag::TagType;
|
||||
|
||||
/// An `ID3v2` frame ID
|
||||
///
|
||||
/// ⚠ WARNING ⚠: Be very careful when constructing this by hand. It is recommended to use [`FrameId::new`].
|
||||
#[derive(PartialEq, Clone, Debug, Eq, Hash)]
|
||||
pub enum FrameId<'a> {
|
||||
/// A valid `ID3v2.3/4` frame
|
||||
|
@ -20,6 +22,8 @@ pub enum FrameId<'a> {
|
|||
impl<'a> FrameId<'a> {
|
||||
/// Attempts to create a `FrameId` from an ID string
|
||||
///
|
||||
/// NOTE: This will not upgrade IDs, for that behavior use [`Frame::new`](crate::id3::v2::Frame::new).
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * `id` contains invalid characters (must be 'A'..='Z' and '0'..='9')
|
||||
|
@ -79,6 +83,19 @@ impl<'a> FrameId<'a> {
|
|||
Self::Outdated(inner) => FrameId::Outdated(Cow::Owned(inner.into_owned())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes the [`FrameId`], returning the inner value
|
||||
pub fn into_inner(self) -> Cow<'a, str> {
|
||||
match self {
|
||||
FrameId::Valid(v) | FrameId::Outdated(v) => v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Into<Cow<'a, str>> for FrameId<'a> {
|
||||
fn into(self) -> Cow<'a, str> {
|
||||
self.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a ItemKey> for FrameId<'a> {
|
||||
|
|
Loading…
Add table
Reference in a new issue