use super::*;
impl<E: Environment> Cast<Address<E>> for Field<E> {
#[inline]
fn cast(&self) -> Result<Address<E>> {
Address::from_field(self)
}
}
impl<E: Environment> Cast<Boolean<E>> for Field<E> {
#[inline]
fn cast(&self) -> Result<Boolean<E>> {
if self.is_zero() {
Ok(Boolean::new(false))
} else if self.is_one() {
Ok(Boolean::new(true))
} else {
bail!("Failed to convert field to boolean: field element is not zero or one")
}
}
}
impl<E: Environment> Cast<Field<E>> for Field<E> {
#[inline]
fn cast(&self) -> Result<Field<E>> {
Ok(*self)
}
}
impl<E: Environment> Cast<Group<E>> for Field<E> {
#[inline]
fn cast(&self) -> Result<Group<E>> {
Group::from_field(self)
}
}
impl<E: Environment, I: IntegerType> Cast<Integer<E, I>> for Field<E> {
#[inline]
fn cast(&self) -> Result<Integer<E, I>> {
Integer::from_field(self)
}
}
impl<E: Environment> Cast<Scalar<E>> for Field<E> {
#[inline]
fn cast(&self) -> Result<Scalar<E>> {
Scalar::from_field(self)
}
}
impl<E: Environment> Cast<IdentifierLiteral<E>> for Field<E> {
#[inline]
fn cast(&self) -> Result<IdentifierLiteral<E>> {
IdentifierLiteral::from_field(self)
}
}