Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] add conversion SafePrimitive to QuantumCell::Existing #169

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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