Skip to content

Commit 83b26b3

Browse files
committed
Tags: Add a <Tag>::new() alias for <Tag>::default()
1 parent 4741a0c commit 83b26b3

File tree

8 files changed

+108
-0
lines changed

8 files changed

+108
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- **Properties**: Expose channel mask (only supported for WAV and MPEG for now) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/155))
1111
- **ItemKey**: `InitialKey` mapping for Vorbis Comments ([PR](https://github.com/Serial-ATA/lofty-rs/pull/156))
1212
- **VorbisComments**: `VorbisComments::push` to allow for a non-replacing insertion
13+
- **Tags**: `<Tag>::new()` as an alias for `<Tag>::default()`
1314

1415
### Changed
1516
- **APE**/**ID3v1**/**ID3v2**/**Tag**:

src/ape/tag/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ pub struct ApeTag {
7575
}
7676

7777
impl ApeTag {
78+
/// Create a new empty `ApeTag`
79+
///
80+
/// # Examples
81+
///
82+
/// ```rust
83+
/// use lofty::ape::ApeTag;
84+
/// use lofty::TagExt;
85+
///
86+
/// let ape_tag = ApeTag::new();
87+
/// assert!(ape_tag.is_empty());
88+
/// ```
89+
pub fn new() -> Self {
90+
Self::default()
91+
}
92+
7893
/// Get an [`ApeItem`] by key
7994
///
8095
/// NOTE: While `APE` items are supposed to be case-sensitive,

src/id3/v1/tag.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ pub struct ID3v1Tag {
8989
pub genre: Option<u8>,
9090
}
9191

92+
impl ID3v1Tag {
93+
/// Create a new empty `ID3v1Tag`
94+
///
95+
/// # Examples
96+
///
97+
/// ```rust
98+
/// use lofty::id3::v1::ID3v1Tag;
99+
/// use lofty::TagExt;
100+
///
101+
/// let id3v1_tag = ID3v1Tag::new();
102+
/// assert!(id3v1_tag.is_empty());
103+
/// ```
104+
pub fn new() -> Self {
105+
Self::default()
106+
}
107+
}
108+
92109
impl Accessor for ID3v1Tag {
93110
impl_accessor!(title, artist, album,);
94111

src/id3/v2/tag.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ impl Default for ID3v2Tag {
132132
}
133133

134134
impl ID3v2Tag {
135+
/// Create a new empty `ID3v2Tag`
136+
///
137+
/// # Examples
138+
///
139+
/// ```rust
140+
/// use lofty::id3::v2::ID3v2Tag;
141+
/// use lofty::TagExt;
142+
///
143+
/// let id3v2_tag = ID3v2Tag::new();
144+
/// assert!(id3v2_tag.is_empty());
145+
/// ```
146+
pub fn new() -> Self {
147+
Self::default()
148+
}
149+
135150
/// Returns the [`ID3v2TagFlags`]
136151
pub fn flags(&self) -> &ID3v2TagFlags {
137152
&self.flags

src/iff/aiff/tag.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ impl Accessor for AIFFTextChunks {
120120
}
121121

122122
impl AIFFTextChunks {
123+
/// Create a new empty `AIFFTextChunks`
124+
///
125+
/// # Examples
126+
///
127+
/// ```rust
128+
/// use lofty::iff::aiff::AIFFTextChunks;
129+
/// use lofty::TagExt;
130+
///
131+
/// let aiff_tag = AIFFTextChunks::new();
132+
/// assert!(aiff_tag.is_empty());
133+
/// ```
134+
pub fn new() -> Self {
135+
Self::default()
136+
}
137+
123138
/// Returns the copyright message
124139
pub fn copyright(&self) -> Option<&str> {
125140
self.copyright.as_deref()

src/iff/wav/tag/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ pub struct RIFFInfoList {
4949
}
5050

5151
impl RIFFInfoList {
52+
/// Create a new empty `RIFFInfoList`
53+
///
54+
/// # Examples
55+
///
56+
/// ```rust
57+
/// use lofty::iff::wav::RIFFInfoList;
58+
/// use lofty::TagExt;
59+
///
60+
/// let riff_info_tag = RIFFInfoList::new();
61+
/// assert!(riff_info_tag.is_empty());
62+
/// ```
63+
pub fn new() -> Self {
64+
Self::default()
65+
}
66+
5267
/// Get an item by key
5368
pub fn get(&self, key: &str) -> Option<&str> {
5469
self.items

src/mp4/ilst/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ pub struct Ilst {
8484
}
8585

8686
impl Ilst {
87+
/// Create a new empty `Ilst`
88+
///
89+
/// # Examples
90+
///
91+
/// ```rust
92+
/// use lofty::mp4::Ilst;
93+
/// use lofty::TagExt;
94+
///
95+
/// let ilst_tag = Ilst::new();
96+
/// assert!(ilst_tag.is_empty());
97+
/// ```
98+
pub fn new() -> Self {
99+
Self::default()
100+
}
101+
87102
/// Get an item by its [`AtomIdent`]
88103
pub fn atom(&self, ident: &AtomIdent<'_>) -> Option<&Atom<'static>> {
89104
self.atoms.iter().find(|a| &a.ident == ident)

src/ogg/tag.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ pub struct VorbisComments {
5252
}
5353

5454
impl VorbisComments {
55+
/// Create a new empty `VorbisComments`
56+
///
57+
/// # Examples
58+
///
59+
/// ```rust
60+
/// use lofty::ogg::VorbisComments;
61+
/// use lofty::TagExt;
62+
///
63+
/// let vorbis_comments_tag = VorbisComments::new();
64+
/// assert!(vorbis_comments_tag.is_empty());
65+
/// ```
66+
pub fn new() -> Self {
67+
Self::default()
68+
}
69+
5570
/// Returns the vendor string
5671
pub fn vendor(&self) -> &str {
5772
&self.vendor

0 commit comments

Comments
 (0)