Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies of async-log-attributes and make it to be optional #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ before_script: |
rustup component add clippy-preview
script: |
cargo fmt -- --check &&
cargo clippy -- -D clippy &&
cargo clippy -- -D all &&
cargo build --verbose &&
cargo test --verbose
cargo build --no-default-features --verbose &&
cargo test --verbose &&
cargo test --no-default-features --verbose
cache: cargo
11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ authors = ["Yoshua Wuyts <[email protected]>"]
readme = "README.md"
edition = "2018"

[features]
default = ["attributes"]
attributes = ["async-log-attributes"]

[dependencies]
log = { version = "0.4.8", features = ["std", "kv_unstable"] }
backtrace = "0.3.34"
async-log-attributes = { path = "async-log-attributes", version = "1.0.1" }
async-log-attributes = { path = "async-log-attributes", version = "1.0.1", optional = true }

[dev-dependencies]
femme = "1.2.0"

[[example]]
name = "trace"
path = "examples/trace.rs"
required-features = ["attributes"]

[workspace]
members = [
".",
Expand Down
6 changes: 3 additions & 3 deletions async-log-attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ edition = "2018"
proc-macro = true

[dependencies]
syn = { version = "0.15.33", features = ["full"] }
proc-macro2 = { version = "0.4.29", features = ["nightly"] }
quote = "0.6.12"
syn = { version = "1.0", features = ["full"] }
proc-macro2 = "1.0"
quote = "1.0"
28 changes: 14 additions & 14 deletions async-log-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#![deny(missing_debug_implementations, nonstandard_style)]
#![recursion_limit = "512"]

extern crate proc_macro;

use proc_macro::TokenStream;
use quote::{quote, quote_spanned};
use syn::spanned::Spanned;
Expand All @@ -17,25 +15,25 @@ pub fn instrument(_attr: TokenStream, item: TokenStream) -> TokenStream {

let attrs = &input.attrs;
let vis = &input.vis;
let constness = &input.constness;
let unsafety = &input.unsafety;
let asyncness = &input.asyncness;
let abi = &input.abi;

let generics = &input.decl.generics;
let name = &input.ident;
let inputs = &input.decl.inputs;
let output = &input.decl.output;
let constness = &input.sig.constness;
let unsafety = &input.sig.unsafety;
let asyncness = &input.sig.asyncness;
let abi = &input.sig.abi;

let generics = &input.sig.generics;
let name = &input.sig.ident;
let inputs = &input.sig.inputs;
let output = &input.sig.output;
let body = &input.block.stmts;

let mut names = String::new();
let mut args = Vec::<syn::Pat>::new();

for fn_arg in inputs {
if let syn::FnArg::Captured(arg) = fn_arg {
if let syn::FnArg::Typed(arg) = fn_arg {
let pat = arg.pat.clone();

if let syn::Pat::Ident(pat_ident) = &pat {
if let syn::Pat::Ident(pat_ident) = &*pat {
names.push_str(&format!(", {}={{:?}}", pat_ident.ident));
} else {
let tokens = quote_spanned! { fn_arg.span() =>
Expand All @@ -44,10 +42,12 @@ pub fn instrument(_attr: TokenStream, item: TokenStream) -> TokenStream {
return TokenStream::from(tokens);
}

args.push(pat);
args.push(*pat);
}
}

let inputs = inputs.iter();

let result = quote! {
#(#attrs)*
#vis #constness #unsafety #asyncness #abi fn #name #generics (#(#inputs)*) #output {
Expand Down
21 changes: 11 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,27 @@
//! .unwrap();
//! }
//!
//! fn main() {
//! setup_logger();
//!
//! span!("new level, depth={}", 1, {
//! let x = "beep";
//! info!("look at this value, x={}", x);
//! setup_logger();
//!
//! span!("new level, depth={}", 2, {
//! let y = "boop";
//! info!("another nice value, y={}", y);
//! })
//! span!("new level, depth={}", 1, {
//! let x = "beep";
//! info!("look at this value, x={}", x);
//!
//! span!("new level, depth={}", 2, {
//! let y = "boop";
//! info!("another nice value, y={}", y);
//! })
//! }
//! })
//!
//! ```

#![forbid(unsafe_code, future_incompatible, rust_2018_idioms)]
#![deny(missing_debug_implementations, nonstandard_style)]
#![warn(missing_docs, unreachable_pub)]
#![cfg_attr(test, deny(warnings))]

#[cfg(feature = "attributes")]
pub use async_log_attributes::instrument;

use std::fmt::Arguments;
Expand Down