From a98e84e09aaa056c0608516ec6bdc8ae3acb2413 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sun, 7 May 2017 09:39:01 -0600 Subject: [PATCH] Move Cow/Convert out of curves module. --- src/curves/mod.rs | 43 +++++++------------------------------------ src/lib.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/curves/mod.rs b/src/curves/mod.rs index 21b93b7..3fa30f2 100644 --- a/src/curves/mod.rs +++ b/src/curves/mod.rs @@ -1,11 +1,12 @@ use rand; use std::fmt; -use std::ops::Deref; use std::borrow::Borrow; use std::marker::PhantomData; use serde::{Serialize, Deserialize}; +use super::{Cow, Convert}; + pub mod bls381; pub trait Engine: Sized + Clone @@ -199,11 +200,6 @@ pub trait SnarkField: PrimeField fn root_of_unity(&E) -> Self; } -pub struct BitIterator { - t: T, - n: usize -} - pub struct WindowTable> { table: Table, wnaf: Vec, @@ -248,6 +244,11 @@ impl> WindowTable> { } } +pub struct BitIterator { + t: T, + n: usize +} + impl> Iterator for BitIterator { type Item = bool; @@ -276,36 +277,6 @@ impl<'a> From<&'a [u64]> for BitIterator<&'a [u64]> } } -pub enum Cow<'a, T: 'a> { - Owned(T), - Borrowed(&'a T) -} - -impl<'a, T: 'a> Deref for Cow<'a, T> { - type Target = T; - - fn deref(&self) -> &T { - match *self { - Cow::Owned(ref v) => v, - Cow::Borrowed(v) => v - } - } -} - -pub trait Convert { - type Target: Borrow; - - fn convert(&self, &E) -> Cow; -} - -impl Convert for T { - type Target = T; - - fn convert(&self, _: &E) -> Cow { - Cow::Borrowed(self) - } -} - macro_rules! bit_iter_impl( ($n:expr) => { impl From<[u64; $n]> for BitIterator<[u64; $n]> { diff --git a/src/lib.rs b/src/lib.rs index d47ee55..489c98f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,8 @@ pub mod groth16; use std::collections::HashMap; use std::ops; +use std::ops::Deref; +use std::borrow::Borrow; use curves::{Engine, Field}; @@ -149,3 +151,33 @@ pub trait ConstraintSystem { c: LinearCombination ); } + +pub enum Cow<'a, T: 'a> { + Owned(T), + Borrowed(&'a T) +} + +impl<'a, T: 'a> Deref for Cow<'a, T> { + type Target = T; + + fn deref(&self) -> &T { + match *self { + Cow::Owned(ref v) => v, + Cow::Borrowed(v) => v + } + } +} + +pub trait Convert { + type Target: Borrow; + + fn convert(&self, &E) -> Cow; +} + +impl Convert for T { + type Target = T; + + fn convert(&self, _: &E) -> Cow { + Cow::Borrowed(self) + } +}