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: introduce StructVisitor #2437

Merged
merged 22 commits into from
Apr 28, 2023
Merged

deer: introduce StructVisitor #2437

merged 22 commits into from
Apr 28, 2023

Conversation

indietyp
Copy link
Member

@indietyp indietyp commented Apr 17, 2023

🌟 What is the purpose of this PR?

Implements StructVisitor, one of the few remaining key pieces, this allows non self-describing formats (like bincode or msgpack) to use arrays instead of objects to denote structs.

Important: our json implementation does not support visit_array, this is on purpose, we do not want self-describing formats to do the same as non self-describing formats. They should always prefer the object variant.

The visitor has 4 methods (instead of 2): visit_none, visit_null, visit_object, visit_array. visit_none and visit_null are of interest, as they allow us easily implement Default behaviour.

> TODO: ^ the above statement should not be true, combining the OptionalVisitor with the StructVisitor should be enough!

🔗 Related links

🚀 Has this modified a publishable library?

This PR:

  • modifies an npm-publishable library and I have added a changeset file(s)
  • modifies a Cargo-publishable library and I have amended the version
  • modifies a Cargo-publishable library, but it is not yet ready to publish
  • modifies a block that will need publishing via GitHub action once merged
  • does not modify any publishable blocks or libraries, or modifications do not need publishing
  • I am unsure / need advice

🐾 Next steps

  • IdentifierVisitor (allows for non-string identifiers for different formats)
  • ReceivedVariant and ExpectedVariant support for non-str types
  • KeyError, MissingError additions
  • Content (GEN-34: deer: implement Content IR #2434)
  • core::ops (deer: implement Deserialize for core::ops #2422 - unblocked by this PR)
  • switch to justjson for json
  • json tests (blocked by item above)
  • alloc implementation
  • derive macro (can happen simultaneously to other tasks once IdentifierVisitor, MissingError, KeyError, and Content are in)

Experiments (slated for 0.2)

  • blueprint (in local repo)
  • switch from serde to value-bag (in local repo)

@github-actions github-actions bot added the area/libs > deer Affects the `deer` crate (library) label Apr 17, 2023
@indietyp indietyp marked this pull request as ready for review April 17, 2023 19:06
@indietyp indietyp requested a review from a team as a code owner April 17, 2023 19:06
@indietyp indietyp changed the title feat: create struct visitor deer: introduce StructVisitor Apr 17, 2023
@codecov
Copy link

codecov bot commented Apr 17, 2023

Codecov Report

Merging #2437 (fb619ad) into main (45acb52) will decrease coverage by 0.25%.
The diff coverage is 23.46%.

@@            Coverage Diff             @@
##             main    #2437      +/-   ##
==========================================
- Coverage   56.35%   56.11%   -0.25%     
==========================================
  Files         340      341       +1     
  Lines       26417    26563     +146     
  Branches      384      384              
==========================================
+ Hits        14888    14905      +17     
- Misses      11528    11657     +129     
  Partials        1        1              
Flag Coverage Δ
deer 66.41% <23.46%> (-1.99%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
libs/deer/desert/src/lib.rs 100.00% <ø> (ø)
libs/deer/desert/src/token.rs 4.34% <0.00%> (-20.66%) ⬇️
libs/deer/json/src/lib.rs 0.22% <0.00%> (-0.01%) ⬇️
libs/deer/src/lib.rs 70.58% <0.00%> (-4.69%) ⬇️
libs/deer/src/value.rs 23.88% <0.00%> (-6.89%) ⬇️
libs/deer/src/value/array.rs 0.00% <0.00%> (ø)
libs/deer/src/value/object.rs 0.00% <0.00%> (ø)
libs/deer/src/value/string.rs 33.33% <0.00%> (-9.10%) ⬇️
libs/deer/src/value/bytes.rs 35.89% <9.09%> (-10.77%) ⬇️
libs/deer/desert/src/deserializer.rs 76.87% <53.84%> (-2.17%) ⬇️
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

libs/deer/json/src/lib.rs Fixed Show fixed Hide fixed
libs/deer/json/src/lib.rs Fixed Show fixed Hide fixed
libs/deer/desert/src/skip.rs Fixed Show fixed Hide fixed
libs/deer/desert/src/skip.rs Fixed Show fixed Hide fixed
Copy link
Contributor

@thehabbos007 thehabbos007 left a comment

Choose a reason for hiding this comment

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

Looks pretty comprehensive so far. Have a couple comments, but nothing stood out other than that. Thank you!

Comment on lines +245 to +248
// TODO: maybe number
// TODO: IdentifierVisitor (u8, u64, str, borrowed_str, string,
// bytes, bytes_buf, borrowed_bytes)
// TODO: test
Copy link
Contributor

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? :)

Copy link
Member Author

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)

Copy link
Contributor

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 👍

thehabbos007
thehabbos007 previously approved these changes Apr 28, 2023
@indietyp indietyp added this pull request to the merge queue Apr 28, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 28, 2023
libs/deer/desert/src/token.rs Fixed Show fixed Hide fixed
libs/deer/desert/src/token.rs Fixed Show fixed Hide fixed
@indietyp indietyp added this pull request to the merge queue Apr 28, 2023
Merged via the queue into main with commit f168bc9 Apr 28, 2023
@indietyp indietyp deleted the bm/deer/struct-visitor branch April 28, 2023 18:29
indietyp added a commit that referenced this pull request Jun 6, 2023
* feat: nuke old version

* feat: init deserializer

* feat: error

* feat: parse number

* feat: deserialize more tokens

* feat: deserialize more

* fix: ref

* chore: yoink from #2437

* feat: adapt `skip_tokens` for `justjson`

* chore: imports

* feat: create `ObjectAccess`

* fix: compile

* feat: recursion limit

* feat: recursion limit grace

* feat: deserialize colon

* feat: deserialize array

* feat: deserialize struct

* feat: deserialize enum

* fix: clippy

* chore: remove comments

* chore: temporary fix

* fix: clippy

* feat: implement `deserialize_identifier`

* feat: pub `StackLimit`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/libs > deer Affects the `deer` crate (library)
Development

Successfully merging this pull request may close these issues.

2 participants