Skip to content

Commit

Permalink
[chore] add conversion SafePrimitive to QuantumCell::Existing (#169)
Browse files Browse the repository at this point in the history
chore: add conversion `SafePrimitive` to `QuantumCell::Existing`
  • Loading branch information
jonathanpwang committed Sep 26, 2023
1 parent e36c45b commit 7acbe4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion halo2-base/src/safe_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
borrow::{Borrow, BorrowMut},
borrow::Borrow,
cmp::{max, min},
};

Expand Down
24 changes: 15 additions & 9 deletions halo2-base/src/safe_types/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::ops::Deref;

use crate::QuantumCell;

use super::*;
/// SafeType for bool (1 bit).
///
Expand All @@ -23,21 +27,17 @@ macro_rules! safe_primitive_impls {
}
}

impl<F: ScalarField> AsMut<AssignedValue<F>> for $SafePrimitive {
fn as_mut(&mut self) -> &mut AssignedValue<F> {
&mut self.0
}
}

impl<F: ScalarField> Borrow<AssignedValue<F>> for $SafePrimitive {
fn borrow(&self) -> &AssignedValue<F> {
&self.0
}
}

impl<F: ScalarField> BorrowMut<AssignedValue<F>> for $SafePrimitive {
fn borrow_mut(&mut self) -> &mut AssignedValue<F> {
&mut self.0
impl<F: ScalarField> Deref for $SafePrimitive {
type Target = AssignedValue<F>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

Expand All @@ -46,6 +46,12 @@ macro_rules! safe_primitive_impls {
safe_primitive.0
}
}

impl<F: ScalarField> From<$SafePrimitive> for QuantumCell<F> {
fn from(safe_primitive: $SafePrimitive) -> Self {
QuantumCell::Existing(safe_primitive.0)
}
}
};
}

Expand Down

0 comments on commit 7acbe4d

Please sign in to comment.