-
Notifications
You must be signed in to change notification settings - Fork 11
Indexes 2: Add new_unchecked() constructors to spk schema objects
#1337
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
base: index-1-package-trait-changes
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,12 +55,20 @@ pub enum CompatRule { | |
| Binary, | ||
| } | ||
|
|
||
| // 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. | ||
|
Comment on lines
+58
to
+62
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refers to something that is worked around in later Indexing changes. But it could also be something that gets addressed in future, by separating the two uses into distinct types.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like the idea of there being a newtype that wraps the other and giving them their own distinct |
||
| impl std::fmt::Display for CompatRule { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| if f.alternate() { | ||
| // Request for alternate (long form) names. | ||
| f.write_str(match self { | ||
| CompatRule::None => unreachable!(), | ||
| CompatRule::None => unreachable!( | ||
| "CompatRule '{}' fmt() cannot be displayed when using the alternate flag", | ||
| self | ||
| ), | ||
| CompatRule::API => API_STR, | ||
| CompatRule::Binary => BINARY_STR, | ||
| }) | ||
|
|
@@ -690,6 +698,18 @@ impl Compat { | |
| } | ||
| } | ||
|
|
||
| /// Create a compat from the given string without checking it. For | ||
| /// internal use only for data from a index. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The caller must ensure the string parses as a valid compat. | ||
| pub unsafe fn new_unchecked(compat: &str) -> Result<Self> { | ||
| // TODO: change this to be more direct once Compat objects are | ||
| // directly represented in indexes. | ||
| Self::from_str(compat) | ||
| } | ||
|
|
||
| /// Return true if the two versions are api compatible by this compat rule. | ||
| pub fn is_api_compatible(&self, base: &Version, other: &Version) -> Compatibility { | ||
| self.check_compat(base, other, CompatRule::API) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
No
new_checked()methods were added for these String based types here. But in a later indexes PRs there are several uses ofunsafe { ... }around an existing method on these types. It may be we want to fold those into anew_unchecked()method for non-test cases use.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.
Big picture I think we want to be able to say that values in the index were already validated before put into the index and therefore should be trusted without having to re-validate them when reading the index.
However we need a way to introduce changes to spk that may change validation rules. For example let's say we stop allowing
'-'in package names. How do we want to put some kind of version number in the index metadata so at runtime the spk process can check that the index conforms to its expectations?I'm interested in having a way to validate the whole index at once, in a sense, instead of having to validate every individual value found in the index.