Indexes 2: Add new_unchecked() constructors to spk schema objects#1337
Indexes 2: Add new_unchecked() constructors to spk schema objects#1337dcookspi wants to merge 2 commits intoindex-1-package-trait-changesfrom
new_unchecked() constructors to spk schema objects#1337Conversation
These allow for directly creating those objects from other existing object pieces, e.g. from index data objects. Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
| // TODO: CompatRules that allow ::None are used in Compat | ||
| // structs. CompatRules that do not allow ::None are used in | ||
| // required_compat's in Requests. They should be separate types, | ||
| // perhaps one wrapping the other, to clarify where ::None is and is | ||
| // not a valid value. |
There was a problem hiding this comment.
This refers to something that is worked around in later Indexing changes. But it could also be something that gets addresses in future by separating the two uses into distinct types.
| /// Makes a VersionFilter from the given string, without checking | ||
| /// that it is valid. This is used by indexing. | ||
| pub fn new_unchecked(filter_string: &str) -> Self { | ||
| VersionFilter::from_str(filter_string).unwrap() | ||
| } | ||
|
|
There was a problem hiding this comment.
This unwrap isn't good. But I've left it for now because it is likely the indexed representation of a VersionFilter, as part of an install requirement, will change to be stored as more pieces and that will mean this method is reworked entirely.
| } | ||
|
|
||
| // Allow tests to manufacture owned instances with known good values. | ||
| // Allow tests and indexes to manufacture owned instances with known good values. |
There was a problem hiding this comment.
No new_checked() methods were added for these String based types here. But in a later indexes PR there are several uses of unsafe { ... } around an existing method on these types. It may be that we want to fold those into a new_unchecked() method here for the non-test cases use.
Fixing up a comment Signed-off-by: dcookspi <92065525+dcookspi@users.noreply.github.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Note: for info on benefits of indexing for spk solves see #1340 (5 of 5). Maybe start there and work back down to this PR if you prefer to review PRs top down.
This adds
new_unchecked()constructor methods to various spk schema objects. These allow direct creation of those objects from other existing object pieces, e.g. from other pieces of those objects in index data. This is one of the changes that supports adding indexes and index based packages to Spk repositories. It allows indexes to avoid reparsing data from text for some objects.This is 2 of 5 chained PRs for adding indexes to spk solves:
spk repo indexsubcommand for index generation and updates #1340