impl_eq_based_self_iso

Macro impl_eq_based_self_iso 

Source
macro_rules! impl_eq_based_self_iso {
    ($type:ty) => { ... };
}
Expand description

Implements the trivial canonical isomorphism Self: CanIsoFromTo<Self> for the given type.

Note that this does not support generic types, as for those, it is usually better to implement

// define `RingConstructor<R: RingStore>`
impl<R, S> CanHomFrom<RingConstructor<S>> for RingConstructor<R>
    where R: RingStore, S: RingStore, R::Type: CanHomFrom<S::Type>
{
    type Homomorphism = <R::Type as CanHomFrom<S::Type>>::Homomorphism;
 
    fn has_canonical_hom(&self, from: &RingConstructor<S>) -> Option<<R::Type as CanHomFrom<S::Type>>::Homomorphism> {
        // delegate to base ring of type `R::Type`
    }
 
    fn map_in(&self, from: &RingConstructor<S>, el: <RingConstructor<S> as RingBase>::Element, hom: &Self::Homomorphism) -> <Self as RingBase>::Element {
        // delegate to base ring of type `R::Type`
    }
}
 
// and same for CanIsoFromTo

or something similar.

ยงExample

 
#[derive(PartialEq, Clone)]
struct MyI32Ring;
 
impl DelegateRing for MyI32Ring {
 
    type Base = StaticRingBase<i32>;
    type Element = i32;
 
    fn get_delegate(&self) -> &Self::Base {
        StaticRing::<i32>::RING.get_ring()
    }
 
    fn delegate_ref<'a>(&self, el: &'a i32) -> &'a i32 {
        el
    }
 
    fn delegate_mut<'a>(&self, el: &'a mut i32) -> &'a mut i32 {
        el
    }
 
    fn delegate(&self, el: i32) -> i32 {
        el
    }
 
    fn postprocess_delegate_mut(&self, _: &mut i32) {
        // sometimes it might be necessary to fix some data of `Self::Element`
        // if the underlying `Self::Base::Element` was modified via `delegate_mut()`;
        // this is not the case here, so leave empty
    }
 
    fn rev_delegate(&self, el: i32) -> i32 {
        el
    }
}
 
// since we provide `PartialEq`, the trait `CanIsoFromTo<Self>` is trivial
// to implement
impl_eq_based_self_iso!{ MyI32Ring }
 
let ring = RingValue::from(MyI32Ring);
assert_el_eq!(ring, ring.int_hom().map(1), ring.one());