Skip to content

Commit 7dd7876

Browse files
committed
Add to_u64 function in corepc-types
1 parent 207e17d commit 7dd7876

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

types/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ pub fn to_u32(value: i64, field: &str) -> Result<u32, NumericError> {
6363
u32::try_from(value).map_err(|_| NumericError::Overflow { value, field: field.to_owned() })
6464
}
6565

66+
/// Converts an `i64` numeric type to a `u64`.
67+
pub fn to_u64(value: i64, field: &str) -> Result<u64, NumericError> {
68+
u64::try_from(value).map_err(|_| NumericError::Negative { value, field: field.to_owned() })
69+
}
70+
6671
/// Error converting an `i64` to a `u32`.
6772
///
6873
/// If we expect a numeric value to sanely fit inside a `u32` we use that type in the `model`

0 commit comments

Comments
 (0)