Skip to content

Commit 533cd7d

Browse files
uklotzdeSerial-ATA
authored andcommitted
Renaming: rejoin -> merge
1 parent 2132d01 commit 533cd7d

File tree

10 files changed

+40
-36
lines changed

10 files changed

+40
-36
lines changed

src/ape/tag/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::ape::tag::item::{ApeItem, ApeItemRef};
66
use crate::error::{LoftyError, Result};
77
use crate::tag::item::{ItemKey, ItemValue, TagItem};
88
use crate::tag::{Tag, TagType};
9-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
9+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
1010

1111
use std::borrow::Cow;
1212
use std::convert::TryInto;
@@ -289,7 +289,7 @@ impl TagExt for ApeTag {
289289
}
290290
}
291291

292-
impl SplitAndRejoinTag for ApeTag {
292+
impl SplitAndMergeTag for ApeTag {
293293
fn split_tag(&mut self) -> Tag {
294294
fn split_pair(
295295
content: &str,
@@ -349,7 +349,7 @@ impl SplitAndRejoinTag for ApeTag {
349349
tag
350350
}
351351

352-
fn rejoin_tag(&mut self, tag: Tag) {
352+
fn merge_tag(&mut self, tag: Tag) {
353353
for item in tag.items {
354354
if let Ok(ape_item) = item.try_into() {
355355
self.insert(ape_item)
@@ -377,7 +377,7 @@ impl From<ApeTag> for Tag {
377377
impl From<Tag> for ApeTag {
378378
fn from(input: Tag) -> Self {
379379
let mut ape_tag = Self::default();
380-
ape_tag.rejoin_tag(input);
380+
ape_tag.merge_tag(input);
381381
ape_tag
382382
}
383383
}

src/id3/v1/tag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::error::{LoftyError, Result};
22
use crate::id3::v1::constants::GENRES;
33
use crate::tag::item::{ItemKey, ItemValue, TagItem};
44
use crate::tag::{Tag, TagType};
5-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
5+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
66

77
use std::borrow::Cow;
88
use std::fs::{File, OpenOptions};
@@ -238,7 +238,7 @@ impl TagExt for ID3v1Tag {
238238
}
239239
}
240240

241-
impl SplitAndRejoinTag for ID3v1Tag {
241+
impl SplitAndMergeTag for ID3v1Tag {
242242
fn split_tag(&mut self) -> Tag {
243243
let mut tag = Tag::new(TagType::ID3v1);
244244

@@ -272,7 +272,7 @@ impl SplitAndRejoinTag for ID3v1Tag {
272272
tag
273273
}
274274

275-
fn rejoin_tag(&mut self, tag: Tag) {
275+
fn merge_tag(&mut self, tag: Tag) {
276276
*self = tag.into();
277277
}
278278
}

src/id3/v2/tag.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::id3::v2::items::language_frame::LanguageFrame;
99
use crate::picture::{Picture, PictureType, TOMBSTONE_PICTURE};
1010
use crate::tag::item::{ItemKey, ItemValue, TagItem};
1111
use crate::tag::{Tag, TagType};
12-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
12+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
1313
use crate::util::text::TextEncoding;
1414

1515
use std::borrow::Cow;
@@ -533,7 +533,7 @@ impl TagExt for ID3v2Tag {
533533
}
534534
}
535535

536-
impl SplitAndRejoinTag for ID3v2Tag {
536+
impl SplitAndMergeTag for ID3v2Tag {
537537
fn split_tag(&mut self) -> Tag {
538538
fn split_pair(
539539
content: &str,
@@ -693,7 +693,7 @@ impl SplitAndRejoinTag for ID3v2Tag {
693693
tag
694694
}
695695

696-
fn rejoin_tag(&mut self, mut tag: Tag) {
696+
fn merge_tag(&mut self, mut tag: Tag) {
697697
fn join_items(tag: &mut Tag, key: &ItemKey) -> String {
698698
let mut iter = tag.take_strings(key);
699699

@@ -748,7 +748,7 @@ impl From<ID3v2Tag> for Tag {
748748
impl From<Tag> for ID3v2Tag {
749749
fn from(input: Tag) -> Self {
750750
let mut id3v2_tag = ID3v2Tag::default();
751-
id3v2_tag.rejoin_tag(input);
751+
id3v2_tag.merge_tag(input);
752752
id3v2_tag
753753
}
754754
}

src/iff/aiff/tag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::iff::chunk::Chunks;
33
use crate::macros::err;
44
use crate::tag::item::{ItemKey, ItemValue, TagItem};
55
use crate::tag::{Tag, TagType};
6-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
6+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
77

88
use std::borrow::Cow;
99
use std::convert::TryFrom;
@@ -216,12 +216,12 @@ impl TagExt for AIFFTextChunks {
216216
}
217217
}
218218

219-
impl SplitAndRejoinTag for AIFFTextChunks {
219+
impl SplitAndMergeTag for AIFFTextChunks {
220220
fn split_tag(&mut self) -> Tag {
221221
std::mem::take(self).into()
222222
}
223223

224-
fn rejoin_tag(&mut self, tag: Tag) {
224+
fn merge_tag(&mut self, tag: Tag) {
225225
*self = tag.into();
226226
}
227227
}

src/iff/wav/tag/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod write;
44
use crate::error::{LoftyError, Result};
55
use crate::tag::item::{ItemKey, ItemValue, TagItem};
66
use crate::tag::{Tag, TagType};
7-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
7+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
88

99
use std::borrow::Cow;
1010
use std::fs::{File, OpenOptions};
@@ -211,12 +211,12 @@ impl TagExt for RIFFInfoList {
211211
}
212212
}
213213

214-
impl SplitAndRejoinTag for RIFFInfoList {
214+
impl SplitAndMergeTag for RIFFInfoList {
215215
fn split_tag(&mut self) -> Tag {
216216
std::mem::take(self).into()
217217
}
218218

219-
fn rejoin_tag(&mut self, tag: Tag) {
219+
fn merge_tag(&mut self, tag: Tag) {
220220
*self = tag.into();
221221
}
222222
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub use crate::tag::{Tag, TagType};
178178
pub use tag::item::{ItemKey, ItemValue, TagItem};
179179
pub use util::text::TextEncoding;
180180

181-
pub use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
181+
pub use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
182182

183183
pub use picture::PictureInformation;
184184

src/mp4/ilst/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::mp4::ilst::atom::AtomDataStorage;
1010
use crate::picture::{Picture, PictureType, TOMBSTONE_PICTURE};
1111
use crate::tag::item::{ItemKey, ItemValue, TagItem};
1212
use crate::tag::{Tag, TagType};
13-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
13+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
1414
use atom::{AdvisoryRating, Atom, AtomData};
1515

1616
use std::borrow::Cow;
@@ -377,7 +377,7 @@ impl TagExt for Ilst {
377377
}
378378
}
379379

380-
impl SplitAndRejoinTag for Ilst {
380+
impl SplitAndMergeTag for Ilst {
381381
fn split_tag(&mut self) -> Tag {
382382
let mut tag = Tag::new(TagType::MP4ilst);
383383

@@ -446,7 +446,7 @@ impl SplitAndRejoinTag for Ilst {
446446
tag
447447
}
448448

449-
fn rejoin_tag(&mut self, tag: Tag) {
449+
fn merge_tag(&mut self, tag: Tag) {
450450
fn convert_to_uint(space: &mut Option<u16>, cont: &str) {
451451
if let Ok(num) = cont.parse::<u16>() {
452452
*space = Some(num);
@@ -538,7 +538,7 @@ impl From<Ilst> for Tag {
538538
impl From<Tag> for Ilst {
539539
fn from(input: Tag) -> Self {
540540
let mut ilst = Self::default();
541-
ilst.rejoin_tag(input);
541+
ilst.merge_tag(input);
542542
ilst
543543
}
544544
}

src/ogg/tag.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::picture::{Picture, PictureInformation};
77
use crate::probe::Probe;
88
use crate::tag::item::{ItemKey, ItemValue, TagItem};
99
use crate::tag::{Tag, TagType};
10-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
10+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
1111

1212
use std::borrow::Cow;
1313
use std::fs::{File, OpenOptions};
@@ -328,7 +328,7 @@ impl TagExt for VorbisComments {
328328
}
329329
}
330330

331-
impl SplitAndRejoinTag for VorbisComments {
331+
impl SplitAndMergeTag for VorbisComments {
332332
fn split_tag(&mut self) -> Tag {
333333
let mut tag = Tag::new(TagType::VorbisComments);
334334

@@ -359,7 +359,7 @@ impl SplitAndRejoinTag for VorbisComments {
359359
tag
360360
}
361361

362-
fn rejoin_tag(&mut self, mut tag: Tag) {
362+
fn merge_tag(&mut self, mut tag: Tag) {
363363
if let Some(TagItem {
364364
item_value: ItemValue::Text(val),
365365
..
@@ -403,7 +403,7 @@ impl From<VorbisComments> for Tag {
403403
impl From<Tag> for VorbisComments {
404404
fn from(input: Tag) -> Self {
405405
let mut vorbis_comments = Self::default();
406-
vorbis_comments.rejoin_tag(input);
406+
vorbis_comments.merge_tag(input);
407407
vorbis_comments
408408
}
409409
}

src/tag/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::file::FileType;
66
use crate::macros::err;
77
use crate::picture::{Picture, PictureType};
88
use crate::probe::Probe;
9-
use crate::traits::{Accessor, SplitAndRejoinTag, TagExt};
9+
use crate::traits::{Accessor, SplitAndMergeTag, TagExt};
1010
use item::{ItemKey, ItemValue, TagItem};
1111

1212
use std::borrow::Cow;
@@ -583,12 +583,12 @@ impl TagExt for Tag {
583583
}
584584
}
585585

586-
impl SplitAndRejoinTag for Tag {
586+
impl SplitAndMergeTag for Tag {
587587
fn split_tag(&mut self) -> Self {
588588
std::mem::replace(self, Self::new(self.tag_type))
589589
}
590590

591-
fn rejoin_tag(&mut self, tag: Self) {
591+
fn merge_tag(&mut self, tag: Self) {
592592
*self = tag;
593593
}
594594
}

src/traits.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ pub trait TagExt: Accessor + Into<Tag> + Sized {
233233
fn clear(&mut self);
234234
}
235235

236-
/// Split and rejoin tags.
236+
/// Split and merge tags.
237237
///
238238
/// Useful and required for implementing lossless read/modify/write round trips.
239239
///
240240
/// # Example
241241
///
242242
/// ```no_run
243243
/// use lofty::mpeg::MPEGFile;
244-
/// use lofty::{AudioFile, ItemKey, SplitAndRejoinTag as _};
244+
/// use lofty::{AudioFile, ItemKey, SplitAndMergeTag as _};
245245
///
246246
/// // Read the tag from a file
247247
/// # let mut file = std::fs::OpenOptions::new().write(true).open("/path/to/file.mp3")?;
@@ -264,19 +264,19 @@ pub trait TagExt: Accessor + Into<Tag> + Sized {
264264
/// tag.remove_key(&ItemKey::Composer);
265265
///
266266
/// // ID3v2 <- [`lofty::Tag`]
267-
/// id3v2.rejoin_tag(tag);
267+
/// id3v2.merge_tag(tag);
268268
///
269269
/// // Write the changes back into the file
270270
/// mpeg_file.save_to(&mut file)?;
271271
///
272272
/// # Ok::<(), lofty::LoftyError>(())
273273
/// ```
274-
pub trait SplitAndRejoinTag {
274+
pub trait SplitAndMergeTag {
275275
/// Extract and split generic contents into a [`Tag`].
276276
///
277277
/// Leaves the remainder that cannot be represented in the
278278
/// resulting tag in `self`. This is useful if the modified [`Tag`]
279-
/// is rejoined later using [`SplitAndRejoinTag::rejoin_tag`].
279+
/// is merged later using [`SplitAndMergeTag::merge_tag`].
280280
// NOTE: Using the "typestate pattern" (http://cliffle.com/blog/rust-typestate/)
281281
// to represent the intermediate state turned out as less flexible
282282
// and useful than expected.
@@ -285,11 +285,15 @@ pub trait SplitAndRejoinTag {
285285
/// Rejoin a [`Tag`].
286286
///
287287
/// Rejoin a tag that has previously been obtained with
288-
/// [`SplitAndRejoinTag::split_tag`].
288+
/// [`SplitAndMergeTag::split_tag`].
289289
///
290290
/// Restores the original representation merged with the contents of
291291
/// `tag` for further processing, e.g. writing back into a file.
292-
fn rejoin_tag(&mut self, tag: Tag);
292+
///
293+
/// This method must only be called once and after [`Self::split_tag`]!
294+
/// Otherwise the behavior is undefined and may result in redundancies
295+
/// or inconsistencies.
296+
fn merge_tag(&mut self, tag: Tag);
293297
}
294298

295299
// TODO: https://github.com/rust-lang/rust/issues/59359

0 commit comments

Comments
 (0)