File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
//! Generic Field Traits
4
4
5
+ use core:: convert:: TryInto ;
5
6
use core:: iter:: { Skip , Take } ;
6
7
use core:: { fmt, hash, iter, ops} ;
7
8
@@ -153,7 +154,7 @@ pub trait Field:
153
154
154
155
/// Trait describing a simple extension field (field obtained from another by
155
156
/// adjoining one element).
156
- pub trait ExtensionField : Field + From < Self :: BaseField > {
157
+ pub trait ExtensionField : Field + From < Self :: BaseField > + TryInto < Self :: BaseField > {
157
158
/// The type of the base field.
158
159
type BaseField : Field ;
159
160
Original file line number Diff line number Diff line change @@ -37,6 +37,19 @@ impl<const DEG: usize> From<Fe32> for Fe32Ext<DEG> {
37
37
}
38
38
}
39
39
40
+ impl < const DEG : usize > core:: convert:: TryFrom < Fe32Ext < DEG > > for Fe32 {
41
+ type Error = ( ) ;
42
+
43
+ fn try_from ( ext : Fe32Ext < DEG > ) -> Result < Self , Self :: Error > {
44
+ for elem in & ext. inner [ 1 ..] {
45
+ if * elem != Fe32 :: Q {
46
+ return Err ( ( ) ) ;
47
+ }
48
+ }
49
+ Ok ( ext. inner [ 0 ] )
50
+ }
51
+ }
52
+
40
53
impl < const DEG : usize > fmt:: Debug for Fe32Ext < DEG > {
41
54
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result { fmt:: Display :: fmt ( self , f) }
42
55
}
You can’t perform that action at this time.
0 commit comments