mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-03 14:27:18 +00:00
Files: Add <File>::set_{tag}
This commit is contained in:
parent
42908415b4
commit
a5b1ccaff0
2 changed files with 21 additions and 1 deletions
|
@ -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))
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue