• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2024 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use std::collections::BTreeMap;
16 
17 use crates_index::Dependency;
18 use semver::VersionReq;
19 
20 mod android_target;
21 pub use android_target::AndroidTarget;
22 
23 mod dependency_diff;
24 pub use dependency_diff::DependencyDiffer;
25 
26 mod feature;
27 pub use feature::{FeatureRef, FeaturesAndOptionalDeps};
28 
29 mod feature_diff;
30 pub use feature_diff::{FeatureDiff, FeatureDiffer};
31 
32 mod feature_resolver;
33 pub use feature_resolver::FeatureResolver;
34 
35 mod index;
36 pub use index::CratesIoIndex;
37 
38 type DepSet<'a> = BTreeMap<&'a str, &'a Dependency>;
39 
40 pub trait ParsedVersionReq {
parsed_version_req(&self) -> Result<VersionReq, semver::Error>41     fn parsed_version_req(&self) -> Result<VersionReq, semver::Error>;
42 }
43 
44 impl ParsedVersionReq for Dependency {
parsed_version_req(&self) -> Result<VersionReq, semver::Error>45     fn parsed_version_req(&self) -> Result<VersionReq, semver::Error> {
46         VersionReq::parse(self.requirement())
47     }
48 }
49 
50 /// Error types for the 'crates_io_util' crate.
51 #[derive(thiserror::Error, Debug)]
52 pub enum Error {
53     /// Crate not found in crates.io
54     #[error("Crate {0} not found in crates.io")]
55     CrateNotFound(String),
56     /// Feature not found for crate
57     #[error("Feature {0} not found for crate {1}")]
58     FeatureNotFound(String, String),
59     /// Dependency not found for crate
60     #[error("Dependency {0} not found for crate {1}")]
61     DepNotFound(String, String),
62     /// Failed to get HTTP headers
63     #[error("Failed to get HTTP headers")]
64     HttpHeader,
65     /// Error fetching HTTP data
66     #[error(transparent)]
67     HttpFetch(#[from] ureq::Error),
68     /// Propagated crates_index::Error
69     #[error(transparent)]
70     CratesIndex(#[from] crates_index::Error),
71     /// Propagated crates_index::http::Error
72     #[error(transparent)]
73     CratesIndexHttp(#[from] crates_index::http::Error),
74 }
75