diff --git a/examples/sparse_http_reqwest.rs b/examples/sparse_http_reqwest.rs
index 509f3112..94151f07 100644
--- a/examples/sparse_http_reqwest.rs
+++ b/examples/sparse_http_reqwest.rs
@@ -1,4 +1,4 @@
-use crates_index::{SparseIndex};
+use crates_index::SparseIndex;
///
/// **important**:
@@ -18,18 +18,18 @@ fn main() {
print_crate(&mut index);
}
-fn print_crate(index: &mut SparseIndex){
+fn print_crate(index: &mut SparseIndex) {
match index.crate_from_cache(CRATE_TO_FETCH) {
Ok(krate) => {
println!("{:?}", krate.highest_normal_version().unwrap().version());
}
Err(_err) => {
- println!("could not find crate {}",CRATE_TO_FETCH)
+ println!("could not find crate {}", CRATE_TO_FETCH)
}
}
}
-fn update(index: &mut SparseIndex){
+fn update(index: &mut SparseIndex) {
let req = index.make_cache_request(CRATE_TO_FETCH).unwrap().body(()).unwrap();
let (parts, _) = req.into_parts();
@@ -41,9 +41,7 @@ fn update(index: &mut SparseIndex){
let res = client.execute(req).unwrap();
- let mut builder = http::Response::builder()
- .status(res.status())
- .version(res.version());
+ let mut builder = http::Response::builder().status(res.status()).version(res.version());
builder
.headers_mut()
@@ -54,4 +52,4 @@ fn update(index: &mut SparseIndex){
let res = builder.body(body.to_vec()).unwrap();
index.parse_cache_response(CRATE_TO_FETCH, res, true).unwrap();
-}
\ No newline at end of file
+}
diff --git a/examples/sparse_http_ureq.rs b/examples/sparse_http_ureq.rs
index 42a59e86..3f939b9c 100644
--- a/examples/sparse_http_ureq.rs
+++ b/examples/sparse_http_ureq.rs
@@ -1,5 +1,5 @@
+use crates_index::SparseIndex;
use std::io;
-use crates_index::{SparseIndex};
///
/// **important**:
@@ -19,27 +19,28 @@ fn main() {
print_crate(&mut index);
}
-fn print_crate(index: &mut SparseIndex){
+fn print_crate(index: &mut SparseIndex) {
match index.crate_from_cache(CRATE_TO_FETCH) {
Ok(krate) => {
println!("{:?}", krate.highest_normal_version().unwrap().version());
}
Err(_err) => {
- println!("could not find crate {}",CRATE_TO_FETCH)
+ println!("could not find crate {}", CRATE_TO_FETCH)
}
}
}
-fn update(index: &mut SparseIndex){
+fn update(index: &mut SparseIndex) {
let request: ureq::Request = index.make_cache_request(CRATE_TO_FETCH).unwrap().into();
let response: http::Response = request
.call()
- .map_err(|_e| io::Error::new(io::ErrorKind::InvalidInput, "connection error")).unwrap()
+ .map_err(|_e| io::Error::new(io::ErrorKind::InvalidInput, "connection error"))
+ .unwrap()
.into();
let (parts, body) = response.into_parts();
let response = http::Response::from_parts(parts, body.into_bytes());
index.parse_cache_response(CRATE_TO_FETCH, response, true).unwrap();
-}
\ No newline at end of file
+}
diff --git a/examples/update_and_get_latest.rs b/examples/update_and_get_latest.rs
index 427eea0f..56293dff 100644
--- a/examples/update_and_get_latest.rs
+++ b/examples/update_and_get_latest.rs
@@ -3,12 +3,16 @@ fn main() -> Result<(), Box> {
let mut index = crates_index::GitIndex::new_cargo_default()?;
println!("Updating index…");
index.update()?;
-
+
let limit = 10;
println!("The most recent {limit} changes:\n");
for change in index.changes()?.take(limit) {
let change = change?;
- println!("{name} changed in {commit}", name = change.crate_name(), commit = change.commit_hex());
+ println!(
+ "{name} changed in {commit}",
+ name = change.crate_name(),
+ commit = change.commit_hex()
+ );
}
Ok(())
-}
\ No newline at end of file
+}
diff --git a/rustfmt.toml b/rustfmt.toml
index c7ad93ba..0a453277 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1 +1,2 @@
-disable_all_formatting = true
+max_width = 120
+disable_all_formatting = false
diff --git a/src/config.rs b/src/config.rs
index b83c57d6..0264a806 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,5 +1,5 @@
-use serde_derive::Deserialize;
use crate::dirs::crate_prefix;
+use serde_derive::Deserialize;
/// Global configuration of an index, reflecting the [contents of config.json](https://doc.rust-lang.org/cargo/reference/registries.html#index-format).
#[derive(Clone, Debug, Deserialize)]
diff --git a/src/dedupe.rs b/src/dedupe.rs
index a60f79d4..877ae05e 100644
--- a/src/dedupe.rs
+++ b/src/dedupe.rs
@@ -25,7 +25,8 @@ impl DedupeContext {
if let Some(has_feats) = self.features.get(&features_to_dedupe) {
*features = Arc::clone(&has_feats.map);
} else {
- if self.features.len() > 16384 { // keeps peak memory low (must clear, remove is leaving tombstones)
+ if self.features.len() > 16384 {
+ // keeps peak memory low (must clear, remove is leaving tombstones)
self.features.clear();
}
self.features.insert(features_to_dedupe);
@@ -36,7 +37,8 @@ impl DedupeContext {
if let Some(has_deps) = self.deps.get(&*deps) {
*deps = Arc::clone(has_deps);
} else {
- if self.deps.len() > 16384 { // keeps peak memory low (must clear, remove is leaving tombstones)
+ if self.deps.len() > 16384 {
+ // keeps peak memory low (must clear, remove is leaving tombstones)
self.deps.clear();
}
self.deps.insert(Arc::clone(deps));
@@ -52,7 +54,10 @@ pub struct HashableHashMap {
}
impl Hash for HashableHashMap {
- fn hash(&self, hasher: &mut H) where H: Hasher {
+ fn hash(&self, hasher: &mut H)
+ where
+ H: Hasher,
+ {
hasher.write_u64(self.hash);
}
}
diff --git a/src/dirs.rs b/src/dirs.rs
index d67902b5..6c4b1b26 100644
--- a/src/dirs.rs
+++ b/src/dirs.rs
@@ -31,12 +31,30 @@ pub(crate) fn crate_prefix(accumulator: &mut String, crate_name: &str, separator
3 => {
accumulator.push('3');
accumulator.push(separator);
- accumulator.extend(crate_name.as_bytes().get(0..1)?.iter().map(|c| c.to_ascii_lowercase() as char));
+ accumulator.extend(
+ crate_name
+ .as_bytes()
+ .get(0..1)?
+ .iter()
+ .map(|c| c.to_ascii_lowercase() as char),
+ );
}
_ => {
- accumulator.extend(crate_name.as_bytes().get(0..2)?.iter().map(|c| c.to_ascii_lowercase() as char));
+ accumulator.extend(
+ crate_name
+ .as_bytes()
+ .get(0..2)?
+ .iter()
+ .map(|c| c.to_ascii_lowercase() as char),
+ );
accumulator.push(separator);
- accumulator.extend(crate_name.as_bytes().get(2..4)?.iter().map(|c| c.to_ascii_lowercase() as char));
+ accumulator.extend(
+ crate_name
+ .as_bytes()
+ .get(2..4)?
+ .iter()
+ .map(|c| c.to_ascii_lowercase() as char),
+ );
}
};
Some(())
@@ -52,7 +70,6 @@ pub(crate) fn crate_name_to_relative_path(crate_name: &str, separator: Option Result<(String, String), Error> {
@@ -174,51 +191,35 @@ mod test {
use crate::sparse::URL;
assert_eq!(
super::url_to_local_dir(URL).unwrap(),
- (
- "index.crates.io-6f17d22bba15001f".to_owned(),
- URL.to_owned(),
- )
+ ("index.crates.io-6f17d22bba15001f".to_owned(), URL.to_owned(),)
);
// I've confirmed this also works with a custom registry, unfortunately
// that one includes a secret key as part of the url which would allow
// anyone to publish to the registry, so uhh...here's a fake one instead
assert_eq!(
- super::url_to_local_dir(
- "https://dl.cloudsmith.io/aBcW1234aBcW1234/embark/rust/cargo/index.git"
- )
- .unwrap(),
+ super::url_to_local_dir("https://dl.cloudsmith.io/aBcW1234aBcW1234/embark/rust/cargo/index.git").unwrap(),
(
"dl.cloudsmith.io-ff79e51ddd2b38fd".to_owned(),
"https://dl.cloudsmith.io/aBcW1234aBcW1234/embark/rust/cargo/index.git".to_owned()
)
);
}
-
+
#[test]
#[cfg(feature = "git")]
fn git_url_matches_cargo() {
use crate::git::URL;
assert_eq!(
crate::dirs::url_to_local_dir(URL).unwrap(),
- (
- "github.com-1ecc6299db9ec823".to_owned(),
- URL.to_owned()
- )
+ ("github.com-1ecc6299db9ec823".to_owned(), URL.to_owned())
);
// Ensure we actually strip off the irrelevant parts of a url, note that
// the .git suffix is not part of the canonical url, but *is* used when hashing
assert_eq!(
- crate::dirs::url_to_local_dir(&format!(
- "registry+{}.git?one=1&two=2#fragment",
- URL
- ))
- .unwrap(),
- (
- "github.com-c786010fb7ef2e6e".to_owned(),
- URL.to_owned()
- )
+ crate::dirs::url_to_local_dir(&format!("registry+{}.git?one=1&two=2#fragment", URL)).unwrap(),
+ ("github.com-c786010fb7ef2e6e".to_owned(), URL.to_owned())
);
}
}
diff --git a/src/error.rs b/src/error.rs
index 360d6c6f..127fa13b 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,5 +1,5 @@
pub use serde_json::Error as SerdeJsonError;
-use std::{io};
+use std::io;
use std::path::PathBuf;
pub use toml::de::Error as TomlDeError;
@@ -12,7 +12,7 @@ pub enum Error {
Git(#[from] GixError),
#[error("{0}")]
Url(String),
- #[error("Could not obtain the most recent head commit in repo at {}. Tried {}, had {} available", repo_path.display(), refs_tried.join(", "), refs_available.join(", "))]
+ #[error("Could not obtain the most recent head commit in repo at {}. Tried {}, had {} available", repo_path.display(), refs_tried.join(", "), refs_available.join(", "))]
MissingHead {
/// The references we tried to get commits for.
refs_tried: &'static [&'static str],
@@ -49,9 +49,7 @@ pub enum GixError {
#[error(transparent)]
IntoObjectKind(#[from] gix::object::try_into::Error),
#[error("The '{}' file is missing at the root of the tree of the crates index", path.display())]
- PathMissing {
- path: std::path::PathBuf
- },
+ PathMissing { path: std::path::PathBuf },
#[error(transparent)]
LockAcquire(#[from] gix::lock::acquire::Error),
#[error(transparent)]
diff --git a/src/git/changes.rs b/src/git/changes.rs
index 5f650182..9563c2e4 100644
--- a/src/git/changes.rs
+++ b/src/git/changes.rs
@@ -1,5 +1,5 @@
-use crate::git::{Change, fetch_remote};
use crate::error::GixError;
+use crate::git::{fetch_remote, Change};
use crate::Error;
use crate::GitIndex;
use gix::bstr::ByteSlice;
@@ -9,7 +9,6 @@ use std::time::{Duration, SystemTime};
const INDEX_GIT_ARCHIVE_URL: &str = "https://github.com/rust-lang/crates.io-index-archive";
-
/// An iterator over individual changes, see [`GitIndex::changes`] for more.
pub struct Changes<'repo> {
repo: &'repo gix::Repository,
@@ -30,7 +29,15 @@ impl<'repo> Iterator for Changes<'repo> {
};
let parent_tree = parent.tree().ok()?;
let time = SystemTime::UNIX_EPOCH + Duration::from_secs(self.current.time().ok()?.seconds.max(0) as _);
- Self::tree_additions(&self.repo, &mut self.out, time, &self.current.id(), &self.current_tree, &parent_tree).ok()?;
+ Self::tree_additions(
+ &self.repo,
+ &mut self.out,
+ time,
+ &self.current.id(),
+ &self.current_tree,
+ &parent_tree,
+ )
+ .ok()?;
self.current_tree = parent_tree;
self.current = parent;
}
@@ -40,7 +47,11 @@ impl<'repo> Iterator for Changes<'repo> {
impl<'repo> Changes<'repo> {
pub(crate) fn new(index: &'repo GitIndex) -> Result {
- let current = index.repo.find_object(index.head_commit)?.peel_to_kind(gix::object::Kind::Commit)?.into_commit();
+ let current = index
+ .repo
+ .find_object(index.head_commit)?
+ .peel_to_kind(gix::object::Kind::Commit)?
+ .into_commit();
let current_tree = current.tree()?;
Ok(Self {
@@ -52,7 +63,13 @@ impl<'repo> Changes<'repo> {
}
fn get_parent(&self) -> Result