2010YOUY01 commented on code in PR #23054:
URL: https://github.com/apache/datafusion/pull/23054#discussion_r3447782521
##########
datafusion/common/src/config.rs:
##########
@@ -582,6 +583,87 @@ impl Display for SpillCompression {
}
}
+/// A `usize` configuration value that rejects zero when set from strings.
+///
+/// Use this for options where zero is never a meaningful runtime value. The
+/// default should be constructed with [`ConfigNonZeroUsize::new`] so invalid
+/// defaults fail at compile/test time, while user-provided values return a
+/// configuration error through [`ConfigField`].
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+pub struct ConfigNonZeroUsize(NonZeroUsize);
+
+impl ConfigNonZeroUsize {
+ /// Creates a [`ConfigNonZeroUsize`], panicking if `value` is zero.
+ pub const fn new(value: usize) -> Self {
+ match NonZeroUsize::new(value) {
+ Some(value) => Self(value),
+ None => panic!("value must be greater than 0"),
+ }
+ }
+
+ /// Creates a [`ConfigNonZeroUsize`], returning a configuration error if
+ /// `value` is zero.
+ pub fn try_new(value: usize) -> Result<Self> {
+ NonZeroUsize::new(value).map(Self).ok_or_else(|| {
+ DataFusionError::Configuration("value must be greater than
0".to_string())
Review Comment:
[b37fe74](https://github.com/apache/datafusion/pull/23054/commits/b37fe74d71df09bcc58b4b03e9e3ca4d8a7a3188)
--
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]