Skip to content
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

deer: add *Access::context() #2443

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libs/deer/desert/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use deer::{
ArrayAccessError, ArrayLengthError, BoundedContractViolationError, ExpectedLength,
ReceivedLength, Variant,
},
Deserialize, Deserializer as _,
Context, Deserialize, Deserializer as _,
};
use error_stack::{Report, Result, ResultExt};

Expand Down Expand Up @@ -57,6 +57,10 @@ impl<'a, 'b, 'de> ArrayAccess<'a, 'b, 'de> {
}

impl<'de> deer::ArrayAccess<'de> for ArrayAccess<'_, '_, 'de> {
fn context(&self) -> &Context {
self.deserializer.context()
}

fn set_bounded(&mut self, length: usize) -> Result<(), ArrayAccessError> {
if self.consumed > 0 {
return Err(
Expand Down
6 changes: 5 additions & 1 deletion libs/deer/desert/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use deer::{
BoundedContractViolationError, ExpectedLength, ObjectAccessError, ObjectLengthError,
ReceivedLength, Variant,
},
Deserializer as _, FieldVisitor,
Context, Deserializer as _, FieldVisitor,
};
use error_stack::{Report, Result, ResultExt};

Expand Down Expand Up @@ -57,6 +57,10 @@ impl<'a, 'b, 'de: 'a> ObjectAccess<'a, 'b, 'de> {
}

impl<'de> deer::ObjectAccess<'de> for ObjectAccess<'_, '_, 'de> {
fn context(&self) -> &Context {
self.deserializer.context()
}

fn set_bounded(&mut self, length: usize) -> Result<(), ObjectAccessError> {
if self.consumed > 0 {
return Err(
Expand Down
8 changes: 8 additions & 0 deletions libs/deer/json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ impl<'a> ArrayAccess<'a> {
}

impl<'a, 'de> deer::ArrayAccess<'de> for ArrayAccess<'a> {
fn context(&self) -> &Context {
self.context
}

fn set_bounded(&mut self, length: usize) -> Result<(), ArrayAccessError> {
if self.dirty {
return Err(
Expand Down Expand Up @@ -550,6 +554,10 @@ impl<'a> ObjectAccess<'a> {
}

impl<'a, 'de> deer::ObjectAccess<'de> for ObjectAccess<'a> {
fn context(&self) -> &Context {
self.context
}

fn set_bounded(&mut self, length: usize) -> Result<(), ObjectAccessError> {
if self.dirty {
return Err(
Expand Down
4 changes: 4 additions & 0 deletions libs/deer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type FieldValue<'de, F> = <F as FieldVisitor<'de>>::Value;
type FieldResult<'de, F> = Option<Result<FieldValue<'de, F>, ObjectAccessError>>;

pub trait ObjectAccess<'de> {
fn context(&self) -> &Context;

/// This enables bound-checking for [`ObjectAccess`].
///
/// After calling this [`ObjectAccess`] will
Expand Down Expand Up @@ -115,6 +117,8 @@ pub trait FieldVisitor<'de> {
}

pub trait ArrayAccess<'de> {
fn context(&self) -> &Context;

/// Enables bound-checking for [`ArrayAccess`].
///
/// After calling this [`ArrayAccess`] will
Expand Down