Ergonomics: Collection footgun#151
Draft
nicholascioli wants to merge 9 commits into
Draft
Conversation
This commit switches the `DataService` from using `async-trait` to using the Rust-maintained `trait-variant`. This fixes an issue with using the `DataService` trait inside of `tokio::spawn` due to an old Rust compiler bug around lifetime elision in generic associated types (GAT). See [1] for more info and [2] for a response from the Rust team about the `trait-variant` crate and why it was added. [1]: rust-lang/rust#100013 [2]: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits/#async-fn-in-public-traits
This alias was confusing since it violated the principle of least surprise by looking like a std::result::Result.
NoIdInSample, InitialSchemaError, and ChannelClosed were emitted only from code paths that were removed when trimming the library to leaf primitives. None of the remaining schema-builder-library code emits them, and downstream consumers (schema-builder-orchestration) carry their own Error enum, so removing them from the library's public Error enum is safe.
This commit refactors the `CollectionInfo` struct to better model the underlying data representation in MongoDB while also enforcing certain intrinsics about fields and their relation to their type. This should make it harder to misuse a collection returned from a `DataService` driver. A follow up ticket will need to explore why a view's `viewOn` field might be missing but allowed behaviour.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR changes the
CollectionInfostruct into an enum that better represents the underlying data while making it more difficult to use incorrectly.This PR is dependent on #148, so please review all commits after "refactor CollectionInfo for better ergonomics". This PR will be rebased once that other PR is merged.