Skip to content

Rewrite most of the crate with updated dependencies #9

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

Merged
merged 42 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
64cf77f
Remove almost everything
LukasKalbertodt Jul 3, 2018
a63b0fe
Add `proxy.rs` to parse proxy types
LukasKalbertodt Jul 3, 2018
4825193
Add two simple tests for `proxy.rs`
LukasKalbertodt Jul 3, 2018
bdf8363
Add basic structure
LukasKalbertodt Jul 3, 2018
a85d657
Add simple example to test with
LukasKalbertodt Jul 3, 2018
056e596
Add simple impl generator (still uncomplete)
LukasKalbertodt Jul 4, 2018
8dab34c
Add first code generating the header of the trait impl
LukasKalbertodt Jul 4, 2018
b8e2796
Add a second, unused way to generate the impl header
LukasKalbertodt Jul 4, 2018
96fd682
Remove second way of generating the head and shorten old code
LukasKalbertodt Jul 4, 2018
2f21d62
Fix three bugs in the header generation code
LukasKalbertodt Jul 4, 2018
96d2558
Disable unused code for now to fix warning
LukasKalbertodt Jul 4, 2018
d0acac7
Add basics for generating trait items
LukasKalbertodt Jul 4, 2018
f05169a
Add another example to `simple`
LukasKalbertodt Jul 4, 2018
20639d1
Import proc_macro2::Span as Span2
LukasKalbertodt Jul 4, 2018
fbc13da
Add first version of method_item
LukasKalbertodt Jul 4, 2018
bae0c2c
Add `spanned` module to obtain useful Span information
LukasKalbertodt Jul 4, 2018
a17b02c
Add error checking for self/proxy type combiniations
LukasKalbertodt Jul 4, 2018
c7f0858
Finish generation of method impls (except for Fn*)
LukasKalbertodt Jul 4, 2018
3aa074f
Fix bug in method generation
LukasKalbertodt Jul 5, 2018
c47eebd
Add method to generate associated type impls
LukasKalbertodt Jul 5, 2018
891b7b0
Forbid macro invocations in trait bodies
LukasKalbertodt Jul 5, 2018
e4aa40a
Print error when encountering verbatim-item
LukasKalbertodt Jul 5, 2018
ce89a3a
Rename `items` to `gen_items`
LukasKalbertodt Jul 5, 2018
cbaa7f4
Add `SelfType::from_sig` helper method
LukasKalbertodt Jul 5, 2018
26a965d
Add incomplete function to extract Fn-type from trait
LukasKalbertodt Jul 5, 2018
593a1d5
Finish generation for Fn-traits without args and return type
LukasKalbertodt Jul 5, 2018
da4acfc
Add signature modifier check for Fn traits
LukasKalbertodt Jul 5, 2018
89f39eb
Add extension trait to help with recurring notes on Diagnostics
LukasKalbertodt Jul 5, 2018
118ab60
Finish generation of Fn-type (without correct lifetimes)
LukasKalbertodt Jul 5, 2018
11b9100
Respect local lifetimes and declare them as HRTBs
LukasKalbertodt Jul 7, 2018
15c4e80
Formatting, mostly rustfmt
LukasKalbertodt Jul 7, 2018
200f912
Add two simple examples
LukasKalbertodt Jul 7, 2018
2d982c0
Fix two bugs in impl-generation
LukasKalbertodt Jul 7, 2018
f344b1e
Remove useless code
LukasKalbertodt Jul 7, 2018
e06e863
Remove failing test and leave comment to explain why
LukasKalbertodt Jul 7, 2018
595eed9
Remove testing example
LukasKalbertodt Jul 7, 2018
1322d80
Remove debug output and improve comments in lib.rs
LukasKalbertodt Jul 7, 2018
08ebf33
Remove `extra-traits` feature from syn (only used for debugging)
LukasKalbertodt Jul 7, 2018
565190e
Add minimal documentation
LukasKalbertodt Jul 7, 2018
eb1e38e
Add my name to the list of authors
LukasKalbertodt Jul 7, 2018
fb05e56
Add support for associated consts
LukasKalbertodt Jul 8, 2018
624076f
Update after proc_macro stabilization
LukasKalbertodt Jul 17, 2018
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
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[package]
name = "auto_impl"
version = "0.2.0"
authors = ["Ashley Mannix <[email protected]>"]
authors = [
"Ashley Mannix <[email protected]>",
"Lukas Kalbertodt <[email protected]>",
]
license = "MIT"
description = "Automatically implement traits for common smart pointers and closures"
repository = "https://github.com/KodrAus/auto_impl"
Expand All @@ -17,5 +20,6 @@ travis-ci = { repository = "KodrAus/auto_impl" }
proc-macro = true

