From 46626c98e95245213e6f8126151b75f558e11a8f Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:15:05 -0400 Subject: [PATCH] Tag: Seal {Split,Merge}Tag traits --- src/tag/split_merge_tag.rs | 41 ++++++++++++++++++++++++++++++++++++-- src/tag/tag_ext.rs | 1 + 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/tag/split_merge_tag.rs b/src/tag/split_merge_tag.rs index 80804a66..8cdd3374 100644 --- a/src/tag/split_merge_tag.rs +++ b/src/tag/split_merge_tag.rs @@ -39,7 +39,7 @@ use super::Tag; /// /// # Ok(()) } /// ``` -pub trait SplitTag { +pub trait SplitTag: private::Sealed { /// The remainder of the split operation that is not represented /// in the resulting `Tag`. type Remainder: MergeTag; @@ -53,7 +53,7 @@ pub trait SplitTag { } /// The counterpart of [`SplitTag`]. -pub trait MergeTag { +pub trait MergeTag: private::Sealed { /// The resulting tag. type Merged: SplitTag; @@ -66,3 +66,40 @@ pub trait MergeTag { /// depending on the support for multi-valued fields in `self`. fn merge_tag(self, tag: Tag) -> Self::Merged; } + +// https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed +mod private { + use crate::ape::ApeTag; + use crate::id3::v1::Id3v1Tag; + use crate::id3::v2::Id3v2Tag; + use crate::iff::aiff::AIFFTextChunks; + use crate::iff::wav::RIFFInfoList; + use crate::ogg::VorbisComments; + use crate::tag::Tag; + + pub trait Sealed {} + + impl Sealed for AIFFTextChunks {} + impl Sealed for crate::iff::aiff::tag::SplitTagRemainder {} + + impl Sealed for ApeTag {} + impl Sealed for crate::ape::tag::SplitTagRemainder {} + + impl Sealed for Id3v1Tag {} + impl Sealed for crate::id3::v1::tag::SplitTagRemainder {} + + impl Sealed for Id3v2Tag {} + impl Sealed for crate::id3::v2::tag::SplitTagRemainder {} + + impl Sealed for crate::mp4::Ilst {} + impl Sealed for crate::mp4::ilst::SplitTagRemainder {} + + impl Sealed for RIFFInfoList {} + impl Sealed for crate::iff::wav::tag::SplitTagRemainder {} + + impl Sealed for Tag {} + impl Sealed for crate::tag::SplitTagRemainder {} + + impl Sealed for VorbisComments {} + impl Sealed for crate::ogg::tag::SplitTagRemainder {} +} diff --git a/src/tag/tag_ext.rs b/src/tag/tag_ext.rs index 4510ac8f..7d5ffa8a 100644 --- a/src/tag/tag_ext.rs +++ b/src/tag/tag_ext.rs @@ -150,6 +150,7 @@ pub trait TagExt: Accessor + Into + Sized + private::Sealed { fn clear(&mut self); } +// https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed mod private { use crate::ape::ApeTag; use crate::id3::v1::Id3v1Tag;