Make opaque Scalar
conversions explicit rather than using From
/Into
trait.
#228
Labels
Scalar
conversions explicit rather than using From
/Into
trait.
#228
Background and Motivation
Currently, the
Scalar
trait requires various conversions using theFrom
andInto
traits. Some of these are confusing, while others are clear.In general, the rule should be that for types with a natural embedding into the associated
Scalar
field,Scalar
should implementFrom
. In all other cases, the conversion should either be auto-implemented, or a trait method, where appropriate.NOTE: The following issue also necessitates changes to Scalar, so be aware of potential merge conflicts:
#234
Changes Required
Each of these should be a separate PR.
Into<[u64; 4]>
,From<[u64; 4]>
, andRefInto<[u64; 4]>
bounds.fn from_limbs(val: [u64; 4]) -> Self
andfn to_limbs(&self) -> [u64; 4]
Scalar
is a field element (number mod some prime) with slightly less than 256 bits. Usually,Scalar
s are internally stored in Montgomery form, so these conversions are non-free. However, they are needed in some situations.From<&'a String>
,From<String>
, andFrom<&'a str>
bounds. These three implementations ultimately rely on the conversions to and from limbs. As a result, these should have blanket/default implementations.fn from_str_via_hash(val: &str) -> Self
and add a default implementation.impl<S: Scalar> From<String> for S
, this is not allowed by the Rust type system. Solutions other than the default implementation of a trait method are welcome.Scalar
itself. This is different from a parsing method.VarInt
bound and replace it with a blanketimpl<S: Scalar> VarInt for S
implementation. The existing (and requested) implementation relies on the limb conversions only.The text was updated successfully, but these errors were encountered: