From 2eb0f65c74de06e594c871ec493741ef37b352ee Mon Sep 17 00:00:00 2001 From: Aiden Farley Date: Wed, 4 Sep 2024 18:43:09 -0500 Subject: [PATCH] Preliminary fix of dotenvy attribute to work with async_std --- dotenvy-macros/src/lib.rs | 4 ++-- examples/async-std-dotenvy/.env | 0 examples/async-std-dotenvy/Cargo.toml | 8 ++++++++ examples/async-std-dotenvy/src/main.rs | 5 +++++ examples/tokio-dotenvy/.env | 0 examples/tokio-dotenvy/Cargo.toml | 8 ++++++++ examples/tokio-dotenvy/src/main.rs | 5 +++++ rust-toolchain.toml | 1 + 8 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 examples/async-std-dotenvy/.env create mode 100644 examples/async-std-dotenvy/Cargo.toml create mode 100644 examples/async-std-dotenvy/src/main.rs create mode 100644 examples/tokio-dotenvy/.env create mode 100644 examples/tokio-dotenvy/Cargo.toml create mode 100644 examples/tokio-dotenvy/src/main.rs create mode 100644 rust-toolchain.toml diff --git a/dotenvy-macros/src/lib.rs b/dotenvy-macros/src/lib.rs index 61065049..102b5a52 100644 --- a/dotenvy-macros/src/lib.rs +++ b/dotenvy-macros/src/lib.rs @@ -71,9 +71,9 @@ pub fn load(attr: TokenStream, item: TokenStream) -> TokenStream { // this works with `tokio::main`` but not `async_std::main`` quote! { // non-async wrapper function - #vis fn #fn_name() #output { + #vis async fn #fn_name() #output { #load_env - #new_fn_name() + #new_fn_name().await } // orig async function, but renamed diff --git a/examples/async-std-dotenvy/.env b/examples/async-std-dotenvy/.env new file mode 100644 index 00000000..e69de29b diff --git a/examples/async-std-dotenvy/Cargo.toml b/examples/async-std-dotenvy/Cargo.toml new file mode 100644 index 00000000..7d87ffb2 --- /dev/null +++ b/examples/async-std-dotenvy/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "async-std-dotenvy" +version = "0.1.0" +edition = "2021" + +[dependencies] +async-std = { version = "1.12.0", features = ["attributes"] } +dotenvy = { path = "../../dotenvy" } \ No newline at end of file diff --git a/examples/async-std-dotenvy/src/main.rs b/examples/async-std-dotenvy/src/main.rs new file mode 100644 index 00000000..92ca5c27 --- /dev/null +++ b/examples/async-std-dotenvy/src/main.rs @@ -0,0 +1,5 @@ +#[async_std::main] +#[dotenvy::load] +async fn main() { + println!("Hello, world!"); +} diff --git a/examples/tokio-dotenvy/.env b/examples/tokio-dotenvy/.env new file mode 100644 index 00000000..e69de29b diff --git a/examples/tokio-dotenvy/Cargo.toml b/examples/tokio-dotenvy/Cargo.toml new file mode 100644 index 00000000..eefc1ea0 --- /dev/null +++ b/examples/tokio-dotenvy/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "tokio-dotenvy" +version = "0.1.0" +edition = "2021" + +[dependencies] +dotenvy = { path = "../../dotenvy" } +tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"]} \ No newline at end of file diff --git a/examples/tokio-dotenvy/src/main.rs b/examples/tokio-dotenvy/src/main.rs new file mode 100644 index 00000000..1e23d2e7 --- /dev/null +++ b/examples/tokio-dotenvy/src/main.rs @@ -0,0 +1,5 @@ +#[tokio::main] +#[dotenvy::load] +async fn main() { + println!("hello world") +} \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..73027556 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1 @@ +toolchain.channel = "nightly" \ No newline at end of file