#algebra #monoid #abstract-algebra

macro alga_derive

Derive attribute for implementing algebraic traits from the alga crate

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

Download history 744/week @ 2024-05-22 842/week @ 2024-05-29 650/week @ 2024-06-05 531/week @ 2024-06-12 660/week @ 2024-06-19 639/week @ 2024-06-26 106/week @ 2024-07-03 737/week @ 2024-07-10 654/week @ 2024-07-17 720/week @ 2024-07-24 681/week @ 2024-07-31 1086/week @ 2024-08-07 829/week @ 2024-08-14 692/week @ 2024-08-21 828/week @ 2024-08-28 640/week @ 2024-09-04

3,286 downloads per month
Used in 4 crates

Apache-2.0

23KB
426 lines

Build status

Documentation

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:

  • AbstractQuasigroup
  • AbstractMonoid
  • AbstractSemigroup
  • AbstractGroup
  • AbstractGroupAbelian
  • AbstractRing
  • AbstractRingCommutative
  • AbstractField

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:

  • AbstractQuasigroup
  • AbstractMonoid
  • AbstractSemigroup
  • AbstractGroup
  • AbstractGroupAbelian
  • AbstractRing
  • AbstractRingCommutative
  • AbstractField

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