[dependencies]
quote = "~0.3"
syn = { version = "~0.11", features = ["full"] }
proc-macro2 = { version = "0.4.6", features = ["nightly"] }
quote = "0.6.3"
syn = { version = "0.14.4", features = ["full"] }
2 changes: 1 addition & 1 deletion compile_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Try running `cargo expand` on this crate to see the output of `#[auto_impl]`.
*/

#![feature(proc_macro)]
#![feature(use_extern_macros)]

extern crate auto_impl;

Expand Down
41 changes: 41 additions & 0 deletions examples/greet_closure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![feature(use_extern_macros)]

extern crate auto_impl;

use auto_impl::auto_impl;


/// This simple trait can be implemented for `Fn` types, but not for `FnMut` or
/// `FnOnce` types. The latter two types require a mutable reference to `self`
/// or a `self` by value to be called, but `greet()` only has an immutable
/// reference. Try creating an auto-impl for `FnMut`: you should get an error.
///
/// This attribute expands to the following impl (not exactly this code, but
/// equivalent, slightly uglier code):
///
/// ```
/// impl<F: Fn(&str)> Greeter for F {
/// fn greet(&self, name: &str) {
/// self(name)
/// }
/// }
/// ```
#[auto_impl(Fn)]
trait Greeter {
fn greet(&self, name: &str);
}


fn greet_people(greeter: impl Greeter) {
greeter.greet("Anna");
greeter.greet("Bob");
}


fn main() {
// We can simply pass a closure here, since this specific closure
// implements `Fn(&str)` and therefore also `Greeter`. Note that we need
// explicit type annotations here. This has nothing to do with `auto_impl`,
// but is simply a limitation of type inference.
greet_people(|name: &str| println!("Hallo {} :)", name));
}
64 changes: 64 additions & 0 deletions examples/refs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![feature(use_extern_macros)]

extern crate auto_impl;

use std::fmt::Display;

use auto_impl::auto_impl;


/// This trait can be implemented for all reference or pointer types: &, &mut,
/// Box, Rc and Arc.
///
/// This attribute expands to the following impl (not exactly this code, but
/// equivalent, slightly uglier code):
///
/// ```
/// impl<'a, T: 'a + DisplayCollection> DisplayCollection for &'a T {
/// type Out = T::Out;
/// fn display_at(&self, index: usize) -> Option<&Self::Out> {
/// (**self).display_at(index)
/// }
/// }
///
/// impl<T: DisplayCollection> DisplayCollection for Box<T> {
/// type Out = T::Out;
/// fn display_at(&self, index: usize) -> Option<&Self::Out> {
/// (**self).display_at(index)
/// }
/// }
/// ```
#[auto_impl(&, Box)]
trait DisplayCollection {
/// If the length is statically known, this is `Some(len)`.
const LEN: Option<usize>;
type Out: Display;
fn display_at(&self, index: usize) -> Option<&Self::Out>;
}

impl<T: Display> DisplayCollection for Vec<T> {
const LEN: Option<usize> = None;
type Out = T;
fn display_at(&self, index: usize) -> Option<&Self::Out> {
self.get(index)
}
}

fn show_first(c: impl DisplayCollection) {
match c.display_at(0) {
Some(x) => println!("First: {}", x),
None => println!("Nothing :/"),
}
}


fn main() {
let v = vec!["dog", "cat"];
let boxed = Box::new(v.clone());

show_first(v.clone()); // Vec<&str> (our manual impl)
show_first(&v); // &Vec<&str> (auto-impl)
show_first(&&v); // &&Vec<&str> (works too, of course)
show_first(boxed.clone()); // Box<Vec<&str>> (auto-impl)
show_first(&boxed); // &Box<Vec<&str>>
}
Loading