Skip to content

Commit

Permalink
impl FromMeta for PathBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
TedDriggs committed Nov 17, 2023
1 parent 22a1268 commit 1c27b38
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/from_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ impl FromMeta for String {
}
}

impl FromMeta for std::path::PathBuf {
fn from_string(s: &str) -> Result<Self> {
Ok(s.into())
}
}

/// Generate an impl of `FromMeta` that will accept strings which parse to numbers or
/// integer literals.
macro_rules! from_meta_num {
Expand Down Expand Up @@ -795,6 +801,14 @@ mod tests {
assert_eq!(&fm::<String>(quote!(ignore = r#"world"#)), "world");
}

#[test]
fn pathbuf_succeeds() {
assert_eq!(
fm::<std::path::PathBuf>(quote!(ignore = r#"C:\"#)),
std::path::PathBuf::from(r#"C:\"#)
);
}

#[test]
#[allow(clippy::float_cmp)] // we want exact equality
fn number_succeeds() {
Expand Down

0 comments on commit 1c27b38

Please sign in to comment.