tisonkun commented on issue #27:
URL:
https://github.com/apache/datasketches-rust/issues/27#issuecomment-3665881332
Take another example, we now have:
```rust
impl HllSketch {
/// # Panics
///
/// If lg_config_k is not in range [4, 21]
pub fn new(lg_config_k: u8, hll_type: HllType) -> Self {
assert!(
lg_config_k > 4 && lg_config_k < 21,
"lg_config_k must be in [4, 21]"
);
}
}
```
(N.B. @notfilippo This seems a bug that it should be `lg_config_k >= 4 &&
lg_config_k <= 21`)
Users will write:
```rust
// check lg_config_k before hand by any means; typically, it is a user
specified constant.
// then ..
let hll = HllSketch::new(DEFAULT_HLL_K);
```
What if we change the assert to `Result<Self, E>`?
```rust
impl HllSketch {
pub fn new(lg_config_k: u8, hll_type: HllType) -> Result<Self,
SomeError> {
if lg_config_k < 4 || lg_config_k > 21 { return SomeError; }
}
}
```
Then users will write:
```rust
// check lg_config_k before hand by any means
let hll = HllSketch::new(DEFAULT_HLL_K).unwrap();
```
Some Rust method `foo` would have a `try_foo` variant to return SomeError
here instead of letting the caller check the contract. But in many cases, the
contract can be checked.
--
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]