Skip to content

Commit 368f048

Browse files
committed
docs: Improve tag conversion docs
1 parent bcfc6ad commit 368f048

File tree

6 files changed

+72
-32
lines changed

6 files changed

+72
-32
lines changed

lofty/src/ape/tag/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ macro_rules! impl_accessor {
6161
/// a normal [`ItemValue`](crate::tag::ItemValue) unlike other formats.
6262
///
6363
/// Pictures are stored as [`ItemValue::Binary`](crate::tag::ItemValue::Binary), and can be converted with
64-
/// [`Picture::from_ape_bytes`](crate::picture::Picture::from_ape_bytes). For the appropriate item keys, see
65-
/// [`APE_PICTURE_TYPES`](crate::ape::APE_PICTURE_TYPES).
64+
/// [`Picture::from_ape_bytes()`]. For the appropriate item keys, see [`APE_PICTURE_TYPES`].
6665
///
6766
/// ## Conversions
6867
///
@@ -72,8 +71,20 @@ macro_rules! impl_accessor {
7271
///
7372
/// ### From `Tag`
7473
///
74+
/// Converting [`Tag`]s into `ApeTag` is *mostly* seamless.
75+
///
76+
/// #### Items
77+
///
78+
/// As long at the [`ItemKey`] has a mapping for APE, it can be converted to an [`ApeItem`].
79+
///
80+
/// #### Pictures
81+
///
7582
/// When converting pictures, any of type [`PictureType::Undefined`](crate::picture::PictureType::Undefined) will be discarded.
76-
/// For items, see [`ApeItem::new`].
83+
/// Since APE doesn't have dedicated item types for pictures like other formats (e.g. [Id3v2Tag]), pictures
84+
/// **must** be disambiguated by their [`PictureType`](crate::picture::PictureType).
85+
///
86+
/// [`Picture::from_ape_bytes()`]: crate::picture::Picture::from_ape_bytes
87+
/// [`APE_PICTURE_TYPES`]: crate::ape::APE_PICTURE_TYPES
7788
#[derive(Default, Debug, PartialEq, Eq, Clone)]
7889
#[tag(
7990
description = "An `APE` tag",

lofty/src/id3/v1/tag.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,24 @@ macro_rules! impl_accessor {
5656
/// * `comment` -> [`ItemKey::Comment`]
5757
/// * `track_number` -> [`ItemKey::TrackNumber`]
5858
/// * `genre` -> [`ItemKey::Genre`] (As long as the genre is a valid index into [`GENRES`])
59-
///
59+
/// * Note that [`ItemKey::Genre`] will contain the *string* at [`GENRES`]\[index\], not the index.
6060
///
6161
/// ### From `Tag`
6262
///
63+
/// #### Items
64+
///
6365
/// All of the [`ItemKey`]s referenced in the conversion to [`Tag`] will be checked.
6466
///
6567
/// The values will be used as-is, with two exceptions:
6668
///
6769
/// * [`ItemKey::TrackNumber`] - Will only be used if the value can be parsed as a `u8`
6870
/// * [`ItemKey::Genre`] - Will only be used if:
71+
/// * [`GENRES`] contains the string
72+
/// * **OR** The [`ItemValue`](crate::ItemValue) can be parsed into a `u8` ***and*** it is a valid index into [`GENRES`]
73+
///
74+
/// #### Pictures
6975
///
70-
/// [`GENRES`] contains the string **OR** The [`ItemValue`](crate::ItemValue) can be parsed into
71-
/// a `u8` ***and*** it is a valid index into [`GENRES`]
76+
/// Pictures will be discarded, as they aren't supported in this format.
7277
#[derive(Default, Debug, PartialEq, Eq, Clone)]
7378
#[tag(
7479
description = "An ID3v1 tag",

lofty/src/id3/v2/tag.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,33 @@ macro_rules! impl_accessor {
7676
///
7777
/// In the [`Accessor`] methods, these values have the separators (`\0`) replaced with `"/"` for convenience.
7878
///
79+
/// ## Special Frames
80+
///
81+
/// ID3v2 has `GEOB` and `SYLT` frames, which are not parsed by default, instead storing them as [`FrameType::Binary`].
82+
/// They can easily be parsed with [`GeneralEncapsulatedObject::parse`](crate::id3::v2::GeneralEncapsulatedObject::parse)
83+
/// and [`SynchronizedText::parse`](crate::id3::v2::SynchronizedTextFrame::parse) respectively, and converted back to binary with
84+
/// [`GeneralEncapsulatedObject::as_bytes`](crate::id3::v2::GeneralEncapsulatedObject::as_bytes) and
85+
/// [`SynchronizedText::as_bytes`](crate::id3::v2::SynchronizedTextFrame::as_bytes) for writing.
86+
///
7987
/// ## Conversions
8088
///
81-
/// ⚠ **Warnings** ⚠
89+
/// ### To `Tag`
90+
///
91+
/// * TXXX/WXXX
92+
/// * These frames map to [`ItemKey`] by their description, rather than their frame ID (e.g. `TXXX:REPLAYGAIN_ALBUM_GAIN` maps to [`ItemKey::ReplayGainAlbumGain`]).
93+
/// * Anything without a mapping will be discarded.
94+
/// * POPM - These frames will be stored as a raw [`ItemValue::Binary`] value under the [`ItemKey::Popularimeter`] key.
8295
///
8396
/// ### From `Tag`
8497
///
8598
/// When converting from a [`Tag`] to an `Id3v2Tag`, some frames may need editing.
8699
///
87100
/// * [`ItemKey::Comment`] and [`ItemKey::Lyrics`] - Unlike a normal text frame, these require a language and description.
88101
/// * If these values aren't specified in the [`TagItem`], it will be filled in with (possibly incorrect) defaults.
89-
/// * `language` - Unknown and set to "XXX"
102+
/// * `language` - Set to [`UNKNOWN_LANGUAGE`]
90103
/// * `description` - Left empty, which is invalid if there are more than one of these frames. These frames can only be identified
91104
/// by their descriptions, and as such they are expected to be unique for each.
92105
/// * See [`CommentFrame`] and [`UnsynchronizedTextFrame`] respectively.
93-
///
94-
/// ### To `Tag`
95-
///
96-
/// * TXXX/WXXX - These frames will be stored as an [`ItemKey`] by their description. Some variants exist
97-
/// for these descriptions, such as [`ItemKey::ReplayGainAlbumGain`]. Anything without a mapping will
98-
/// be discarded.
99-
/// * POPM - These frames will be stored as a raw [`ItemValue::Binary`] value under the [`ItemKey::Popularimeter`] key.
100-
///
101-
/// ## Special Frames
102-
///
103-
/// ID3v2 has `GEOB` and `SYLT` frames, which are not parsed by default, instead storing them as [`FrameType::Binary`].
104-
/// They can easily be parsed with [`GeneralEncapsulatedObject::parse`](crate::id3::v2::GeneralEncapsulatedObject::parse)
105-
/// and [`SynchronizedText::parse`](crate::id3::v2::SynchronizedTextFrame::parse) respectively, and converted back to binary with
106-
/// [`GeneralEncapsulatedObject::as_bytes`](crate::id3::v2::GeneralEncapsulatedObject::as_bytes) and
107-
/// [`SynchronizedText::as_bytes`](crate::id3::v2::SynchronizedTextFrame::as_bytes) for writing.
108106
#[derive(PartialEq, Eq, Debug, Clone)]
109107
#[tag(
110108
description = "An `ID3v2` tag",

lofty/src/iff/wav/tag/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ macro_rules! impl_accessor {
4343
///
4444
/// ### From `Tag`
4545
///
46-
/// When converting a [`TagItem`], it must have a value other than [`ItemValue::Binary`](crate::ItemValue::Binary)
46+
/// #### Items
47+
///
48+
/// When converting a [`TagItem`], the only conditions are that:
49+
///
50+
/// * It has an [`ItemKey`] mapping
51+
/// * It has a value of [`ItemValue::Text`](crate::ItemValue::Text) or [`ItemValue::Locator`](crate::ItemValue::Locator)
52+
///
53+
/// #### Pictures
54+
///
55+
/// Pictures will be discarded, as they aren't supported in this format.
4756
#[derive(Default, Debug, PartialEq, Eq, Clone)]
4857
#[tag(description = "A RIFF INFO LIST", supported_formats(Wav))]
4958
pub struct RiffInfoList {

lofty/src/mp4/ilst/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,25 @@ macro_rules! impl_flag_accessors {
101101
///
102102
/// ### To `Tag`
103103
///
104-
/// When converting to [`Tag`], only atoms with a value of [`AtomData::UTF8`] and [`AtomData::UTF16`],
105-
/// with the exception of the `trkn` and `disk` atoms, as well as pictures, will be preserved.
104+
/// For an [`Atom`] to be converted it must:
106105
///
107-
/// Do note, all pictures will be [`PictureType::Other`](crate::PictureType::Other)
106+
/// * Have a value of [`AtomData::UTF8`] and [`AtomData::UTF16`]
107+
/// * **OR** be a `trkn`/`disk` atom
108+
/// * **OR** be a `covr` atom
109+
///
110+
/// Note that all pictures will be [`PictureType::Other`].
108111
///
109112
/// ### From `Tag`
110113
///
111-
/// When converting from [`Tag`], only items with a value of [`ItemValue::Text`](crate::ItemValue::Text), as
112-
/// well as pictures, will be preserved.
114+
/// #### Items
115+
///
116+
/// For a [`TagItem`] to be converted, it must have a value of [`ItemValue::Text`].
117+
///
118+
/// An attempt will be made to create the `TrackNumber/TrackTotal` (trkn) and `DiscNumber/DiscTotal` (disk) atoms.
119+
///
120+
/// #### Pictures
113121
///
114-
/// An attempt will be made to create the `TrackNumber/TrackTotal` (trkn) and `DiscNumber/DiscTotal` (disk) pairs.
122+
/// [`Picture`]s will also be preserved, but their [`PictureType`] will be overwritten with [`PictureType::Other`].
115123
#[derive(Default, PartialEq, Debug, Clone)]
116124
#[tag(description = "An MP4 ilst atom", supported_formats(Mp4))]
117125
pub struct Ilst {

lofty/src/ogg/tag.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,26 @@ macro_rules! impl_accessor {
4444
///
4545
/// ### To `Tag`
4646
///
47-
/// All items will be converted to a [`TagItem`], with all unknown keys being stored with [`ItemKey::Unknown`].
47+
/// All items without an [`ItemKey`] mapping will be discarded.
4848
///
4949
/// In order to preserve the vendor string, a required part of the OGG formats, it will simply be inserted as
5050
/// [`ItemKey::EncoderSoftware`], given an item with this key does not already exist.
5151
///
5252
/// ### From `Tag`
5353
///
54+
/// #### Items
55+
///
56+
/// When converting a [`TagItem`], the only conditions are that:
57+
///
58+
/// * It has an [`ItemKey`] mapping
59+
/// * It has a value of [`ItemValue::Text`] or [`ItemValue::Locator`]
60+
///
5461
/// If a [`TagItem`] with the key [`ItemKey::EncoderSoftware`] is available, it will be taken and
5562
/// used for the vendor string.
5663
///
57-
/// When converting [Picture]s, they will first be passed through [`PictureInformation::from_picture`].
64+
/// #### Pictures
65+
///
66+
/// When converting [`Picture`]s, they will first be passed through [`PictureInformation::from_picture()`].
5867
/// If the information is available, it will be used. Otherwise, the picture will be stored with zeroed out
5968
/// [`PictureInformation`].
6069
#[derive(Default, PartialEq, Eq, Debug, Clone)]

0 commit comments

Comments
 (0)