Skip to main content

Cast

Trait Cast 

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

Unary operator for casting values of one type to another.

Required Methods§

Source

fn cast(&self) -> T

Casts the value of self into a value of type T.

This method checks that the cast does not lose any bits of information.

Implementations on Foreign Types§

Source§

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

Source§

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

Casts a Boolean to a Boolean.

Source§

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

Source§

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

Casts a Field to a Field.

Source§

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

Source§

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

Casts a Scalar to a Scalar.

Source§

impl<E: Environment> Cast for IdentifierLiteral<E>

Source§

fn cast(&self) -> IdentifierLiteral<E>

Casts an IdentifierLiteral to itself.

Source§

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

Source§

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

Casts a Boolean to an Address.

Source§

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

Source§

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

Casts a Field to an Address.

This operation attempts to recover the group element from the field element, and then constructs an address from the group element.

To cast arbitrary field elements to addresses, use Field::cast_lossy.

Source§

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

Source§

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

Casts a Scalar to an Address.

This operation converts the scalar to a field element, and then attempts to recover the group element by treating the field element as an x-coordinate. The group element is then converted to an address.

To cast arbitrary scalars to addresses, use Scalar::cast_lossy.

Source§

impl<E: Environment> Cast<Address<E>> for IdentifierLiteral<E>

Source§

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

Casts an IdentifierLiteral to an Address.

Source§

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

Source§

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

Casts a Field to a Boolean, if the field is zero or one.

To cast arbitrary field elements to booleans, use Field::cast_lossy.

Source§

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

Source§

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

Casts a Scalar to a Boolean, if the scalar is zero or one.

To cast arbitrary scalars to booleans, use Scalar::cast_lossy.

Source§

impl<E: Environment> Cast<Boolean<E>> for IdentifierLiteral<E>

Source§

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

Casts an IdentifierLiteral to a Boolean.

Note: This cast always fails because valid identifier literals cannot map to boolean values (0x00 or 0x01). The byte 0x00 is null and 0x01 (SOH) is not a valid identifier character. This implementation exists for uniformity with the impl_cast_body! macro used by all literal types.

Source§

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

Source§

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

Casts a Boolean to a Field.

Source§

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

Source§

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

Casts a Scalar to a Field.

Source§

impl<E: Environment> Cast<Field<E>> for IdentifierLiteral<E>

Source§

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

Casts an IdentifierLiteral to a Field.

Source§

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

Source§

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

Casts a Boolean to a Group.

Source§

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

Source§

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

Casts a Field to a Group.

This operation attempts to recover the group element from the field element, and returns an error if the field element is not a valid x-coordinate.

To cast arbitrary field elements to groups, use Field::cast_lossy.

Source§

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

Source§

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

Casts a Scalar to a Group.

This operation converts the scalar to a field element, and then attempts to recover the group element by treating the field element as an x-coordinate.

To cast arbitrary scalars to groups, use Scalar::cast_lossy.

Source§

impl<E: Environment> Cast<Group<E>> for IdentifierLiteral<E>

Source§

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

Casts an IdentifierLiteral to a Group.

Source§

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

Source§

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

Casts a Boolean to a Scalar.

Source§

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

Source§

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

Casts a Field to a Scalar, if the field element is in the scalar’s range.

To cast arbitrary field elements to scalars, use Field::cast_lossy.

Source§

impl<E: Environment> Cast<Scalar<E>> for IdentifierLiteral<E>

Source§

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

Casts an IdentifierLiteral to a Scalar.

Source§

impl<E: Environment> Cast<IdentifierLiteral<E>> for Boolean<E>

Source§

fn cast(&self) -> IdentifierLiteral<E>

Casts a Boolean to an IdentifierLiteral.

Note: This cast always fails because valid identifier literals cannot map to boolean values (0x00 or 0x01). The byte 0x00 is null and 0x01 (SOH) is not a valid identifier character. This implementation exists for uniformity with the impl_cast_body! macro used by all literal types.

Source§

impl<E: Environment> Cast<IdentifierLiteral<E>> for Field<E>

Source§

fn cast(&self) -> IdentifierLiteral<E>

Casts a Field to an IdentifierLiteral.

This operation validates that the field element represents a valid identifier literal.

Source§

impl<E: Environment> Cast<IdentifierLiteral<E>> for Scalar<E>

Source§

fn cast(&self) -> IdentifierLiteral<E>

Casts a Scalar to an IdentifierLiteral.

This operation converts the scalar to a field element, and then attempts to create an identifier literal from that field element.

Source§

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

Source§

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

Casts an Integer to another Integer, if the conversion is lossless.

Source§

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

Source§

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

Casts an Integer to an Address.

This operation converts the integer to a field element, and then attempts to recover the group element by treating the field element as an x-coordinate. The group element is then converted to an address.

To cast arbitrary integers to addresses, use Integer::cast_lossy.

Source§

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

Source§

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

Casts an Integer to a Boolean, if the integer is zero or one.

To cast arbitrary integers to booleans, use Integer::cast_lossy.

Source§

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

Source§

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

Casts an Integer to a Field.

Source§

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

Source§

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

Casts an Integer to a Group.

This operation converts the integer to a field element, and then attempts to recover the group element by treating the field element as an x-coordinate.

To cast arbitrary integers to groups, use Integer::cast_lossy.

Source§

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

Source§

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

Casts a Boolean to an Integer.

Source§

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

Source§

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

Casts a Field to an Integer, if the field element is in the integer’s range.

To cast arbitrary field elements to integers, use Field::cast_lossy.

Source§

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

Source§

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

Casts a Scalar to an Integer, if the scalar is in the range of the integer.

To cast arbitrary scalars to integers, via truncation, use Scalar::cast_lossy.

Source§

impl<E: Environment, I: IntegerType> Cast<Integer<E, I>> for IdentifierLiteral<E>

Source§

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

Casts an IdentifierLiteral to an Integer.

Source§

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

Source§

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

Casts an Integer to a Scalar.

Source§

impl<E: Environment, I: IntegerType> Cast<IdentifierLiteral<E>> for Integer<E, I>

Source§

fn cast(&self) -> IdentifierLiteral<E>

Casts an Integer to an IdentifierLiteral.

Implementors§