10 releases
Uses old Rust 2015
| 0.9.2 | Mar 2, 2020 |
|---|---|
| 0.9.1 | May 11, 2019 |
| 0.9.0 | Mar 31, 2019 |
| 0.7.1 | Sep 13, 2018 |
| 0.5.0 | Mar 29, 2017 |
#11 in #abstract-algebra
3,286 downloads per month
Used in 4 crates
23KB
426 lines
alga-derive − automatic deriving of abstract algebra traits for Rust
alga-derive allows automatic deriving of traits provided by alga.
It supports deriving following alga traits:
AbstractQuasigroupAbstractMonoidAbstractSemigroupAbstractGroupAbstractGroupAbelianAbstractRingAbstractRingCommutativeAbstractField
The custom derive can also be used to generate quickcheck tests that check that algebraic properties are satisfied by the target of the derive.
lib.rs:
alga-derive
Custom derive for alga traits.
Supported traits:
AbstractQuasigroupAbstractMonoidAbstractSemigroupAbstractGroupAbstractGroupAbelianAbstractRingAbstractRingCommutativeAbstractField
Examples
extern crate alga;
#[macro_use]
extern crate alga_derive;
use alga::general::Additive;
#[derive(Alga)]
#[alga_traits(Group(Additive))]
struct Struct;
This derive implements AbstractGroup marker trait with Additive operator and all
marker traits required by the algebraic groupness property
(AbstractMonoid, AbstractSemigroup, AbstractLoop and AbstractQuasigroup) for the target of the derive.
Traits required by these marker traits (Identity, PartialEq, TwoSidedInverse and AbstractMagma) should be implemented manually.
If #[alga_quickcheck] attribute is added for the target of the derive,
then quickcheck tests will be generated.
These tests will check that the algebraic properties of the derived trait are true for the type.
This attribute requires quickchecks Arbitrary trait to be implemented for the target of the derive.
extern crate alga;
#[macro_use]
extern crate alga_derive;
use alga::general::{Additive, AbstractGroup};
#[derive(Alga)]
#[alga_traits(Group(Additive), Where = "T: AbstractGroup")]
#[alga_quickcheck(check(i32), check(i64))]
struct Struct<T>;
When there is generic parameters on the target of the derive,
then all the concrete type parameters that the tests are generated for can be specified in
alga_quickcheck attribute by listing them in checks.
If bounds are required for the alga traits to be implemented,
they can be listed by Where = "A: Bound1. B: Bound2".
Dependencies
~3MB
~57K SLoC