lofty_attr: Return removed tags in <File>::remove_*

Previously, we just removed and dropped the tag. That should really be left up to the user, though.
This commit is contained in:
Serial 2022-11-09 13:09:42 -05:00 committed by Alex
parent 793b2d03d1
commit 7fdc3e0b2a
3 changed files with 9 additions and 4 deletions

View file

@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- **TagExt**: `TagExt::contains`
### Changed
- **Files**: Return the removed tag from `<File>::remove(TagType)`
- Previously, the only way to remove and take a tag was through `TaggedFile::take`.
This was not possible when using a concrete type, such as `OpusFile`.
## [0.9.0] - 2022-10-30
### Added

View file

@ -20,7 +20,7 @@ cfg-if = "1.0.0"
# ID3 compressed frames
flate2 = { version = "1.0.24", optional = true }
# Proc macros
lofty_attr = "0.4.0"
lofty_attr = { path = "lofty_attr" }
# Debug logging
log = "0.4.17"
# OGG Vorbis/Opus

View file

@ -304,7 +304,7 @@ fn get_getters<'a>(
let remove_ident = Ident::new(&format!("remove_{}", name), Span::call_site());
let remover = if f.needs_option {
quote! {self.#field_name = None;}
quote! { self.#field_name.take() }
} else {
let assert_field_ty_default = quote_spanned! {f.name.span()=>
struct _AssertDefault where #field_ty: core::default::Default;
@ -312,7 +312,7 @@ fn get_getters<'a>(
quote! {
#assert_field_ty_default
self.#field_name = <#field_ty>::default();
::core::mem::replace(&mut self.#field_name, <#field_ty>::default())
}
};
@ -331,7 +331,7 @@ fn get_getters<'a>(
}
/// Removes the tag
pub fn #remove_ident(&mut self) {
pub fn #remove_ident(&mut self) -> #ty_prefix #field_ty #ty_suffix {
#remover
}
}