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/out.rs b/examples/async-std-dotenvy/out.rs new file mode 100644 index 00000000..4f4a7710 --- /dev/null +++ b/examples/async-std-dotenvy/out.rs @@ -0,0 +1,45 @@ +#![feature(prelude_import)] +#[prelude_import] +use std::prelude::rust_2021::*; +#[macro_use] +extern crate std; +fn main() { + async fn main() { + use dotenvy::{EnvLoader, EnvSequence}; + use std::{ + error::Error, io::{self, ErrorKind}, + process, + }; + let seq = if false { EnvSequence::InputOnly } else { EnvSequence::InputThenEnv }; + let mut loader = EnvLoader::from_path(".env").sequence(seq); + if let Err(e) = unsafe { loader.load_and_modify() } { + if let Some(io_err) = e + .source() + .and_then(|src| src.downcast_ref::()) + { + if io_err.kind() == io::ErrorKind::NotFound && !true {} + } + { + ::std::io::_eprint( + format_args!( + "Failed to load env file from path \'{0}\': {1}\n", + ".env", + e, + ), + ); + }; + process::exit(1); + } + main_inner() + } + async fn main_inner() { + { + { + { + ::std::io::_print(format_args!("Hello, world!\n")); + }; + } + } + } + async_std::task::block_on(async { main().await }) +} 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/out.rs b/examples/tokio-dotenvy/out.rs new file mode 100644 index 00000000..0192d2be --- /dev/null +++ b/examples/tokio-dotenvy/out.rs @@ -0,0 +1,20 @@ +#![feature(prelude_import)] +#[prelude_import] +use std::prelude::rust_2021::*; +#[macro_use] +extern crate std; +fn main() { + let body = async { + { + ::std::io::_print(format_args!("hello world\n")); + } + }; + #[allow(clippy::expect_used, clippy::diverging_sub_expression)] + { + return tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("Failed building the Runtime") + .block_on(body); + } +} 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