Skip to content

Commit

Permalink
Merge pull request #1 from kas-gui/work
Browse files Browse the repository at this point in the history
Prepare 0.1.0
  • Loading branch information
dhardy authored Mar 21, 2022
2 parents badc902 + da4c7e8 commit f2b62a8
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 14 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,38 @@ jobs:
- name: Clippy
run: cargo clippy --all

test:
name: Test MSRV
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
toolchain: [stable]
include:
- os: ubuntu-latest
toolchain: "1.56.0"
stable:
name: Stable on Windows
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
toolchain: stable
override: true
components: clippy

- name: Test
run: cargo test --all-features
- name: Clippy (stable)
run: cargo clippy --all -- -D warnings -A unknown_lints

msrv:
name: MSRV
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: "1.56.0"
override: true
components: clippy

- name: Test
run: cargo test --all-features --lib --tests
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] — 2022-03-21

New release, including the `autoimpl` macro (extracted from `kas-macros` crate).
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "impl-tools"
version = "0.0.0"
version = "0.1.0"
authors = ["Diggory Hardy <[email protected]>"]
edition = "2021"
license = "MIT/Apache-2.0"
description = "A set of helper macros"
description = "Helper macros: autoimpl"
keywords = ["proc-macro", "macro", "derive", "trait", "procedural"]
categories = ["development-tools::procedural-macro-helpers"]
repository = "https://github.com/kas-gui/impl-tools"
Expand All @@ -24,3 +24,6 @@ version = "1.0.14"
# We need 'extra-traits' for equality testing
# We need 'full' for parsing macros within macro arguments
features = ["extra-traits", "full"]

[dev-dependencies]
doc-comment = "0.3.3"
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,59 @@ Impltools
A set of helper macros


Macros
------

### Autoimpl

`#[autoimpl]` is a variant of `#[derive]`, supporting:

- explicit generic parameter bounds
- ignored fields
- traits defined using a primary field
- generic re-implementations for traits

```rust
# use impl_tools::autoimpl;
# use std::fmt::Debug;

#[autoimpl(for<'a, T: trait + ?Sized> Box<T>)]
// Generates: impl<'a, T: trait + ?Sized> Animal for Box<T> { .. }
trait Animal {
fn number_of_legs(&self) -> u32;
}

#[autoimpl(Debug ignore self.animal where T: Debug)]
// Generates: impl<T, A: Animal> std::fmt::Debug for Named<A> where T: Debug { .. }
#[autoimpl(Deref, DerefMut using self.animal)]
// Generates: impl<T, A: Animal> std::ops::Deref for Named<A> { .. }
// Generates: impl<T, A: Animal> std::ops::DerefMut for Named<A> { .. }
struct Named<T, A: Animal> {
name: T,
animal: A,
}

fn main() {
struct Fish;
impl Animal for Fish {
fn number_of_legs(&self) -> u32 {
0
}
}

let my_fish = Named {
name: "Nemo",
animal: Box::new(Fish),
};

assert_eq!(
format!("{my_fish:?} has {} legs!", my_fish.number_of_legs()),
r#"Named { name: "Nemo", .. } has 0 legs!"#
);
}
```


Minimum Supported Rust Version
------------------------------

Expand Down
52 changes: 52 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,58 @@
// https://www.apache.org/licenses/LICENSE-2.0

//! # Impl-tools
//!
//! ## Autoimpl
//!
//! `#[autoimpl]` is a variant of `#[derive]`, supporting:
//!
//! - explicit generic parameter bounds
//! - ignored fields
//! - traits defined using a primary field
//! - generic re-implementations for traits
//!
//! ```
//! # use impl_tools::autoimpl;
//! # use std::fmt::Debug;
//!
//! #[autoimpl(for<'a, T: trait + ?Sized> Box<T>)]
//! // Generates: impl<'a, T: trait + ?Sized> Animal for Box<T> { .. }
//! trait Animal {
//! fn number_of_legs(&self) -> u32;
//! }
//!
//! #[autoimpl(Debug ignore self.animal where T: Debug)]
//! // Generates: impl<T, A: Animal> std::fmt::Debug for Named<A> where T: Debug { .. }
//! #[autoimpl(Deref, DerefMut using self.animal)]
//! // Generates: impl<T, A: Animal> std::ops::Deref for Named<A> { .. }
//! // Generates: impl<T, A: Animal> std::ops::DerefMut for Named<A> { .. }
//! struct Named<T, A: Animal> {
//! name: T,
//! animal: A,
//! }
//!
//! fn main() {
//! struct Fish;
//! impl Animal for Fish {
//! fn number_of_legs(&self) -> u32 {
//! 0
//! }
//! }
//!
//! let my_fish = Named {
//! name: "Nemo",
//! animal: Box::new(Fish),
//! };
//!
//! assert_eq!(
//! format!("{my_fish:?} has {} legs!", my_fish.number_of_legs()),
//! r#"Named { name: "Nemo", .. } has 0 legs!"#
//! );
//! }
//! ```
#[cfg(doctest)]
doc_comment::doctest!("../README.md");

extern crate proc_macro;

Expand Down

0 comments on commit f2b62a8

Please sign in to comment.