Lean on RepoName's Deref and AsRef impls
With RepoName implementing Deref<Target = str> and AsRef<Path>, the inherent as_str() method is redundant: path joins coerce through AsRef and the name() accessor through Deref. The git-init array literal keeps an explicit &str via &name[..], since deref coercion does not fire on array elements.
Assisted-by: Claude Opus 4.8 via Claude Code
diff --git a/quire-server/src/bin/quire/commands/repo.rs b/quire-server/src/bin/quire/commands/repo.rs
index a7a674e..331dbce 100644
--- a/quire-server/src/bin/quire/commands/repo.rs
+++ b/quire-server/src/bin/quire/commands/repo.rs
@@ -15,7 +15,7 @@ pub async fn new(quire: &Quire, name: &RepoName) -> Result<()> {
}
let status = Command::new("git")
- .args(["init", "--bare", "--initial-branch=main", name.as_str()])
+ .args(["init", "--bare", "--initial-branch=main", &name[..]])
.current_dir(quire.repos_dir())
.status()
.into_diagnostic()?;
diff --git a/quire-server/src/quire/mod.rs b/quire-server/src/quire/mod.rs
index 720ced4..4aa8d27 100644
--- a/quire-server/src/quire/mod.rs
+++ b/quire-server/src/quire/mod.rs
@@ -72,12 +72,6 @@ pub struct CiConfig {
#[derive(Clone, Debug)]
pub struct RepoName(String);
-impl RepoName {
- pub fn as_str(&self) -> &str {
- &self.0
- }
-}
-
impl std::ops::Deref for RepoName {
type Target = str;
@@ -86,6 +80,12 @@ impl std::ops::Deref for RepoName {
}
}
+impl AsRef<Path> for RepoName {
+ fn as_ref(&self) -> &Path {
+ Path::new(&self.0)
+ }
+}
+
impl std::str::FromStr for RepoName {
type Err = RepoNameError;
@@ -163,12 +163,12 @@ impl Repo {
}
pub fn path(&self) -> PathBuf {
- self.quire_root.join("repos").join(self.name.as_str())
+ self.quire_root.join("repos").join(&self.name)
}
/// The repo name relative to the repos directory (e.g. `foo.git`).
pub fn name(&self) -> &str {
- self.name.as_str()
+ &self.name
}
pub fn exists(&self) -> bool {
@@ -211,7 +211,7 @@ impl Repo {
/// The base directory for CI runs (`runs/<repo>/`).
pub fn runs_base(&self) -> PathBuf {
- self.quire_root.join("runs").join(self.name.as_str())
+ self.quire_root.join("runs").join(&self.name)
}
/// Access CI runs for this repo.