pub trait Cast<T: Sized = Self> {
// Required method
fn cast(&self) -> T;
}
Expand description
Unary operator for casting values of one type to another.
Casts the value of self
into a value of type T
.
This method checks that the cast does not lose any bits of information.
Casts a Boolean
to a Boolean
.
Casts a Field
to a Field
.
Casts a Scalar
to a Scalar
.
Casts a Boolean
to an Address
.
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
.
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
.
Casts a Field
to a Boolean
, if the field is zero or one.
To cast arbitrary field elements to booleans, use Field::cast_lossy
.
Casts a Scalar
to a Boolean
, if the scalar is zero or one.
To cast arbitrary scalars to booleans, use Scalar::cast_lossy
.
Casts a Boolean
to a Field
.
Casts a Scalar
to a Field
.
Casts a Boolean
to a Group
.
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
.
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
.
Casts a Boolean
to a Scalar
.
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
.
Casts an Integer
to another Integer
, if the conversion is lossless.
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
.
Casts an Integer
to a Boolean
, if the integer is zero or one.
To cast arbitrary integers to booleans, use Integer::cast_lossy
.
Casts an Integer
to a Field
.
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
.
Casts a Boolean
to an Integer
.
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
.
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
.
Casts an Integer
to a Scalar
.