Skip to content

Commit

Permalink
Preliminary fix of dotenvy attribute to work with async_std
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenfarley committed Sep 6, 2024
1 parent fa19b77 commit 2eb0f65
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dotenvy-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added examples/async-std-dotenvy/.env
Empty file.
8 changes: 8 additions & 0 deletions examples/async-std-dotenvy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" }
5 changes: 5 additions & 0 deletions examples/async-std-dotenvy/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[async_std::main]
#[dotenvy::load]
async fn main() {
println!("Hello, world!");
}
Empty file added examples/tokio-dotenvy/.env
Empty file.
8 changes: 8 additions & 0 deletions examples/tokio-dotenvy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]}
5 changes: 5 additions & 0 deletions examples/tokio-dotenvy/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[tokio::main]
#[dotenvy::load]
async fn main() {
println!("hello world")
}
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
toolchain.channel = "nightly"

0 comments on commit 2eb0f65

Please sign in to comment.