I think it's butter to return a Result for invalid add
Closed this issue · 5 comments
https://github.com/BurntSushi/chan/blob/master/src/wait_group.rs#L57
pub fn add(&self, delta: i32) {
let mut count = self.0.count.lock().unwrap();
*count += delta;
assert!(*count >= 0);
self.0.cond.notify_all();
}
I disagree. But in any case, it doesn't matter. Did you miss the first line of the README? https://github.com/BurntSushi/chan#this-crate-has-reached-its-end-of-life-and-is-now-deprecated
@BurntSushi I think it can constrain the user's usage, but as a lib there should not trigger the panic, the Result
can be returned and the user decides by himself.
but as a lib there should not trigger the panic
This is wrong. It is perfectly idiomatic to set a precondition for library APIs. See RefCell::borrow or str::split_at.
See also: https://blog.burntsushi.net/unwrap/
And this isn't just Rust. Take a look at popular C libraries like PCRE2. There are innumerable ways to provoke UB by giving PCRE2 API functions invalid inputs. Those are preconditions and they are strictly worse than what Rust tends to: panic.
Thanks for your reply.