-
Notifications
You must be signed in to change notification settings - Fork 85
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
: introduce StructVisitor
#2437
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b6a12a1
feat: create struct visitor
indietyp 2d102c5
feat: add mandatory `visit_null` and `visit_none`
indietyp 40b33ae
feat: implement `deserialize_struct` for desert
indietyp c4864a1
feat: implement `deserialize_struct` for json
indietyp efe37e9
feat: implement manual implementation of `Deserialize` for struct
indietyp 5a5b8fe
feat: outline ok
indietyp 0348a13
fix: value deserializer
indietyp 8a3784f
test: `StructVisitor`
indietyp 4a9949f
feat: remove `visit_null`/`visit_none` from `StructVisitor`
indietyp af640af
fix: json `Deserializer`
indietyp 885249b
test: remove indirection in struct code
indietyp 180d7a7
chore: comments
indietyp 9470e22
chore: comments (II)
indietyp adac7bd
Merge branch 'main' into bm/deer/struct-visitor
indietyp bef152c
feat: use `NoneDeserializer` for values
indietyp 0589a23
fix: drive-by: generalize skip logic, fix regression, skip value if k…
indietyp 4bc447f
fix: clippy
indietyp 2a2fa12
fix: clippy
indietyp 7b8282a
fix: rustfmt
indietyp 53630e1
Merge branch 'main' into bm/deer/struct-visitor
indietyp cbecc23
fix: remove reflection of removed tokens
indietyp fb619ad
Merge branch 'main' into bm/deer/struct-visitor
indietyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::{deserializer::Deserializer, Token}; | ||
|
||
fn scan_object(deserializer: &Deserializer, stop: &Token) -> usize { | ||
let mut objects: usize = 0; | ||
let mut arrays: usize = 0; | ||
|
||
let mut n = 0; | ||
|
||
loop { | ||
let Some(token) = deserializer.peek_n(n) else { | ||
// we're at the end | ||
return n; | ||
}; | ||
|
||
if token == *stop && arrays == 0 && objects == 0 { | ||
// we're at the outer layer, meaning we can know where we end | ||
// need to increment by one as we want to also skip the ObjectEnd | ||
return n + 1; | ||
} | ||
|
||
match token { | ||
Token::Array { .. } => arrays += 1, | ||
Token::ArrayEnd => arrays = arrays.saturating_sub(1), | ||
Token::Object { .. } => objects += 1, | ||
Token::ObjectEnd => objects = objects.saturating_sub(1), | ||
_ => {} | ||
} | ||
|
||
n += 1; | ||
} | ||
} | ||
|
||
/// Skips all tokens required for the start token, be aware that the start token should no longer be | ||
/// on the tape | ||
pub(crate) fn skip_tokens(deserializer: &mut Deserializer, start: &Token) { | ||
let n = match start { | ||
Token::Array { .. } => scan_object(&*deserializer, &Token::ArrayEnd), | ||
Token::Object { .. } => scan_object(&*deserializer, &Token::ObjectEnd), | ||
_ => 0, | ||
}; | ||
|
||
if n > 0 { | ||
deserializer.tape_mut().bump_n(n); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we want these todos to be more explicit? :)
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.
that might be a good idea, I have those mirrored into my own personal todo list (/ project management system), but because I do not have access to Asana I cannot create those tasks there and I didn't want to pollute the GitHub issues for this sort of thing as they are mostly bug reports right now (tho I heard whispers that that might change in the future)
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'm okay with this for now as a lot of this is in flux still 👍