Skip to content

Commit 7caed6e

Browse files
gyscosclaude
andcommitted
Derive the usual traits on ResetDirective
It was the only public enum in the crate with no derives at all, while FrameFormat, DictAttachPref, ParamSwitch, CParameter and DParameter all derive Copy, Clone, Debug, PartialEq and Eq - CParameter and DParameter even though they carry data. Being Copy also means as_sys() no longer consumes the directive, so the reset methods can just ask it whether it drops the session rather than working that out beforehand. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TeZDBS4Uw5kdF77tkJ7cAe
1 parent bf7b1f7 commit 7caed6e

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

‎zstd-safe/src/lib.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,10 @@ impl<'a> CCtx<'a> {
642642
/// Wraps the `ZSTD_CCtx_reset()` function.
643643
pub fn reset(&mut self, reset: ResetDirective) -> SafeResult {
644644
// Safety: Just FFI
645-
let resets_session = reset.resets_session();
646645
let res = parse_code(unsafe {
647646
zstd_sys::ZSTD_CCtx_reset(self.0.as_ptr(), reset.as_sys())
648647
});
649-
if res.is_ok() && resets_session {
648+
if res.is_ok() && reset.resets_session() {
650649
self.2.clear();
651650
}
652651
res
@@ -1126,11 +1125,10 @@ impl<'a> DCtx<'a> {
11261125
///
11271126
/// Wraps the `ZSTD_DCtx_reset()` function.
11281127
pub fn reset(&mut self, reset: ResetDirective) -> SafeResult {
1129-
let resets_session = reset.resets_session();
11301128
let res = parse_code(unsafe {
11311129
zstd_sys::ZSTD_DCtx_reset(self.0.as_ptr(), reset.as_sys())
11321130
});
1133-
if res.is_ok() && resets_session {
1131+
if res.is_ok() && reset.resets_session() {
11341132
self.2.clear();
11351133
}
11361134
res
@@ -2162,6 +2160,7 @@ pub fn get_dict_id_from_frame(src: &[u8]) -> Option<NonZeroU32> {
21622160
}
21632161

21642162
/// What kind of context reset should be applied.
2163+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
21652164
pub enum ResetDirective {
21662165
/// Only the session will be reset.
21672166
///
@@ -2191,7 +2190,7 @@ impl ResetDirective {
21912190
/// Only a session reset brings a context back from the undefined state an
21922191
/// error can leave it in - `Parameters` alone is refused while a session is
21932192
/// open.
2194-
fn resets_session(&self) -> bool {
2193+
fn resets_session(self) -> bool {
21952194
matches!(
21962195
self,
21972196
ResetDirective::SessionOnly | ResetDirective::SessionAndParameters

0 commit comments

Comments
 (0)