根据alga documentation,这些宏(在alga_traits中定义):
#[derive(Alga)]
#[alga_traits(Group(Additive))]
struct TrivialGroup;
如果特征AbstractGroup
,Additive
,Identity
和{{1的实现,则可以用于通过PartialEq
运算符实现Inverse
标记特征}}。
但是,如果我将它们实现为:
AbstractMagma
编译器仍然认为use alga::general::{AbstractMagma, Additive, AdditiveGroup, Identity, Inverse}; // 0.7.2
use alga_derive::Alga; // 0.7.1
#[derive(Alga, Clone, Copy, PartialEq, Debug)]
#[alga_traits(Group(Additive))]
pub struct TrivialGroup;
impl AbstractMagma<Additive> for TrivialGroup {
fn operate(&self, _right: &Self) -> Self {
TrivialGroup {}
}
}
impl Identity<Additive> for TrivialGroup {
fn identity() -> Self {
TrivialGroup {}
}
}
impl Inverse<Additive> for TrivialGroup {
fn inverse(&self) -> Self {
TrivialGroup {}
}
}
struct Bar<T: AdditiveGroup> {
t: T,
}
fn main() {
let foo = Bar::<TrivialGroup> { t: TrivialGroup {} };
}
不满足TrivialGroup
特质:
AdditiveGroup
我应该如何定义我的加成组?