Trait feanor_math::delegate::DelegateRing

source ·
pub trait DelegateRing: PartialEq {
    type Base: ?Sized + RingBase;
    type Element;

    // Required methods
    fn get_delegate(&self) -> &Self::Base;
    fn delegate_ref<'a>(
        &self,
        el: &'a Self::Element
    ) -> &'a <Self::Base as RingBase>::Element;
    fn delegate_mut<'a>(
        &self,
        el: &'a mut Self::Element
    ) -> &'a mut <Self::Base as RingBase>::Element;
    fn delegate(&self, el: Self::Element) -> <Self::Base as RingBase>::Element;
    fn rev_delegate(
        &self,
        el: <Self::Base as RingBase>::Element
    ) -> Self::Element;

    // Provided methods
    fn postprocess_delegate_mut(&self, el: &mut Self::Element) { ... }
    fn element_cast(&self, el: Self::Element) -> <Self as RingBase>::Element { ... }
    fn rev_element_cast(&self, el: <Self as RingBase>::Element) -> Self::Element { ... }
}
Expand description

Trait to simplify implementing newtype-pattern for rings. When you want to create a ring that just wraps another ring, possibly adding some functionality, you can implement DelegateRing instead of RingBase, and just provide how to map elements in the new ring to the wrapped ring and vice versa.

§Example

 
#[derive(PartialEq, Clone, Copy)]
struct MyI32Ring;
struct MyI32RingEl(i32);
 
impl DelegateRing for MyI32Ring {
 
    type Base = StaticRingBase<i32>;
    type Element = MyI32RingEl;
 
    fn get_delegate(&self) -> &Self::Base {
        StaticRing::<i32>::RING.get_ring()
    }
 
    fn delegate_ref<'a>(&self, MyI32RingEl(el): &'a MyI32RingEl) -> &'a i32 {
        el
    }
 
    fn delegate_mut<'a>(&self, MyI32RingEl(el): &'a mut MyI32RingEl) -> &'a mut i32 {
        el
    }
 
    fn delegate(&self, MyI32RingEl(el): MyI32RingEl) -> i32 {
        el
    }
 
    fn postprocess_delegate_mut(&self, _: &mut MyI32RingEl) {
        // 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) -> MyI32RingEl {
        MyI32RingEl(el)
    }
}
 
// you will have to implement `CanIsoFromTo<Self>`
impl_eq_based_self_iso!{ MyI32Ring }
 
let ring = RingValue::from(MyI32Ring);
assert_el_eq!(&ring, &ring.int_hom().map(1), &ring.one());

Required Associated Types§

Required Methods§

source

fn get_delegate(&self) -> &Self::Base

source

fn delegate_ref<'a>( &self, el: &'a Self::Element ) -> &'a <Self::Base as RingBase>::Element

source

fn delegate_mut<'a>( &self, el: &'a mut Self::Element ) -> &'a mut <Self::Base as RingBase>::Element

source

fn delegate(&self, el: Self::Element) -> <Self::Base as RingBase>::Element

source

fn rev_delegate(&self, el: <Self::Base as RingBase>::Element) -> Self::Element

Provided Methods§

source

fn postprocess_delegate_mut(&self, el: &mut Self::Element)

source

fn element_cast(&self, el: Self::Element) -> <Self as RingBase>::Element

Necessary in some locations to satisfy the type system

source

fn rev_element_cast(&self, el: <Self as RingBase>::Element) -> Self::Element

Necessary in some locations to satisfy the type system

Object Safety§

This trait is not object safe.

Implementors§

source§

impl DelegateRing for feanor_math::rings::zn::zn_42::ZnFastmulBase

source§

impl DelegateRing for feanor_math::rings::zn::zn_64::ZnFastmulBase

source§

impl<R: DivisibilityRingStore> DelegateRing for AsFieldBase<R>

§

type Element = FieldEl<R>

§

type Base = <R as RingStore>::Type