You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement the Deref trait for the BigInt structure to allow users to conveniently access the underlying array.
Context
The Deref trait allows types to be treated like references. By implementing it for BigInt, users can easily access the underlying array when needed. This will simplifies part of the implementations where self.0 is used and can be replaced by self after the implementation.
Proposal
Add a Deref implementation for BigInt with the associated type Target set to [u64; N].
Example
use std::ops::Deref;#[derive(Copy,Clone,PartialEq,Eq,Hash,Zeroize)]pubstructBigInt<constN:usize>(pub[u64;N]);impl<constN:usize>DerefforBigInt<N>{typeTarget = [u64;N];fnderef(&self) -> &Self::Target{&self.0}}fnmain(){let big_int = BigInt::<3>([1,2,3]);// Using Deref to access the underlying arraylet array_ref:&[u64;3] = &*big_int;println!("{:?}", array_ref);// Output: [1, 2, 3]}
The text was updated successfully, but these errors were encountered:
This is behaviour that we want to hide. See, eg, #769
@Pratyush Great then if I understand well the proposed solution I imagine it will make sense to implement Deref for each individual Bs in order to manipulate them then more efficiently what do you think?
Feature Request
Implement the
Deref
trait for theBigInt
structure to allow users to conveniently access the underlying array.Context
The
Deref
trait allows types to be treated like references. By implementing it forBigInt
, users can easily access the underlying array when needed. This will simplifies part of the implementations whereself.0
is used and can be replaced byself
after the implementation.Proposal
Add a
Deref
implementation forBigInt
with the associated typeTarget
set to[u64; N]
.Example
The text was updated successfully, but these errors were encountered: