From 49201989c1958ef81dac4b9a14c3537e100b1ed1 Mon Sep 17 00:00:00 2001 From: Stock84-dev Date: Sun, 17 Sep 2023 18:23:50 +0200 Subject: [PATCH] Add support for string literals --- README.md | 8 +++----- src/lib.rs | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0a4e3b0..1b4e866 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,9 @@ after the declaration using the `=>` operator: use path_no_alloc::with_paths; let p1 = "some/dir"; -let p2 = "file.txt"; let file_exists: bool = with_paths! { - path = p1 / p2 => path.exists() + path = p1 / "file.txt" => path.exists() }; ``` @@ -51,13 +50,12 @@ use std::path::{Path, PathBuf}; let p1 = Path::new("hello"); let p2 = "world".to_string(); -let my_file = "file.txt"; let some_root = PathBuf::from("some/project/root"); let path_exists = with_paths! { path = p1 / p2, - another_path = some_root / p1 / my_file, - some_third_path = p1 / p2 / some_root / my_file + another_path = some_root / p1 / "file.txt", + some_third_path = p1 / p2 / some_root / "file.txt" => diff --git a/src/lib.rs b/src/lib.rs index ca4fa74..453c10a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,7 +124,7 @@ pub fn join_in_buff<'a, const N: usize>( macro_rules! with_paths { // Declaration mode { - $( $name:ident = $( $path:ident ) / + ),* + $( $name:ident = $( $path:tt ) / + ),* $(,)? } => { $( let mut __with_paths_arr: [std::mem::MaybeUninit; 128] = unsafe { std::mem::MaybeUninit::uninit().assume_init() }; @@ -135,7 +135,7 @@ macro_rules! with_paths { // Expression mode { - $( $name:ident = $( $path:ident ) / + ),* + $( $name:ident = $( $path:tt ) / + ),* $(,)? => $( $statements:stmt );* $(;)? } => { {