Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **ItemKey**:
- New Variants: `AppleXID`, `Director`, `Color`
- **AudioFile**: `AudioFile::save_to{_path}`
- **Files**: `<File>::set_{tag}`

### Changed
- **MP4**: `AtomIdent` stores freeform identifiers as `Cow<str>` opposed to `String` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/95))
Expand Down
21 changes: 20 additions & 1 deletion lofty_attr/src/lofty_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ fn get_getters<'a>(
quote! {&mut self.#field_name}
};

let set_ident = Ident::new(&format!("set_{}", name), Span::call_site());

let setter = if f.needs_option {
quote! {
let ret = self.#field_name.take();
self.#field_name = Some(tag);
return ret;
}
} else {
quote! {
Some(::core::mem::replace(&mut self.#field_name, tag))
}
};

let remove_ident = Ident::new(&format!("remove_{}", name), Span::call_site());

let remover = if f.needs_option {
Expand All @@ -353,7 +367,7 @@ fn get_getters<'a>(

quote! {
#assert_field_ty_default
::core::mem::replace(&mut self.#field_name, <#field_ty>::default())
::core::mem::take(&mut self.#field_name)
}
};

Expand All @@ -371,6 +385,11 @@ fn get_getters<'a>(
#mut_access
}

/// Sets the tag, returning the old one
pub fn #set_ident(&mut self, tag: #field_ty) -> Option<#field_ty> {
#setter
}

/// Removes the tag
pub fn #remove_ident(&mut self) -> #ty_prefix #field_ty #ty_suffix {
#remover
Expand Down