Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit 7c57805

Browse files
committed
style: add a .rustfmt.toml
enforces a slightly more opinionate style that should help keep the code a bit more consistent.
1 parent 8f29531 commit 7c57805

27 files changed

Lines changed: 239 additions & 188 deletions

File tree

.rustfmt.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
edition = "2021"
2+
newline_style = "unix"
3+
use_field_init_shorthand = true
4+
use_try_shorthand = true
5+
6+
unstable_features = true
7+
8+
comment_width = 100
9+
condense_wildcard_suffixes = true
10+
error_on_line_overflow = true
11+
format_code_in_doc_comments = true
12+
format_macro_bodies = true
13+
format_macro_matchers = true
14+
format_strings = true
15+
group_imports = "StdExternalCrate"
16+
imports_granularity = "Module"
17+
match_block_trailing_comma = true
18+
normalize_doc_attributes = true
19+
reorder_impl_items = true
20+
style_edition = "2024"
21+
wrap_comments = true

crates/atom/src/core.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use std::{borrow::Cow, path::Path};
2-
3-
use super::id::Id;
1+
use std::borrow::Cow;
2+
use std::path::Path;
43

54
use semver::Version;
65
use serde::{Deserialize, Serialize};
76

7+
use super::id::Id;
8+
89
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
910
/// Represents the deserialized form of an Atom, directly constructed from the TOML manifest.
1011
///
@@ -69,9 +70,11 @@ impl AtomPaths<PathBuf> {
6970
pub fn lock(&self) -> &Path {
7071
self.lock.as_ref()
7172
}
73+
7274
pub fn spec(&self) -> &Path {
7375
self.spec.as_ref()
7476
}
77+
7578
pub fn content(&self) -> &Path {
7679
self.content.as_ref()
7780
}

crates/atom/src/id/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#[cfg(test)]
77
mod tests;
88

9-
use serde::{Deserialize, Serialize, Serializer};
10-
119
use std::borrow::Borrow;
1210
use std::fmt;
1311
use std::ops::Deref;
1412
use std::str::FromStr;
13+
14+
use serde::{Deserialize, Serialize, Serializer};
1515
use thiserror::Error;
1616
use unic_ucd_category::GeneralCategory;
1717

@@ -80,6 +80,7 @@ impl<R> Serialize for AtomId<R> {
8080

8181
impl<T> Deref for AtomHash<'_, T> {
8282
type Target = [u8; 32];
83+
8384
fn deref(&self) -> &Self::Target {
8485
&self.hash
8586
}
@@ -124,6 +125,7 @@ where
124125
let root = src.calculate_root()?;
125126
Ok(AtomId { root, id })
126127
}
128+
127129
/// The root field, which serves as a derived key for the blake-3 hash used to
128130
/// identify the Atom in backend implementations.
129131
pub fn root(&self) -> &R {
@@ -158,6 +160,7 @@ impl Id {
158160

159161
Ok(())
160162
}
163+
161164
pub(super) fn is_invalid_start(c: char) -> bool {
162165
matches!(
163166
GeneralCategory::of(c),
@@ -166,6 +169,7 @@ impl Id {
166169
|| c == '-'
167170
|| !Id::is_valid_char(c)
168171
}
172+
169173
pub(super) fn is_valid_char(c: char) -> bool {
170174
matches!(
171175
GeneralCategory::of(c),
@@ -183,6 +187,7 @@ impl Id {
183187

184188
impl Deref for Id {
185189
type Target = String;
190+
186191
fn deref(&self) -> &Self::Target {
187192
&self.0
188193
}

crates/atom/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ pub mod publish;
3636
pub mod store;
3737
pub mod uri;
3838
pub use core::Atom;
39-
pub use id::AtomId;
40-
pub use id::CalculateRoot;
41-
pub use manifest::Manifest;
42-
4339
use std::sync::LazyLock;
40+
41+
pub use id::{AtomId, CalculateRoot};
42+
pub use manifest::Manifest;
4443
const TOML: &str = "toml";
4544
const BASE32: base32::Alphabet = base32::Alphabet::Rfc4648HexLower { padding: false };
4645
static ATOM_EXT: LazyLock<String> = LazyLock::new(|| format!("@.{}", crate::TOML));

crates/atom/src/manifest.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
//! # Atom Manifest
22
//!
33
//! Provides the core types for working with an Atom's manifest format.
4-
use crate::Atom;
5-
use serde::{Deserialize, Serialize};
4+
mod depends;
5+
6+
use std::collections::HashMap;
67
use std::str::FromStr;
8+
9+
use serde::{Deserialize, Serialize};
710
use thiserror::Error;
8-
use toml_edit::de;
9-
use toml_edit::DocumentMut;
11+
use toml_edit::{DocumentMut, de};
12+
13+
use crate::Atom;
14+
use crate::id::Id;
1015

1116
/// Errors which occur during manifest (de)serialization.
1217
#[derive(Error, Debug)]
@@ -53,6 +58,7 @@ impl Manifest {
5358

5459
impl FromStr for Manifest {
5560
type Err = de::Error;
61+
5662
fn from_str(s: &str) -> Result<Self, Self::Err> {
5763
de::from_str(s)
5864
}

crates/atom/src/manifest/depends.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl AtomSrc {
3636
_ => None,
3737
}
3838
}
39+
3940
pub(crate) fn path(self) -> Option<PathBuf> {
4041
match self {
4142
AtomSrc::Path(path) => Some(path),

crates/atom/src/publish/error.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ pub enum PublishError {
1515
#[cfg(feature = "git")]
1616
pub mod git {
1717
//! # Git Publishing Errors
18-
use crate::store::git::Root;
19-
use gix::object;
2018
use std::path::PathBuf;
19+
20+
use gix::object;
21+
22+
use crate::store::git::Root;
2123
/// An error representing a failure during publishing to a Git Ekala store.
2224
#[derive(thiserror::Error, Debug)]
2325
pub enum Error {
@@ -103,13 +105,13 @@ pub mod git {
103105
remote_root = %**remote,
104106
suggest = Error::INCONSISTENT_ROOT_SUGGESTION
105107
);
106-
}
108+
},
107109
Error::Invalid(e, path) => {
108110
tracing::warn!(message = %self, path = %path.display(), message = format!("\n{}", e));
109-
}
111+
},
110112
Error::NotAnAtom(path) => {
111113
tracing::warn!(message = %self, path = %path.display());
112-
}
114+
},
113115
Error::Failed => (),
114116
_ => tracing::warn!(message = %self),
115117
}

crates/atom/src/publish/git/inner.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
use super::{
2-
super::{ATOM_FORMAT_VERSION, ATOM_MANIFEST, EMPTY_SIG},
3-
AtomContext, AtomRef, GitContext, GitResult, RefKind,
4-
};
5-
use crate::{
6-
core::AtomPaths,
7-
publish::{error::git::Error, ATOM_ORIGIN},
8-
store::git,
9-
Atom, AtomId, Manifest,
10-
};
11-
12-
use gix::{
13-
actor::Signature,
14-
diff::object::Commit as AtomCommit,
15-
object::tree::Entry,
16-
objs::{tree::Entry as AtomEntry, WriteTo},
17-
worktree::object::Tree as AtomTree,
18-
ObjectId, Reference,
19-
};
20-
use std::{
21-
io::{self, Read},
22-
os::unix::ffi::OsStrExt,
23-
path::Path,
24-
};
25-
26-
use std::path::PathBuf;
1+
use std::io::{self, Read};
2+
use std::os::unix::ffi::OsStrExt;
3+
use std::path::{Path, PathBuf};
4+
5+
use gix::actor::Signature;
6+
use gix::diff::object::Commit as AtomCommit;
7+
use gix::object::tree::Entry;
8+
use gix::objs::WriteTo;
9+
use gix::objs::tree::Entry as AtomEntry;
10+
use gix::worktree::object::Tree as AtomTree;
11+
use gix::{ObjectId, Reference};
12+
13+
use super::super::{ATOM_FORMAT_VERSION, ATOM_MANIFEST, EMPTY_SIG};
14+
use super::{AtomContext, AtomRef, GitContext, GitResult, RefKind};
15+
use crate::core::AtomPaths;
16+
use crate::publish::ATOM_ORIGIN;
17+
use crate::publish::error::git::Error;
18+
use crate::store::git;
19+
use crate::{Atom, AtomId, Manifest};
2720
impl<'a> GitContext<'a> {
2821
/// Method to verify the manifest of an entry
2922
pub(super) fn verify_manifest(&self, obj: &Object, path: &Path) -> GitResult<Atom> {
@@ -149,13 +142,13 @@ impl<'a> AtomContext<'a> {
149142
false
150143
}
151144
}
145+
152146
/// Method to write the atom tree object
153147
pub(super) fn write_atom_tree(
154148
&self,
155149
entries: &AtomEntries,
156150
) -> GitResult<MaybeSkipped<AtomTreeId>> {
157-
use Err as Skipped;
158-
use Ok as Wrote;
151+
use {Err as Skipped, Ok as Wrote};
159152

160153
let mut entries: Vec<_> = entries.iter().map(atom_entry).collect();
161154

@@ -320,6 +313,7 @@ impl CommittedAtom {
320313
pub fn commit(&self) -> &AtomCommit {
321314
&self.commit
322315
}
316+
323317
#[must_use]
324318
/// Returns a reference to the tip of this [`CommittedAtom`].
325319
pub fn tip(&self) -> &ObjectId {

crates/atom/src/publish/git/mod.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ mod test;
1515

1616
mod inner;
1717

18-
use super::{error::git::Error, Content, PublishOutcome, Record};
19-
use crate::{
20-
core::AtomPaths,
21-
store::{git::Root, NormalizeStorePath},
22-
Atom, AtomId,
23-
};
24-
25-
use gix::Commit;
26-
use gix::{ObjectId, Repository, Tree};
2718
use std::cell::RefCell;
2819
use std::path::{Path, PathBuf};
20+
21+
use gix::{Commit, ObjectId, Repository, Tree};
2922
use tokio::task::JoinSet;
3023

24+
use super::error::git::Error;
25+
use super::{Content, PublishOutcome, Record};
26+
use crate::core::AtomPaths;
27+
use crate::store::NormalizeStorePath;
28+
use crate::store::git::Root;
29+
use crate::{Atom, AtomId};
30+
3131
type GitAtomId = AtomId<Root>;
3232
/// The Outcome of an Atom publish attempt to a Git store.
3333
pub type GitOutcome = PublishOutcome<Root>;
@@ -198,7 +198,7 @@ impl<'a> StateValidator<Root> for GitPublisher<'a> {
198198
return Err(Error::Duplicates);
199199
}
200200
atoms.insert(atom.id, path);
201-
}
201+
},
202202
Err(e) => e.warn(),
203203
}
204204
}
@@ -228,31 +228,36 @@ impl GitContent {
228228
pub fn spec(&self) -> &gix::refs::Reference {
229229
&self.spec
230230
}
231+
231232
/// Return a reference to the Atom src Git ref.
232233
#[must_use]
233234
pub fn origin(&self) -> &gix::refs::Reference {
234235
&self.origin
235236
}
237+
236238
/// Return a reference to the Atom content ref.
237239
#[must_use]
238240
pub fn content(&self) -> &gix::refs::Reference {
239241
&self.content
240242
}
243+
241244
/// Return a reference to the path to the Atom.
242245
#[must_use]
243246
pub fn path(&self) -> &PathBuf {
244247
&self.path
245248
}
249+
246250
/// Return a reference to the atom ref prefix.
247251
#[must_use]
248252
pub fn ref_prefix(&self) -> &String {
249253
&self.ref_prefix
250254
}
251255
}
252256

257+
use std::collections::HashMap;
258+
253259
use super::Publish;
254260
use crate::id::Id;
255-
use std::collections::HashMap;
256261

257262
impl<'a> super::private::Sealed for GitContext<'a> {}
258263

@@ -261,12 +266,15 @@ impl<'a> Publish<Root> for GitContext<'a> {
261266

262267
/// Publishes atoms.
263268
///
264-
/// This function processes a collection of paths, each representing an atom to be published. The publishing
265-
/// process includes path normalization, existence checks, and actual publishing attempts.
269+
/// This function processes a collection of paths, each representing an atom to be published.
270+
/// The publishing process includes path normalization, existence checks, and actual
271+
/// publishing attempts.
266272
///
267273
/// # Path Normalization
268-
/// - First attempts to interpret each path as relative to the caller's current location inside the repository.
269-
/// - If normalization fails (e.g., in a bare repository), falls back to treating the path as already relative to the repo root.
274+
/// - First attempts to interpret each path as relative to the caller's current location inside
275+
/// the repository.
276+
/// - If normalization fails (e.g., in a bare repository), falls back to treating the path as
277+
/// already relative to the repo root.
270278
/// - The normalized path is used to search the Git history, not the file system.
271279
///
272280
/// # Publishing Process
@@ -285,8 +293,8 @@ impl<'a> Publish<Root> for GitContext<'a> {
285293
///
286294
/// # Return Value
287295
/// Returns a vector of results types (`Vec<Result<PublishOutcome<T>, Self::Error>>`), where the
288-
/// outter result represents whether an atom has failed, and the inner result determines whether an
289-
/// atom was safely skipped, e.g. because it already exists..
296+
/// outter result represents whether an atom has failed, and the inner result determines whether
297+
/// an atom was safely skipped, e.g. because it already exists..
290298
fn publish<C>(&self, paths: C) -> Vec<GitResult<GitOutcome>>
291299
where
292300
C: IntoIterator<Item = PathBuf>,
@@ -306,8 +314,7 @@ impl<'a> Publish<Root> for GitContext<'a> {
306314
}
307315

308316
fn publish_atom<P: AsRef<Path>>(&self, path: P) -> GitResult<GitOutcome> {
309-
use Err as Skipped;
310-
use Ok as Published;
317+
use {Err as Skipped, Ok as Published};
311318

312319
let atom = AtomContext::set(path.as_ref(), self)?;
313320

@@ -385,13 +392,13 @@ impl<'a> GitContext<'a> {
385392
if !output.is_empty() {
386393
tracing::info!(output = %String::from_utf8_lossy(&output));
387394
}
388-
}
395+
},
389396
Ok(Err(e)) => {
390397
errors.push(e);
391-
}
398+
},
392399
Err(e) => {
393400
errors.push(Error::JoinFailed(e));
394-
}
401+
},
395402
}
396403
}
397404
}

0 commit comments

Comments
 (0)