-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: create struct visitor * feat: add mandatory `visit_null` and `visit_none` * feat: implement `deserialize_struct` for desert * feat: implement `deserialize_struct` for json * feat: implement manual implementation of `Deserialize` for struct * feat: outline ok * fix: value deserializer * test: `StructVisitor` * feat: remove `visit_null`/`visit_none` from `StructVisitor` * fix: json `Deserializer` * test: remove indirection in struct code * chore: comments * chore: comments (II) * feat: use `NoneDeserializer` for values * fix: drive-by: generalize skip logic, fix regression, skip value if key is wrong * fix: clippy * fix: clippy * fix: rustfmt * fix: remove reflection of removed tokens
- Loading branch information
Showing
15 changed files
with
876 additions
and
84 deletions.
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.