Skip to content

Commit

Permalink
Add ToConstraintField for bool (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
weikengchen authored Nov 12, 2020
1 parent d0e4077 commit 4a4851d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 10 additions & 0 deletions ff/src/to_field_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ pub trait ToConstraintField<F: Field> {
fn to_field_elements(&self) -> Option<Vec<F>>;
}

impl<F: Field> ToConstraintField<F> for bool {
fn to_field_elements(&self) -> Option<Vec<F>> {
if *self {
Some(vec![F::one()])
} else {
Some(vec![F::zero()])
}
}
}

impl<F: PrimeField> ToConstraintField<F> for F {
fn to_field_elements(&self) -> Option<Vec<F>> {
Some(vec![*self])
Expand Down
5 changes: 1 addition & 4 deletions serialize/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ impl SWFlags {

#[inline]
pub fn is_infinity(&self) -> bool {
match self {
SWFlags::Infinity => true,
_ => false,
}
matches!(self, SWFlags::Infinity)
}

#[inline]
Expand Down

0 comments on commit 4a4851d

Please sign in to comment.