snarkvm_circuit_program

Trait CastLossy

Source
pub trait CastLossy<T: Sized = Self> {
    // Required method
    fn cast_lossy(&self) -> T;
}
Expand description

Unary operator for casting values of one type to another, with lossy truncation.

Required Methods§

Source

fn cast_lossy(&self) -> T

Casts the value of self into a value of type T, with lossy truncation.

This method makes a best-effort attempt to preserve all bits of information, but it is not guaranteed to do so.

Implementations on Foreign Types§

Source§

impl<E: Environment> CastLossy for Boolean<E>

Source§

fn cast_lossy(&self) -> Boolean<E>

Casts a Boolean to a Boolean. This is an identity cast, so it is always lossless.

Source§

impl<E: Environment> CastLossy for Field<E>

Source§

fn cast_lossy(&self) -> Field<E>

Casts a Field to a Field. This is an identity cast, so it is always lossless.

Source§

impl<E: Environment> CastLossy for Scalar<E>

Source§

fn cast_lossy(&self) -> Scalar<E>

Casts a Scalar to a Scalar. This is an identity cast, so it is always lossless.

Source§

impl<E: Environment> CastLossy<Address<E>> for Boolean<E>

Source§

fn cast_lossy(&self) -> Address<E>

Casts a Boolean to an Address. This is safe because casting from a boolean to any other type is always lossless.

If the boolean is true, the address is the generator of the prime-order subgroup. If the boolean is false, the address is the zero group element.

Source§

impl<E: Environment> CastLossy<Address<E>> for Field<E>

Source§

fn cast_lossy(&self) -> Address<E>

Casts a Field to an Address.

This operation attempts to recover the group element from the given field, which is then used to construct the address. See the documentation of Field::cast_lossy on the Group type for more details.

Source§

impl<E: Environment> CastLossy<Address<E>> for Scalar<E>

Source§

fn cast_lossy(&self) -> Address<E>

Casts a Scalar to an Address.

This operation converts the scalar into a field element, and then attempts to recover the group element to construct the address. See the documentation of Field::cast_lossy on the Group type for more details.

Source§

impl<E: Environment> CastLossy<Boolean<E>> for Field<E>

Source§

fn cast_lossy(&self) -> Boolean<E>

Casts a Field to a Boolean, with lossy truncation. This operation returns the least significant bit of the field.

Source§

impl<E: Environment> CastLossy<Boolean<E>> for Scalar<E>

Source§

fn cast_lossy(&self) -> Boolean<E>

Casts a Scalar to a Boolean, with lossy truncation. This operation returns the least significant bit of the scalar.

Source§

impl<E: Environment> CastLossy<Field<E>> for Boolean<E>

Source§

fn cast_lossy(&self) -> Field<E>

Casts a Boolean to a Field. This is safe because casting from a boolean to any other type is always lossless.

Source§

impl<E: Environment> CastLossy<Field<E>> for Scalar<E>

Source§

fn cast_lossy(&self) -> Field<E>

Casts a Scalar to a Field. This operation is always lossless.

Source§

impl<E: Environment> CastLossy<Group<E>> for Boolean<E>

Source§

fn cast_lossy(&self) -> Group<E>

Casts a Boolean to a Group. This is safe because casting from a boolean to any other type is always lossless.

If the boolean is true, the group element is the generator of the prime-order subgroup. If the boolean is false, the group element is the zero group element.

Source§

impl<E: Environment> CastLossy<Group<E>> for Field<E>

Source§

fn cast_lossy(&self) -> Group<E>

Casts a Field to a Group.

This operation attempts to recover the group element from the given field.

If the field is a valid x-coordinate, then the group element is returned. If the field is not a valid x-coordinate, then if the field is the one element, the generator of the prime-order subgroup is returned. Otherwise, Elligator-2 is applied to the field element to recover a group element.

Source§

impl<E: Environment> CastLossy<Group<E>> for Scalar<E>

Source§

fn cast_lossy(&self) -> Group<E>

Casts a Scalar to a Group.

This operation converts the scalar into a field element, and then attempts to recover the group element. See the documentation of Field::cast_lossy on the Group type for more details.

Source§

impl<E: Environment> CastLossy<Scalar<E>> for Boolean<E>

Source§

fn cast_lossy(&self) -> Scalar<E>

Casts a Boolean to a Scalar. This is safe because casting from a boolean to any other type is always lossless.

Source§

impl<E: Environment> CastLossy<Scalar<E>> for Field<E>

Source§

fn cast_lossy(&self) -> Scalar<E>

Casts a Field to a Scalar, with lossy truncation. This operation truncates the field to a scalar.

Source§

impl<E: Environment, I0: IntegerType, I1: IntegerType> CastLossy<Integer<E, I1>> for Integer<E, I0>

Source§

fn cast_lossy(&self) -> Integer<E, I1>

Casts an Integer to an Integer of a different type, with lossy truncation.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Address<E>> for Integer<E, I>

Source§

fn cast_lossy(&self) -> Address<E>

Casts an Integer to an Address.

This operation converts the integer into a field element, and then attempts to recover the group element to construct the address. See the documentation of Field::cast_lossy on the Group type for more details.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Boolean<E>> for Integer<E, I>

Source§

fn cast_lossy(&self) -> Boolean<E>

Casts an Integer to a Boolean, with lossy truncation. This operation returns the least significant bit of the field.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Field<E>> for Integer<E, I>

Source§

fn cast_lossy(&self) -> Field<E>

Casts an Integer to a Field. This is safe because casting from an integer to a field is always lossless.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Group<E>> for Integer<E, I>

Source§

fn cast_lossy(&self) -> Group<E>

Casts an Integer to a Group.

This operation converts the integer into a field element, and then attempts to recover the group element. See the documentation of Field::cast_lossy on the Group type for more details.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Integer<E, I>> for Boolean<E>

Source§

fn cast_lossy(&self) -> Integer<E, I>

Casts a Boolean to an Integer.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Integer<E, I>> for Field<E>

Source§

fn cast_lossy(&self) -> Integer<E, I>

Casts a Field to an Integer, with lossy truncation. This operation truncates the field to an integer.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Integer<E, I>> for Scalar<E>

Source§

fn cast_lossy(&self) -> Integer<E, I>

Casts a Scalar to an Integer, with lossy truncation.

Source§

impl<E: Environment, I: IntegerType> CastLossy<Scalar<E>> for Integer<E, I>

Source§

fn cast_lossy(&self) -> Scalar<E>

Casts an Integer to a Scalar. This is safe because casting from an integer to a scalar is always lossless.

Implementors§