Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use &Path instead of &str for path in write_to_path #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/components/flac_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl AudioTagWrite for FlacTag {
self.inner.write_to(file)?;
Ok(())
}
fn write_to_path(&mut self, path: &str) -> crate::Result<()> {
fn write_to_path(&mut self, path: &Path) -> crate::Result<()> {
self.inner.write_to_path(path)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/id3_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl AudioTagWrite for Id3v2Tag {
self.inner.write_to(file, id3::Version::Id3v24)?;
Ok(())
}
fn write_to_path(&mut self, path: &str) -> crate::Result<()> {
fn write_to_path(&mut self, path: &Path) -> crate::Result<()> {
self.inner.write_to_path(path, id3::Version::Id3v24)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/mp4_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl AudioTagWrite for Mp4Tag {
self.inner.write_to(file)?;
Ok(())
}
fn write_to_path(&mut self, path: &str) -> crate::Result<()> {
fn write_to_path(&mut self, path: &Path) -> crate::Result<()> {
self.inner.write_to_path(path)?;
Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//!
//! ```rust,no_run
//! use audiotags::{Tag, Picture, MimeType};
//! use std::path::Path;
//!
//! // using `default()` or `new()` alone so that the metadata format is
//! // guessed (from the file extension) (in this case, Id3v2 tag is read)
Expand All @@ -58,7 +59,7 @@
//! assert!(tag.album_cover().is_none());
//! tag.remove_album_cover();
//!
//! tag.write_to_path("test.mp3").expect("Fail to save");
//! tag.write_to_path(Path::new("test.mp3")).expect("Fail to save");
//! ```

pub(crate) use audiotags_macro::*;
Expand Down Expand Up @@ -93,14 +94,15 @@ pub use std::convert::{TryFrom, TryInto};
///
/// ```no_run
/// use audiotags::{Tag, TagType};
/// use std::path::Path;
///
/// # fn main() -> audiotags::Result<()> {
/// // Guess the format by default
/// let mut tag = Tag::new().read_from_path("assets/a.mp3").unwrap();
/// tag.set_title("Foo");
///
/// // you can convert the tag type and save the metadata to another file.
/// tag.to_dyn_tag(TagType::Mp4).write_to_path("assets/a.m4a")?;
/// tag.to_dyn_tag(TagType::Mp4).write_to_path(Path::new("assets/a.m4a"))?;
///
/// // you can specify the tag type (but when you want to do this, also consider directly using the concrete type)
/// let tag = Tag::new().with_tag_type(TagType::Mp4).read_from_path("assets/a.m4a").unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use id3::Timestamp;
use std::path::Path;

pub trait AudioTag: AudioTagEdit + AudioTagWrite + ToAnyTag {}

Expand Down Expand Up @@ -148,7 +149,7 @@ pub trait AudioTagEdit: AudioTagConfig {
pub trait AudioTagWrite {
fn write_to(&mut self, file: &mut File) -> crate::Result<()>;
// cannot use impl AsRef<Path>
fn write_to_path(&mut self, path: &str) -> crate::Result<()>;
fn write_to_path(&mut self, path: &Path) -> crate::Result<()>;
}

pub trait AudioTagConfig {
Expand Down
3 changes: 2 additions & 1 deletion tests/inner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use audiotags::*;
use id3::TagLike;
use std::fs;
use std::path::Path;
use tempfile::Builder;

#[test]
Expand All @@ -24,7 +25,7 @@ fn test_inner() {
let mut id3tag = tag.to_dyn_tag(TagType::Id3v2);

id3tag
.write_to_path(tmp_path.to_str().unwrap())
.write_to_path(Path::new(tmp_path.to_str().unwrap()))
.expect("Fail to write!");

let id3tag_reload = Tag::default()
Expand Down