| 1 | // Items that only pertain to internal usage of lofty_attr |
| 2 | |
| 3 | use craterust-analyzer cargo lofty_attr 0.11.1 crate/::lofty_filerust-analyzer cargo lofty_attr 0.11.1 lofty_file/::FieldContentsrust-analyzer cargo lofty_attr 0.11.1 lofty_file/FieldContents#; |
| 4 | |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#; |
| 6 | |
| 7 | use quoterust-analyzer cargo quote 1.0.38 crate/::quoterust-analyzer cargo quote 1.0.38 quote!; |
| 8 | |
| 9 | pub(craterust-analyzer cargo lofty_attr 0.11.1 crate/) fn opt_internal_file_typerust-analyzer cargo lofty_attr 0.11.1 internal/opt_internal_file_type().( |
| 10 | struct_name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 11 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#, bool)> { |
| 12 | const LOFTY_FILE_TYPESrust-analyzer cargo lofty_attr 0.11.1 internal/LOFTY_FILE_TYPES.: [&str; 12] = [ |
| 13 | "Aac", "Aiff", "Ape", "Flac", "Mpeg", "Mp4", "Mpc", "Opus", "Vorbis", "Speex", "Wav", |
| 14 | "WavPack", |
| 15 | ]; |
| 16 | |
| 17 | const ID3V2_STRIPPABLErust-analyzer cargo lofty_attr 0.11.1 internal/ID3V2_STRIPPABLE.: [&str; 2] = ["Flac", "Ape"]; |
| 18 | |
| 19 | let stripped = struct_name.strip_suffixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_suffix().("File"); |
| 20 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prefix) = stripped { |
| 21 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pos) = LOFTY_FILE_TYPESrust-analyzer cargo lofty_attr 0.11.1 internal/LOFTY_FILE_TYPES. |
| 22 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 23 | .positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|p| p.eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().(prefix)) |
| 24 | { |
| 25 | let file_ty = LOFTY_FILE_TYPESrust-analyzer cargo lofty_attr 0.11.1 internal/LOFTY_FILE_TYPES.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 26 | let tt = file_ty.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 27 | |
| 28 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((tt, ID3V2_STRIPPABLErust-analyzer cargo lofty_attr 0.11.1 internal/ID3V2_STRIPPABLE..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&file_ty))); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 33 | } |
| 34 | |
| 35 | pub(craterust-analyzer cargo lofty_attr 0.11.1 crate/) fn init_write_lookuprust-analyzer cargo lofty_attr 0.11.1 internal/init_write_lookup().( |
| 36 | id3v2_strippable: bool, |
| 37 | ) -> HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&'static str, proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#> { |
| 38 | let mut map = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(); |
| 39 | |
| 40 | macro_rules! insertrust-analyzer cargo lofty_attr 0.11.1 internal/insert! { |
| 41 | ($map:ident, $key:path, $val:block) => { |
| 42 | $map.insert(stringify!($key), quote! { $val }) |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | insertrust-analyzer cargo lofty_attr 0.11.1 internal/insert!!(map, Ape, { |
| 47 | lofty::ape::tag::ApeTagRef { |
| 48 | read_only: false, |
| 49 | items: lofty::ape::tag::tagitems_into_ape(tag), |
| 50 | } |
| 51 | .write_to(file, write_options) |
| 52 | }); |
| 53 | |
| 54 | insertrust-analyzer cargo lofty_attr 0.11.1 internal/insert!!(map, Id3v1, { |
| 55 | Into::<lofty::id3::v1::tag::Id3v1TagRef<'_>>::into(tag).write_to(file, write_options) |
| 56 | }); |
| 57 | |
| 58 | if id3v2_strippable { |
| 59 | insertrust-analyzer cargo lofty_attr 0.11.1 internal/insert!!(map, Id3v2, { |
| 60 | lofty::id3::v2::tag::Id3v2TagRef::empty().write_to(file, write_options) |
| 61 | }); |
| 62 | } else { |
| 63 | insertrust-analyzer cargo lofty_attr 0.11.1 internal/insert!!(map, Id3v2, { |
| 64 | lofty::id3::v2::tag::Id3v2TagRef { |
| 65 | flags: lofty::id3::v2::Id3v2TagFlags::default(), |
| 66 | frames: lofty::id3::v2::tag::tag_frames(tag).peekable(), |
| 67 | } |
| 68 | .write_to(file, write_options) |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | insertrust-analyzer cargo lofty_attr 0.11.1 internal/insert!!(map, RiffInfo, { |
| 73 | lofty::iff::wav::tag::RIFFInfoListRef::new(lofty::iff::wav::tag::tagitems_into_riff( |
| 74 | tag.items(), |
| 75 | )) |
| 76 | .write_to(file, write_options) |
| 77 | }); |
| 78 | |
| 79 | insertrust-analyzer cargo lofty_attr 0.11.1 internal/insert!!(map, AiffText, { |
| 80 | lofty::iff::aiff::tag::AiffTextChunksRef { |
| 81 | name: tag.get_string(&lofty::prelude::ItemKey::TrackTitle), |
| 82 | author: tag.get_string(&lofty::prelude::ItemKey::TrackArtist), |
| 83 | copyright: tag.get_string(&lofty::prelude::ItemKey::CopyrightMessage), |
| 84 | annotations: Some(tag.get_strings(&lofty::prelude::ItemKey::Comment)), |
| 85 | comments: None, |
| 86 | } |
| 87 | .write_to(file, write_options) |
| 88 | }); |
| 89 | |
| 90 | map |
| 91 | } |
| 92 | |
| 93 | pub(craterust-analyzer cargo lofty_attr 0.11.1 crate/) fn write_modulerust-analyzer cargo lofty_attr 0.11.1 internal/write_module().( |
| 94 | fields: &[FieldContentsrust-analyzer cargo lofty_attr 0.11.1 lofty_file/FieldContents#], |
| 95 | lookup: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&'static str, proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#>, |
| 96 | ) -> proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream# { |
| 97 | let applicable_formats = fields.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|f| { |
| 98 | let tag_ty = |
| 99 | synrust-analyzer cargo syn 2.0.96 crate/::parse_strrust-analyzer cargo syn 2.0.96 parse_str().::<synrust-analyzer cargo syn 2.0.96 crate/::Pathrust-analyzer cargo syn 2.0.96 path/Path#>(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("::lofty::tag::TagType::{}", &f.tag_typerust-analyzer cargo lofty_attr 0.11.1 lofty_file/FieldContents#tag_type.)) |
| 100 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 101 | |
| 102 | let cfg_features = f.get_cfg_featuresrust-analyzer cargo lofty_attr 0.11.1 lofty_file/impl#[FieldContents]get_cfg_features().(); |
| 103 | |
| 104 | let block = lookup.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().tag_ty.segmentsrust-analyzer cargo syn 2.0.96 path/Path#segments.[rust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`][`Index<usize>`]index().3]rust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`][`Index<usize>`]index()..identrust-analyzer cargo syn 2.0.96 path/PathSegment#ident..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 105 | |
| 106 | quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 107 | #( #cfg_features )* |
| 108 | #tag_ty => #block, |
| 109 | } |
| 110 | }); |
| 111 | |
| 112 | quoterust-analyzer cargo quote 1.0.38 quote!! { |
| 113 | pub(crate) mod write { |
| 114 | #[allow(unused_variables)] |
| 115 | pub(crate) fn write_to<F>(file: &mut F, tag: &::lofty::tag::Tag, write_options: ::lofty::config::WriteOptions) -> ::lofty::error::Result<()> |
| 116 | where |
| 117 | F: ::lofty::io::FileLike, |
| 118 | ::lofty::error::LoftyError: ::std::convert::From<<F as ::lofty::io::Truncate>::Error>, |
| 119 | ::lofty::error::LoftyError: ::std::convert::From<<F as ::lofty::io::Length>::Error>, |
| 120 | { |
| 121 | match tag.tag_type() { |
| 122 | #( #applicable_formats )* |
| 123 | _ => crate::macros::err!(UnsupportedTag), |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |