pub trait IntAccess {
// Required methods
fn as_i64(&self) -> Option<i64>;
fn as_big_int(&self) -> Option<&BigInt>;
}
Expand description
Provides convenient integer accessors for integer values that are like Int
Required Methods§
sourcefn as_i64(&self) -> Option<i64>
fn as_i64(&self) -> Option<i64>
Returns the value as an i64
if it can be represented as such.
Usage
let big_int = Int::BigInt(BigInt::from(100));
let i64_int = Int::I64(100);
assert_eq!(big_int.as_i64(), i64_int.as_i64());
// works on element too
let big_elem: Element = big_int.into();
let i64_elem: Element = i64_int.into();
assert_eq!(big_elem.as_i64(), i64_elem.as_i64());
sourcefn as_big_int(&self) -> Option<&BigInt>
fn as_big_int(&self) -> Option<&BigInt>
Returns a reference as a BigInt
if it is represented as such. Note that this
method may return None
if the underlying representation is not stored in a BigInt
such as if it is represented as an i64
so it is somewhat asymmetric with respect
to IntAccess::as_i64
.
Usage
let big_int = Int::BigInt(BigInt::from(100));
assert_eq!(
BigInt::from_str("100").unwrap(),
*big_int.as_big_int().unwrap()
);
let i64_int = Int::I64(100);
assert_eq!(None, i64_int.as_big_int());
// works on element too
let big_elem: Element = big_int.into();
assert_eq!(
BigInt::from_str("100").unwrap(),
*big_elem.as_big_int().unwrap()
);
let i64_elem: Element = i64_int.into();
assert_eq!(None, i64_elem.as_big_int());