-
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 1 commit
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 @@ | |
| 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 addresses in future by separating the two uses into distinct types. |
||
| 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,14 @@ | |
| } | ||
| } | ||
|
|
||
| /// Create a compat from the given string without checking it. For | ||
| /// internal use only for data from a index. | ||
| pub fn new_unchecked(compat: &str) -> Result<Self> { | ||
| // TODO: change this to be more direct once Compats are | ||
dcookspi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1208,6 +1208,12 @@ impl VersionFilter { | |
| } | ||
| } | ||
|
|
||
| /// 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() | ||
| } | ||
|
|
||
|
Comment on lines
+1211
to
+1216
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 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. |
||
| pub fn single(item: VersionRange) -> Self { | ||
| let mut filter = Self::default(); | ||
| filter.rules.insert(item); | ||
|
|
||
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 PR there are several uses ofunsafe { ... }around an existing method on these types. It may be that we want to fold those into anew_unchecked()method here for the non-test cases use.