-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Result in several places and solve double deletion problem #260
Conversation
cb6c193
to
97ff65e
Compare
Okay, I think this is ready for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looks ok.
src/error.rs
Outdated
#[derive(Debug)] | ||
pub struct WrongGeneration { | ||
/// The action that failed because of the wrong generation. | ||
pub action: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be an enum or a &'static string?
WrongGeneration(WrongGeneration), | ||
|
||
#[doc(hidden)] | ||
__NonExhaustive, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of breakage would occur without this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a client matches against all the variants and we add one, it would cause an error about non-exhaustive matching. By having this additional variant which should never be used, the user is forced to match against _
. This is a very common pattern (even the standard library uses it, see https://doc.rust-lang.org/src/core/sync/atomic.rs.html#220) and there's an RFC about creating an attribute #[non_exhaustive]
for just this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. I have 2 concerns:
- some clients may be better at tracking the entity lifetimes, so we should provide an unsafe way to delete those without extra checks
- better have an
enum
for the action, like @csherratt noted
@kvark A deletion without checks wouldn't really be unsafe, the semantics are just not clearly defined (whether it panics or it's silently ignored). Benchmarking both versions, I cannot see any difference in performance (it may be the case that other checks are eliminated, idk). So if the difference is smaller than |
* Move BoxedErr out of common module * Add unified Error type * Add WrongGeneration error
Even better then - let's have a safe version that ignores the errors. For ergonomics and this undetectable bit of performance ;) |
So should the |
I'm assuming the latter right now, but it's not clear to me. I added these Here's the previous behavior (without checks):
Given this confusing behavior, I thought that a clear check would be better. So I'm not sure if it makes sense to offer a version without a check at all (as opposed to checking and ignoring). |
Ok, that's convincing enough. Thank you! |
Build succeeded |
Not meant to be merged as is
Fixes #94