diff --git a/CHANGELOG.md b/CHANGELOG.md index 27b36f7..cd3f90c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Accept bare paths in `#[darling(default = ...)]` [#258](https://github.com/TedDriggs/darling/pull/258) +- Add `FromMeta` impl for `PathBuf` [#259](https://github.com/TedDriggs/darling/pull/259) ## v0.20.3 (July 12, 2023) diff --git a/core/src/from_meta.rs b/core/src/from_meta.rs index ff57ab0..ba2a3a2 100644 --- a/core/src/from_meta.rs +++ b/core/src/from_meta.rs @@ -203,6 +203,12 @@ impl FromMeta for String { } } +impl FromMeta for std::path::PathBuf { + fn from_string(s: &str) -> Result { + Ok(s.into()) + } +} + /// Generate an impl of `FromMeta` that will accept strings which parse to numbers or /// integer literals. macro_rules! from_meta_num { @@ -795,6 +801,14 @@ mod tests { assert_eq!(&fm::(quote!(ignore = r#"world"#)), "world"); } + #[test] + fn pathbuf_succeeds() { + assert_eq!( + fm::(quote!(ignore = r#"C:\"#)), + std::path::PathBuf::from(r#"C:\"#) + ); + } + #[test] #[allow(clippy::float_cmp)] // we want exact equality fn number_succeeds() {