adriangb commented on code in PR #24483:
URL: https://github.com/apache/datafusion/pull/24483#discussion_r3867699750
##########
datafusion/common/src/utils/mod.rs:
##########
@@ -1142,6 +1144,32 @@ pub fn combine_limit(
(combined_skip, combined_fetch)
}
+/// Converts a wire integer to `usize`, rejecting out-of-range values.
+/// `context` and `field` identify the value in the error message.
+pub fn usize_from_wire<T>(value: T, context: &str, field: &str) ->
Result<usize>
+where
+ T: TryInto<usize> + std::fmt::Display + Copy,
+{
+ value.try_into().map_err(|_| {
+ _plan_datafusion_err!(
+ "{context}: {field} wire value {value} is out of range for usize"
+ )
+ })
+}
+
+/// Converts a `usize` to a wire integer, rejecting out-of-range values.
+pub fn usize_to_wire<T: TryFrom<usize>>(
Review Comment:
Do these need to be public in this crate, or is there a version where
they're private and close the the callers? I'd almost prefer to duplicate a
small helper like this in 2 crates than expose it to the public API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]