用藻箱定义AdditiveGroup

时间:2019-01-22 08:17:56

标签: rust

根据alga documentation,这些宏(在alga_traits中定义):

#[derive(Alga)]
#[alga_traits(Group(Additive))]
struct TrivialGroup;

如果特征AbstractGroupAdditiveIdentity和{{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

我应该如何定义我的加成组?

0 个答案:

没有答案