Allow write guards to be disarmed before drop
- Dominant language
- Rust
- Stars
- 26
- Forks
- 8
- Avg merge
- 16h 41m
- Merged PRs (30d)
- 15
Description
## Problem
Shaq write guards publish their buffer when dropped. If a caller performs a fallible write directly into the buffer, an error can cause the guard to be dropped after only part of the value has been written. The incomplete or invalid buffer is then published to consumers.
For example:
```rust
wincode::serialize_into(guard.as_mut(), &event)?;
```
If serialization fails, error propagation drops the guard and publishes any bytes written before the failure.
## Proposed change
Add a method such as `disarm` or `abort` to write guards:
```rust
let mut guard = producer.write()?;
if let Err(err) = wincode::serialize_into(guard.as_mut(), &event) {
guard.disarm();
return Err(err);
}
```
Dropping an armed guard should preserve the existing publish-on-drop behavior. Dropping a disarmed guard should release or recycle the reserved slot without making its contents visible to consumers.
The change should be implemented for each write guard type in separate sub-issues.
## Acceptance criteria
- Write guards can be explicitly disarmed before they are dropped.
- Dropping an armed guard preserves the existing publish-on-drop behavior.
- Dropping a disarmed guard does not expose its buffer to consumers.
- The reserved slot is safely released or recycled for subsequent writes.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.