Skip to content

Commit 20c35fc

Browse files
committed
Format and add function docs
1 parent 030fbb6 commit 20c35fc

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

math/src/field/element.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,10 @@ impl<F: IsPrimeField> FieldElement<F> {
511511
/// Returns a `CreationError::EmptyString` if the input string is empty.
512512
pub fn from_hex(hex_string: &str) -> Result<Self, CreationError> {
513513
if hex_string.is_empty() {
514-
return Err(CreationError::EmptyString)?;
514+
return Err(CreationError::EmptyString);
515515
}
516-
517-
Ok(Self {
518-
value: F::from_hex(hex_string)?,
519-
})
516+
let value = F::from_hex(hex_string)?;
517+
Ok(Self { value })
520518
}
521519

522520
#[cfg(feature = "std")]

math/src/unsigned_integer/element.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl<const NUM_LIMBS: usize> UnsignedInteger<NUM_LIMBS> {
425425
/// Creates an `UnsignedInteger` from a hexstring. It can contain `0x` or not.
426426
/// Returns an `CreationError::InvalidHexString`if the value is not a hexstring.
427427
/// Returns a `CreationError::EmptyString` if the input string is empty.
428+
/// Returns a `CreationError::HexStringIsTooBig` if the the imput hex string is bigger than the maximum amount of characters for this element.
428429
pub fn from_hex(value: &str) -> Result<Self, CreationError> {
429430
let mut string = value;
430431
let mut char_iterator = value.chars();
@@ -447,7 +448,7 @@ impl<const NUM_LIMBS: usize> UnsignedInteger<NUM_LIMBS> {
447448
if string.len() > max_amount_of_hex_chars {
448449
return Err(CreationError::HexStringIsTooBig);
449450
}
450-
451+
451452
Ok(Self::from_hex_unchecked(string))
452453
}
453454

@@ -1258,12 +1259,15 @@ mod tests_u384 {
12581259
fn from_hex_with_overflowing_hexstring_should_error() {
12591260
let u256_from_big_string = U256::from_hex(&"f".repeat(65));
12601261
assert!(u256_from_big_string.is_err());
1261-
assert!(u256_from_big_string == Err(crate::unsigned_integer::element::CreationError::HexStringIsTooBig));
1262+
assert!(
1263+
u256_from_big_string
1264+
== Err(crate::unsigned_integer::element::CreationError::HexStringIsTooBig)
1265+
);
12621266
}
12631267

12641268
#[test]
12651269
fn from_hex_with_non_overflowing_hexstring_should_work() {
1266-
assert_eq!(U256::from_hex(&"0".repeat(64)).unwrap().limbs, [0,0,0,0])
1270+
assert_eq!(U256::from_hex(&"0".repeat(64)).unwrap().limbs, [0, 0, 0, 0])
12671271
}
12681272

12691273
#[test]

0 commit comments

Comments
 (0)