Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
upgrade syn and quote deps
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jul 20, 2018
1 parent 0d8c6f8 commit 90a06be
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 392 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Changes

## 0.2.1 (2018-07-20)
## 0.3.0 (2018-07-20)

* Fix warning in rustc 1.29.0-nightly #9

* Remove nightly support


## 0.2.0 (2018-02-xx)

Expand Down
12 changes: 4 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "actix_derive"
version = "0.2.1"
version = "0.3.0"
authors = ["Callym <hi@callym.com>", "Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actor framework for Rust"
readme = "README.md"
Expand All @@ -10,15 +10,11 @@ repository = "https://github.com/actix/actix-derive.git"
documentation = "https://docs.rs/actix-derive/"
license = "MIT/Apache-2.0"
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
build = "build.rs"

[lib]
proc-macro = true

[dependencies]
quote = "0.3"
rand = "0.5"
syn = { version="0.11", features=["full"] }

[build-dependencies]
version_check = "0.1"
quote = "0.6"
syn = { version="0.14", features=["full"] }
proc-macro2 = "0.4"
10 changes: 0 additions & 10 deletions build.rs

This file was deleted.

5 changes: 5 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
max_width = 89
reorder_imports = true
#wrap_comments = true
fn_args_density = "Compressed"
#use_small_heuristics = false
231 changes: 0 additions & 231 deletions src/actor.rs

This file was deleted.

78 changes: 6 additions & 72 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,83 +1,17 @@
#![cfg_attr(actix_nightly, feature(proc_macro,))]

extern crate rand;
extern crate proc_macro;
extern crate proc_macro2;
extern crate syn;
#[macro_use] extern crate quote;
#[macro_use]
extern crate quote;

use std::str::FromStr;
use proc_macro::TokenStream;
use quote::{Tokens, ToTokens};
use syn::DeriveInput;

mod actor;
mod message;

#[doc(hidden)]
#[proc_macro_derive(Message, attributes(rtype))]
pub fn message_derive_rtype(input: TokenStream) -> TokenStream {
let s = input.to_string();
let ast = syn::parse_derive_input(&s).unwrap();
message::expand(&ast).parse().expect("Expanded output was no correct Rust code")
}

#[cfg(actix_nightly)]
#[proc_macro_attribute]
pub fn actor(attr: TokenStream, input: TokenStream) -> TokenStream {
// Construct a string representation of the type definition
let source = input.to_string();

let mut ctx = None;
let attr = attr.to_string();
if !attr.is_empty() {
let p = &attr[1..attr.len()-1];
if !p.is_empty() {
let p = p.replace('_', "Self");
ctx = Some(syn::parse_path(&p).expect("Can not parse actor's context type"));
}
}

// Parse the string representation into a syntax tree
let mut ast = syn::parse_item(&source).unwrap();

// Build the output
let expanded = actor::build_handler(&mut ast, ctx);

// Return the generated impl as a TokenStream
let mut tokens = Tokens::new();
ast.to_tokens(&mut tokens);
let s = String::from(tokens.as_str()) + expanded.as_str();

TokenStream::from_str(s.as_str()).unwrap()
}

#[cfg(actix_nightly)]
#[proc_macro_attribute]
pub fn msg(attr: TokenStream, input: TokenStream) -> TokenStream {
// Construct a string representation of the type definition
let source = input.to_string();

let mut types = Vec::new();
let attr = attr.to_string();
if !attr.is_empty() {
let p = &attr[1..attr.len()-1];
if !p.is_empty() {
for p in p.split(',') {
types.push(
syn::parse_path(&p).expect("Can not parse actor's context type"));
}
}
}

// Parse the string representation into a syntax tree
let mut ast = syn::parse_item(&source).unwrap();

// Build the output
let expanded = message::message_attr(&mut ast, types);

// Return the generated impl as a TokenStream
let mut tokens = Tokens::new();
ast.to_tokens(&mut tokens);
let s = String::from(tokens.as_str()) + expanded.as_str();
let ast: DeriveInput = syn::parse(input).unwrap();

TokenStream::from_str(s.as_str()).unwrap()
message::expand(&ast).into()
}
Loading

0 comments on commit 90a06be

Please sign in to comment.