Move Cow/Convert out of curves module.

This commit is contained in:
Sean Bowe
2017-05-07 09:39:01 -06:00
parent 72a386ec34
commit a98e84e09a
2 changed files with 39 additions and 36 deletions

View File

@@ -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<E: Engine> {
c: LinearCombination<E>
);
}
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<T: ?Sized, E> {
type Target: Borrow<T>;
fn convert(&self, &E) -> Cow<Self::Target>;
}
impl<T, E> Convert<T, E> for T {
type Target = T;
fn convert(&self, _: &E) -> Cow<T> {
Cow::Borrowed(self)
}
}