mirror of https://github.com/fafhrd91/actix-net
prepare macros v0.2.0 release
This commit is contained in:
parent
057e7cd7c9
commit
00efaccf23
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-macros"
|
name = "actix-macros"
|
||||||
version = "0.2.0-beta.1"
|
version = "0.2.0"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix runtime macros"
|
description = "Macros for Actix system and runtime"
|
||||||
repository = "https://github.com/actix/actix-net"
|
repository = "https://github.com/actix/actix-net"
|
||||||
documentation = "https://docs.rs/actix-macros/"
|
documentation = "https://docs.rs/actix-macros/"
|
||||||
categories = ["network-programming", "asynchronous"]
|
categories = ["network-programming", "asynchronous"]
|
||||||
|
@ -16,11 +16,8 @@ proc-macro = true
|
||||||
quote = "1.0.3"
|
quote = "1.0.3"
|
||||||
syn = { version = "^1", features = ["full"] }
|
syn = { version = "^1", features = ["full"] }
|
||||||
|
|
||||||
[features]
|
|
||||||
actix-reexport = []
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "2.0.0-beta.2"
|
actix-rt = "2.0.0-beta.3"
|
||||||
|
|
||||||
futures-util = { version = "0.3", default-features = false }
|
futures-util = { version = "0.3", default-features = false }
|
||||||
trybuild = "1"
|
trybuild = "1"
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
//! Macros for use with Tokio
|
//! Macros for Actix system and runtime.
|
||||||
|
//!
|
||||||
|
//! The [`actix-rt`](https://docs.rs/actix-rt) crate must be available for macro output to compile.
|
||||||
|
//!
|
||||||
|
//! # Entry-point
|
||||||
|
//! See docs for the [`#[main]`](macro@main) macro.
|
||||||
|
//!
|
||||||
|
//! # Tests
|
||||||
|
//! See docs for the [`#[test]`](macro@test) macro.
|
||||||
|
|
||||||
#![deny(rust_2018_idioms, nonstandard_style)]
|
#![deny(rust_2018_idioms, nonstandard_style)]
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
|
@ -7,10 +15,9 @@
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
/// Marks async function to be executed by Actix system.
|
/// Marks async entry-point function to be executed by Actix system.
|
||||||
///
|
|
||||||
/// ## Usage
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// #[actix_rt::main]
|
/// #[actix_rt::main]
|
||||||
/// async fn main() {
|
/// async fn main() {
|
||||||
|
@ -28,9 +35,12 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let body = &input.block;
|
let body = &input.block;
|
||||||
|
|
||||||
if sig.asyncness.is_none() {
|
if sig.asyncness.is_none() {
|
||||||
return syn::Error::new_spanned(sig.fn_token, "only async fn is supported")
|
return syn::Error::new_spanned(
|
||||||
.to_compile_error()
|
sig.fn_token,
|
||||||
.into();
|
"the async keyword is missing from the function declaration",
|
||||||
|
)
|
||||||
|
.to_compile_error()
|
||||||
|
.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
sig.asyncness = None;
|
sig.asyncness = None;
|
||||||
|
@ -45,18 +55,17 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marks async test function to be executed by Actix system.
|
/// Marks async test function to be executed in an Actix system.
|
||||||
///
|
///
|
||||||
/// ## Usage
|
/// # Examples
|
||||||
///
|
/// ```
|
||||||
/// ```no_run
|
|
||||||
/// #[actix_rt::test]
|
/// #[actix_rt::test]
|
||||||
/// async fn my_test() {
|
/// async fn my_test() {
|
||||||
/// assert!(true);
|
/// assert!(true);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn test_base(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let mut input = syn::parse_macro_input!(item as syn::ItemFn);
|
let mut input = syn::parse_macro_input!(item as syn::ItemFn);
|
||||||
let attrs = &input.attrs;
|
let attrs = &input.attrs;
|
||||||
let vis = &input.vis;
|
let vis = &input.vis;
|
||||||
|
@ -73,7 +82,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
if sig.asyncness.is_none() {
|
if sig.asyncness.is_none() {
|
||||||
return syn::Error::new_spanned(
|
return syn::Error::new_spanned(
|
||||||
input.sig.fn_token,
|
input.sig.fn_token,
|
||||||
format!("only async fn is supported, {}", input.sig.ident),
|
"the async keyword is missing from the function declaration",
|
||||||
)
|
)
|
||||||
.to_compile_error()
|
.to_compile_error()
|
||||||
.into();
|
.into();
|
||||||
|
@ -81,24 +90,19 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
sig.asyncness = None;
|
sig.asyncness = None;
|
||||||
|
|
||||||
let result = if has_test_attr {
|
let missing_test_attr = if has_test_attr {
|
||||||
quote! {
|
quote!()
|
||||||
#(#attrs)*
|
|
||||||
#vis #sig {
|
|
||||||
actix_rt::System::new()
|
|
||||||
.block_on(async { #body })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote!(#[test])
|
||||||
#[test]
|
|
||||||
#(#attrs)*
|
|
||||||
#vis #sig {
|
|
||||||
actix_rt::System::new()
|
|
||||||
.block_on(async { #body })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
result.into()
|
(quote! {
|
||||||
|
#missing_test_attr
|
||||||
|
#(#attrs)*
|
||||||
|
#vis #sig {
|
||||||
|
actix_rt::System::new()
|
||||||
|
.block_on(async { #body })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ fn compile_macros() {
|
||||||
let t = trybuild::TestCases::new();
|
let t = trybuild::TestCases::new();
|
||||||
t.pass("tests/trybuild/main-01-basic.rs");
|
t.pass("tests/trybuild/main-01-basic.rs");
|
||||||
t.compile_fail("tests/trybuild/main-02-only-async.rs");
|
t.compile_fail("tests/trybuild/main-02-only-async.rs");
|
||||||
|
t.pass("tests/trybuild/main-03-fn-params.rs");
|
||||||
|
|
||||||
t.pass("tests/trybuild/test-01-basic.rs");
|
t.pass("tests/trybuild/test-01-basic.rs");
|
||||||
t.pass("tests/trybuild/test-02-keep-attrs.rs");
|
t.pass("tests/trybuild/test-02-keep-attrs.rs");
|
||||||
|
t.compile_fail("tests/trybuild/test-03-only-async.rs");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: only async fn is supported
|
error: the async keyword is missing from the function declaration
|
||||||
--> $DIR/main-02-only-async.rs:2:1
|
--> $DIR/main-02-only-async.rs:2:1
|
||||||
|
|
|
|
||||||
2 | fn main() {
|
2 | fn main() {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#[actix_rt::main]
|
||||||
|
async fn main2(_param: bool) {
|
||||||
|
futures_util::future::ready(()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#[actix_rt::test]
|
||||||
|
fn my_test() {
|
||||||
|
futures_util::future::ready(()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,5 @@
|
||||||
|
error: the async keyword is missing from the function declaration
|
||||||
|
--> $DIR/test-03-only-async.rs:2:1
|
||||||
|
|
|
||||||
|
2 | fn my_test() {
|
||||||
|
| ^^
|
|
@ -5,7 +5,7 @@ authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"Rob Ede <robjtede@icloud.com>",
|
"Rob Ede <robjtede@icloud.com>",
|
||||||
]
|
]
|
||||||
description = "Tokio-based single-thread async runtime for the Actix ecosystem"
|
description = "Tokio-based single-threaded async runtime for the Actix ecosystem"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
homepage = "https://actix.rs"
|
homepage = "https://actix.rs"
|
||||||
repository = "https://github.com/actix/actix-net.git"
|
repository = "https://github.com/actix/actix-net.git"
|
||||||
|
@ -23,7 +23,7 @@ default = ["macros"]
|
||||||
macros = ["actix-macros"]
|
macros = ["actix-macros"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-macros = { version = "0.2.0-beta.1", optional = true }
|
actix-macros = { version = "0.2.0", optional = true }
|
||||||
|
|
||||||
futures-core = { version = "0.3", default-features = false }
|
futures-core = { version = "0.3", default-features = false }
|
||||||
tokio = { version = "1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
tokio = { version = "1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# actix-rt
|
# actix-rt
|
||||||
|
|
||||||
> Tokio-based single-thread async runtime for the Actix ecosystem.
|
> Tokio-based single-threaded async runtime for the Actix ecosystem.
|
||||||
|
|
||||||
See documentation for detailed explanations these components: [https://docs.rs/actix-rt][docs].
|
See documentation for detailed explanations these components: [https://docs.rs/actix-rt][docs].
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Tokio-based single-thread async runtime for the Actix ecosystem.
|
//! Tokio-based single-threaded async runtime for the Actix ecosystem.
|
||||||
//!
|
//!
|
||||||
//! In most parts of the the Actix ecosystem, it has been chosen to use !Send futures. For this
|
//! In most parts of the the Actix ecosystem, it has been chosen to use !Send futures. For this
|
||||||
//! reason, a single-threaded runtime is appropriate since it is guaranteed that futures will not
|
//! reason, a single-threaded runtime is appropriate since it is guaranteed that futures will not
|
||||||
|
|
|
@ -24,7 +24,7 @@ default = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-rt = { version = "2.0.0-beta.2", default-features = false }
|
actix-rt = { version = "2.0.0-beta.3", default-features = false }
|
||||||
actix-service = "2.0.0-beta.3"
|
actix-service = "2.0.0-beta.3"
|
||||||
actix-utils = "3.0.0-beta.1"
|
actix-utils = "3.0.0-beta.1"
|
||||||
|
|
||||||
|
|
|
@ -24,5 +24,5 @@ futures-core = { version = "0.3.7", default-features = false }
|
||||||
pin-project-lite = "0.2"
|
pin-project-lite = "0.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "2.0.0-beta.2"
|
actix-rt = { version = "2.0.0-beta.3", default-features = false }
|
||||||
futures-util = { version = "0.3.7", default-features = false }
|
futures-util = { version = "0.3.7", default-features = false }
|
||||||
|
|
|
@ -41,7 +41,7 @@ uri = ["http"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-rt = { version = "2.0.0-beta.2", default-features = false }
|
actix-rt = { version = "2.0.0-beta.3", default-features = false }
|
||||||
actix-service = "2.0.0-beta.3"
|
actix-service = "2.0.0-beta.3"
|
||||||
actix-utils = "3.0.0-beta.1"
|
actix-utils = "3.0.0-beta.1"
|
||||||
|
|
||||||
|
@ -67,7 +67,6 @@ tls-native-tls = { package = "native-tls", version = "0.2", optional = true }
|
||||||
tokio-native-tls = { version = "0.3", optional = true }
|
tokio-native-tls = { version = "0.3", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "2.0.0-beta.2"
|
|
||||||
actix-server = "2.0.0-beta.2"
|
actix-server = "2.0.0-beta.2"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
|
|
|
@ -23,5 +23,5 @@ tracing = "0.1"
|
||||||
tracing-futures = "0.2"
|
tracing-futures = "0.2"
|
||||||
|
|
||||||
[dev_dependencies]
|
[dev_dependencies]
|
||||||
actix-rt = "2.0.0-beta.2"
|
actix-rt = { version = "2.0.0-beta.3", default-features = false }
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
|
|
|
@ -17,7 +17,7 @@ path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-rt = { version = "2.0.0-beta.2", default-features = false }
|
actix-rt = { version = "2.0.0-beta.3", default-features = false }
|
||||||
actix-service = "2.0.0-beta.3"
|
actix-service = "2.0.0-beta.3"
|
||||||
|
|
||||||
futures-core = { version = "0.3.7", default-features = false }
|
futures-core = { version = "0.3.7", default-features = false }
|
||||||
|
|
Loading…
Reference in New Issue