remove as_str() legacy wrappers, callers use .into() directly

This commit is contained in:
damocles 2026-09-11 21:55:04 +02:00
commit 46456f75ce
25 changed files with 46 additions and 128 deletions

View file

@ -712,7 +712,7 @@ async fn finish_approval(
// snapshot refetch. `approved` rows that succeed get the
// approval's logged resolved_at indirectly via `Utc::now()`;
// failures already wrote it via mark_failed above.
let approval_kind = approval.kind.as_str();
let approval_kind = <&str>::from(approval.kind);
let sha_short = approval
.fetched_sha
.as_deref()
@ -921,7 +921,7 @@ pub fn deny(coord: &Coordinator, id: i64, note: Option<&str>) -> Result<()> {
tracing::info!(%id, note, "approval denied");
if let Some(a) = approval {
let sha = a.fetched_sha.clone();
let approval_kind = a.kind.as_str();
let approval_kind = <&str>::from(a.kind);
let sha_short = sha.as_deref().map(|s| s[..s.len().min(12)].to_owned());
let description = a.description.clone();
let agent_owned = a.agent.clone();

View file

@ -55,7 +55,7 @@ pub fn caps_for(name: &str) -> Vec<String> {
pub fn has_cap(name: &str, cap: hive_sh4re::permissions::Capability) -> bool {
caps_for(name)
.iter()
.any(|s| s.eq_ignore_ascii_case(cap.as_str()))
.any(|s| s.eq_ignore_ascii_case(<&str>::from(cap)))
}
/// Persist the full capability map. Sorted JSON output keeps diffs

View file

@ -72,7 +72,7 @@ fn write(map: &BTreeMap<String, Vec<String>>) -> std::io::Result<()> {
pub fn validate_groups(groups: &[String]) -> anyhow::Result<()> {
let valid: std::collections::BTreeSet<&str> = hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect();
let unknown: Vec<&str> = groups
.iter()
@ -87,7 +87,7 @@ pub fn validate_groups(groups: &[String]) -> anyhow::Result<()> {
unknown.join(", "),
hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect::<Vec<_>>()
.join(", ")
)

View file

@ -638,10 +638,10 @@ impl Coordinator {
/// commits the JSON file, so the P3RM1SS10NS tab updates live.
pub fn emit_capabilities_snapshot(self: &Arc<Self>) {
use hive_sh4re::permissions::Capability;
let caps = Capability::ALL.iter().map(|c| c.as_str()).collect();
let caps = Capability::ALL.iter().map(|c| <&str>::from(*c)).collect();
let descriptions = Capability::ALL
.iter()
.map(|c| (c.as_str(), c.description()))
.map(|c| (<&str>::from(*c), c.description()))
.collect();
let assignments = crate::capabilities::read();
// Best-effort roster (sync path); on a contended cache miss we
@ -665,10 +665,10 @@ impl Coordinator {
/// commits the JSON file, so the P3RM1SS10NS tab updates live.
pub fn emit_tool_groups_snapshot(self: &Arc<Self>) {
use hive_sh4re::permissions::ToolGroup;
let groups = ToolGroup::ALL.iter().map(|g| g.as_str()).collect();
let groups = ToolGroup::ALL.iter().map(|g| <&str>::from(*g)).collect();
let descriptions = ToolGroup::ALL
.iter()
.map(|g| (g.as_str(), g.description()))
.map(|g| (<&str>::from(*g), g.description()))
.collect();
let assignments = crate::tool_groups::read();
let roster = self.live_container_names_blocking().unwrap_or_default();

View file

@ -105,7 +105,7 @@ pub(super) fn gc_orphans(coord: &Coordinator, approvals: Vec<Approval>) -> Vec<A
coord.emit_approval_resolved(crate::coordinator::ApprovalResolved {
id: a.id,
agent: a.agent.as_str(),
approval_kind: a.kind.as_str(),
approval_kind: <&str>::from(a.kind),
sha_short,
status: "failed",
note: Some(note.to_owned()),

View file

@ -50,11 +50,11 @@ pub(super) async fn get_tool_groups(
) -> axum::Json<ToolGroupsSnapshot> {
let groups = hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect();
let descriptions = hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| (g.as_str(), g.description()))
.map(|g| (<&str>::from(*g), g.description()))
.collect();
let assignments = crate::tool_groups::read();
let roster = state
@ -82,7 +82,7 @@ pub(super) async fn get_tool_groups(
pub(crate) fn tool_group_default_names() -> Vec<&'static str> {
hive_sh4re::permissions::ToolGroup::AGENT_DEFAULT
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect()
}
@ -205,10 +205,10 @@ pub(super) async fn get_capabilities(
State(state): State<AppState>,
) -> axum::Json<CapabilitiesSnapshot> {
use hive_sh4re::permissions::Capability;
let caps = Capability::ALL.iter().map(|c| c.as_str()).collect();
let caps = Capability::ALL.iter().map(|c| <&str>::from(*c)).collect();
let descriptions = Capability::ALL
.iter()
.map(|c| (c.as_str(), c.description()))
.map(|c| (<&str>::from(*c), c.description()))
.collect();
let assignments = crate::capabilities::read();
let roster = state
@ -258,7 +258,7 @@ pub(super) async fn post_capabilities(
}
let known: Vec<&str> = hive_sh4re::permissions::Capability::ALL
.iter()
.map(|c| c.as_str())
.map(|c| <&str>::from(*c))
.collect();
for cap in &body.caps {
if !known.contains(&cap.as_str()) {
@ -336,7 +336,7 @@ pub(super) async fn post_permissions(
) -> Result<Response, ProblemDetails> {
let known_caps: Vec<&str> = hive_sh4re::permissions::Capability::ALL
.iter()
.map(|c| c.as_str())
.map(|c| <&str>::from(*c))
.collect();
// Phase 1 — validate everything before touching any file or the
// queue, so a bad entry fails the whole POST with zero side effects.

View file

@ -423,7 +423,7 @@ fn history_view(a: Approval) -> ApprovalHistoryView {
// Pending shouldn't appear in recent_resolved, but be defensive.
hive_sh4re::approvals::ApprovalStatus::Pending => "pending",
};
let kind = a.kind.as_str();
let kind = <&str>::from(a.kind);
ApprovalHistoryView {
id: a.id,
agent: a.agent.to_string(),

View file

@ -385,7 +385,7 @@ fn run_set_wanted(coord: &Arc<Coordinator>, agent: &str, up: bool) -> Result<()>
coord
.power
.set(agent, wanted)
.with_context(|| format!("set wanted={} for agent {agent}", wanted.as_str()))?;
.with_context(|| format!("set wanted={} for agent {agent}", <&str>::from(wanted)))?;
Ok(())
}
@ -579,7 +579,7 @@ async fn run_reconcile(coord: &Arc<Coordinator>, name: &str) -> Result<Option<No
agent: name.to_owned(),
}),
ReconcileAction::Noop => {
tracing::debug!(%name, wanted = wanted.as_str(), running, "reconcile: noop");
tracing::debug!(%name, wanted = <&str>::from(wanted), running, "reconcile: noop");
None
}
})

View file

@ -313,7 +313,7 @@ impl JobQueue {
}
Some(RunningTransient {
agent: agent.to_owned(),
label: n.payload.as_str().to_owned(),
label: <&str>::from(&n.payload).to_owned(),
takes_container_down: n.payload.takes_container_down(),
// `started_at` is set when a node enters `Running`, and this
// only sees `Running` nodes — the fallback is unreachable in

View file

@ -170,7 +170,7 @@ pub enum NodeKind {
/// renders it without knowing what any of it means.
impl hive_jobq_wire::WireNode for NodeKind {
fn label(&self) -> String {
self.as_str().to_owned()
<&str>::from(self).to_owned()
}
fn data(&self, id: hive_jobq_wire::WireId) -> serde_json::Value {
@ -201,16 +201,6 @@ impl hive_jobq_wire::WireNode for NodeKind {
}
impl NodeKind {
/// Wire string for the node's label on the graph wire
/// ([`hive_jobq_wire::WireNode::label`]) — derived
/// (`#[strum(serialize_all = "snake_case")]`), matching the same
/// convention the `#[serde(rename_all = "snake_case")]` tag above
/// uses, rather than a 31-arm hand-written match kept in sync with it
/// by hand.
pub fn as_str(&self) -> &'static str {
self.into()
}
/// The agent this node targets, or `""` for agentless kinds
/// ([`NodeKind::MetaLock`] on the `hyperhive` pseudo-agent,
/// [`NodeKind::Reparent`] which can span multiple agents, and

View file

@ -92,10 +92,11 @@ pub async fn run_worker(coord: Arc<Coordinator>) {
hive_jobq::scheduler::Scheduler::claim_next(&sched, move |id, kind, builder| {
let coord = node_coord;
async move {
let kind_str = <&str>::from(&kind);
tracing::info!(
dag = coord.job_queue.root_of(id).unwrap_or_default(),
node = id.get(),
kind = kind.as_str(),
kind = kind_str,
agent = %kind.agent(),
"job_queue: node running"
);
@ -104,7 +105,7 @@ pub async fn run_worker(coord: Arc<Coordinator>) {
Ok(()) => tracing::info!(node = id.get(), "job_queue: node done"),
Err(e) => tracing::warn!(
node = id.get(),
kind = kind.as_str(),
kind = kind_str,
agent = %kind.agent(),
error = %format!("{e:#}"),
grown_nodes = !grown.is_empty(),

View file

@ -862,7 +862,7 @@ fn rebuild_chain_nodes_suppress_crash_watch() {
kind.takes_container_down(),
"{} must suppress crash-watch — a rebuild takes the container down \
on purpose",
kind.as_str()
<&str>::from(&kind)
);
}
// The counter-case, and the reason this can't be "any node in a rebuild":

View file

@ -823,7 +823,7 @@ fn handle_cancel_loose_end(
coord.emit_approval_resolved(crate::coordinator::ApprovalResolved {
id: approval.id,
agent: approval.agent.as_str(),
approval_kind: approval.kind.as_str(),
approval_kind: <&str>::from(approval.kind),
sha_short,
status: "cancelled",
note: approval.note,

View file

@ -93,7 +93,7 @@ impl Approvals {
VALUES (?1, ?2, ?3, ?4, 'pending', ?5, ?6, ?7)",
params![
agent,
kind.as_str(),
<&str>::from(kind),
commit_ref,
Utc::now().timestamp(),
description,

View file

@ -100,12 +100,6 @@ pub enum BuildStatus {
Fail,
}
impl BuildStatus {
fn as_str(self) -> &'static str {
self.into()
}
}
/// Header-only row returned by `list_recent_for_agent`. Carries the
/// metadata the dashboard's agent-card chip needs (status + age +
/// id-to-open) without the multi-MB stdout/stderr payload.
@ -278,7 +272,7 @@ impl BuildLogs {
let conn = self.conn.lock().unwrap();
if let Err(e) = conn.execute(
"UPDATE build_logs SET finished_at = ?1, status = ?2 WHERE id = ?3",
params![now, status.as_str(), id],
params![now, <&str>::from(status), id],
) {
tracing::warn!(
build_log_id = id,

View file

@ -38,10 +38,6 @@ pub enum Wanted {
}
impl Wanted {
pub fn as_str(self) -> &'static str {
self.into()
}
/// Derived (`strum::EnumString`, the same `snake_case` convention
/// `as_str` uses) rather than a hand-written match kept in sync with
/// it by hand.
@ -138,7 +134,7 @@ impl PowerStore {
conn.execute(
"INSERT INTO agent_power (agent, wanted, updated_at) VALUES (?1, ?2, ?3)
ON CONFLICT(agent) DO UPDATE SET wanted = ?2, updated_at = ?3",
params![agent, wanted.as_str(), Utc::now().timestamp()],
params![agent, <&str>::from(wanted), Utc::now().timestamp()],
)
.context("upsert agent_power")?;
Ok(())
@ -154,7 +150,7 @@ impl PowerStore {
}
let seeded = Wanted::from_running(running);
self.set(agent, seeded)?;
tracing::info!(%agent, wanted = seeded.as_str(), "agent_power: seeded from observed state");
tracing::info!(%agent, wanted = <&str>::from(seeded), "agent_power: seeded from observed state");
Ok(seeded)
}

View file

@ -173,7 +173,7 @@ fn seed_manager_tool_groups() {
}
let all_groups: Vec<String> = hive_sh4re::permissions::ToolGroup::MANAGER_DEFAULT
.iter()
.map(|g| g.as_str().to_owned())
.map(|g| <&str>::from(*g).to_owned())
.collect();
match tool_groups::set_groups(MANAGER_NAME, &all_groups) {
Ok(()) => tracing::info!("seeded ruth's tool groups to MANAGER_DEFAULT (all groups)"),