mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 14:57:17 +00:00
Clippy and some more doc comments
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
ae81ff21e9
commit
04a9ab4634
8 changed files with 31 additions and 22 deletions
|
@ -1,12 +1,11 @@
|
|||
#![cfg(feature = "mp3")]
|
||||
|
||||
use crate::{
|
||||
impl_tag, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Error, MimeType, Picture,
|
||||
Result, TagType, ToAny, ToAnyTag,
|
||||
impl_tag, traits::ReadPath, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Error,
|
||||
MimeType, Picture, Result, TagType, ToAny, ToAnyTag,
|
||||
};
|
||||
use std::{convert::TryInto, fs::File, path::Path};
|
||||
|
||||
use crate::traits::ReadPath;
|
||||
pub use id3::Tag as Id3v2InnerTag;
|
||||
|
||||
impl ReadPath for Id3v2InnerTag {
|
||||
|
@ -111,13 +110,16 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
}
|
||||
|
||||
fn add_artist(&mut self, artist: &str) {
|
||||
if let Some(artists) = self.artist() {
|
||||
let mut artists: Vec<&str> = artists.split(", ").collect();
|
||||
artists.push(artist);
|
||||
self.set_artist(&artists.join(", "))
|
||||
} else {
|
||||
self.set_artist(artist)
|
||||
}
|
||||
let artist = self.artist().as_ref().map_or_else(
|
||||
|| String::from(artist),
|
||||
|artist| {
|
||||
let mut artists: Vec<&str> = artist.split(", ").collect();
|
||||
artists.push(artist);
|
||||
artists.join(", ")
|
||||
},
|
||||
);
|
||||
|
||||
self.set_artist(artist.as_str())
|
||||
}
|
||||
|
||||
fn artists(&self) -> Option<Vec<&str>> {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#![cfg(feature = "mp4")]
|
||||
|
||||
use crate::{
|
||||
impl_tag, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Error, MimeType, Picture,
|
||||
Result, TagType, ToAny, ToAnyTag,
|
||||
impl_tag, traits::ReadPath, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Error,
|
||||
MimeType, Picture, Result, TagType, ToAny, ToAnyTag,
|
||||
};
|
||||
use std::{fs::File, path::Path};
|
||||
|
||||
use crate::traits::ReadPath;
|
||||
pub use mp4ameta::{FourCC, Tag as Mp4InnerTag};
|
||||
|
||||
impl ReadPath for Mp4InnerTag {
|
||||
|
|
|
@ -442,17 +442,19 @@ impl AudioTagWrite for VorbisTag {
|
|||
file.set_len(0)?;
|
||||
file.write_all(&data)?;
|
||||
},
|
||||
TagType::Opus => {},
|
||||
TagType::Flac => {
|
||||
let mut flac_tag: metaflac::Tag = self.into();
|
||||
|
||||
flac_tag.write_to(file)?;
|
||||
},
|
||||
TagType::Opus => {
|
||||
todo!()
|
||||
},
|
||||
TagType::Mp4 => {},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
// self.0.write_to(file)?; TODO
|
||||
|
||||
Ok(())
|
||||
}
|
||||
fn write_to_path(&self, path: &str) -> Result<()> {
|
||||
|
|
|
@ -78,7 +78,8 @@
|
|||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::doc_markdown,
|
||||
clippy::let_underscore_drop
|
||||
clippy::let_underscore_drop,
|
||||
clippy::match_wildcard_for_single_variants
|
||||
)]
|
||||
|
||||
#[doc(hidden)]
|
||||
|
|
|
@ -15,6 +15,7 @@ macro_rules! impl_tag {
|
|||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
#[allow(clippy::missing_errors_doc)]
|
||||
pub fn read_from_path<P>(path: P, tag_type: Option<TagType>) -> Result<Self>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
|
|
|
@ -4,11 +4,6 @@ use std::fs::File;
|
|||
|
||||
pub trait AudioTag: AudioTagEdit + AudioTagWrite + ToAnyTag {}
|
||||
|
||||
// pub trait TagIo {
|
||||
// fn read_from_path(path: &str) -> Result<AnyTag>;
|
||||
// fn write_to_path(path: &str) -> Result<()>;
|
||||
// }
|
||||
|
||||
/// Implementors of this trait are able to read and write audio metadata.
|
||||
///
|
||||
/// Constructor methods e.g. `from_file` should be implemented separately.
|
||||
|
@ -89,8 +84,17 @@ pub trait AudioTagEdit {
|
|||
}
|
||||
|
||||
pub trait AudioTagWrite {
|
||||
/// Write tag to a [`File`][std::fs::File]
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Will return `Err` if unable to write to the `File`
|
||||
fn write_to(&self, file: &mut File) -> Result<()>;
|
||||
// cannot use impl AsRef<Path>
|
||||
/// Write tag to a path
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Will return `Err` if `path` doesn't exist
|
||||
fn write_to_path(&self, path: &str) -> Result<()>;
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue