Skip to content

Add peek methods to Reader#225

Merged
cpubot merged 1 commit intomasterfrom
add-peek-methods
Mar 11, 2026
Merged

Add peek methods to Reader#225
cpubot merged 1 commit intomasterfrom
add-peek-methods

Conversation

@cpubot
Copy link
Contributor

@cpubot cpubot commented Mar 10, 2026

Following the conversation from #220, this keeps most of the deprecations from #216, but keeps a subset of buffer-implicit methods. Specifically, we have observed that there are various cases where either peek or fill_array can significantly simplify manual SchemaRead implementations.

This PR adds the following methods in an effort to unify Reader method naming:

  • peek_byte - In favor of deprecated peek
  • peek_array - In favor of deprecated fill_array

consume and consume_unchecked are no longer deprecated, as they are necessary counterparts to the peek methods.

All other deprecatations and method renames from #216 are preserved.

The result of this in v0.5 will be a Reader that is less burdensome to implement for io-buffer backends, while still preserving minimal buffering functionality to ease manual SchemaRead implementations.

If we ultimately decide against the context system proposed in #220, this is likely the route forward for now.

@cpubot cpubot requested a review from kskalski March 10, 2026 20:52
/// Errors if fewer than `N` bytes are available.
#[inline]
#[expect(deprecated)]
fn peek_array<const N: usize>(&mut self) -> ReadResult<&[u8; N]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's only a rename.
I'm thinking, maybe we should make both peek_byte and peek_array return value instead of borrowing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For peek_byte, definitely makes sense to return by value since a byte is smaller than a pointer. But, for peek_array I think it's reasonable to let the caller decide whether to dereference based on N

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sounds good.

@cpubot cpubot merged commit fc9e2db into master Mar 11, 2026
4 checks passed
@cpubot cpubot deleted the add-peek-methods branch March 11, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants