From 46456f75ce25f3388980b395bd8351ac3c34e32a Mon Sep 17 00:00:00 2001 From: damocles Date: Fri, 11 Sep 2026 21:55:04 +0200 Subject: [PATCH] remove as_str() legacy wrappers, callers use .into() directly --- hive-c0re/src/actions.rs | 4 ++-- hive-c0re/src/agent_config/capabilities.rs | 2 +- hive-c0re/src/agent_config/tool_groups.rs | 4 ++-- hive-c0re/src/coordinator.rs | 8 ++++---- hive-c0re/src/dashboard/approvals.rs | 2 +- hive-c0re/src/dashboard/permissions.rs | 14 +++++++------- hive-c0re/src/dashboard/state_snapshot.rs | 2 +- hive-c0re/src/job_queue/exec.rs | 4 ++-- hive-c0re/src/job_queue/mod.rs | 2 +- hive-c0re/src/job_queue/model.rs | 12 +----------- hive-c0re/src/job_queue/scheduler.rs | 5 +++-- hive-c0re/src/job_queue/tests.rs | 2 +- hive-c0re/src/socket_server/mod.rs | 2 +- hive-c0re/src/stores/approvals.rs | 2 +- hive-c0re/src/stores/build_logs.rs | 8 +------- hive-c0re/src/stores/power.rs | 8 ++------ hive-c0re/src/workers/auto_update.rs | 2 +- hive-forge/src/verbs/issue_edit.rs | 8 +------- hive-sh4re/src/approvals.rs | 11 ----------- hive-sh4re/src/permissions.rs | 17 ----------------- swarm-controller/src/main.rs | 4 ++-- swarm-controller/src/webhook.rs | 16 ++-------------- swarm-queue-client/src/wanted.rs | 15 +-------------- swarm-secret-client/src/path.rs | 18 +++++++----------- swarm-secret-client/src/policy.rs | 2 +- 25 files changed, 46 insertions(+), 128 deletions(-) diff --git a/hive-c0re/src/actions.rs b/hive-c0re/src/actions.rs index cdf84e88..a56d162b 100644 --- a/hive-c0re/src/actions.rs +++ b/hive-c0re/src/actions.rs @@ -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(); diff --git a/hive-c0re/src/agent_config/capabilities.rs b/hive-c0re/src/agent_config/capabilities.rs index 187cb3b7..a911bed2 100644 --- a/hive-c0re/src/agent_config/capabilities.rs +++ b/hive-c0re/src/agent_config/capabilities.rs @@ -55,7 +55,7 @@ pub fn caps_for(name: &str) -> Vec { 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 diff --git a/hive-c0re/src/agent_config/tool_groups.rs b/hive-c0re/src/agent_config/tool_groups.rs index 4f73f7ba..8c93c64b 100644 --- a/hive-c0re/src/agent_config/tool_groups.rs +++ b/hive-c0re/src/agent_config/tool_groups.rs @@ -72,7 +72,7 @@ fn write(map: &BTreeMap>) -> 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::>() .join(", ") ) diff --git a/hive-c0re/src/coordinator.rs b/hive-c0re/src/coordinator.rs index 49706d6b..633533e3 100644 --- a/hive-c0re/src/coordinator.rs +++ b/hive-c0re/src/coordinator.rs @@ -638,10 +638,10 @@ impl Coordinator { /// commits the JSON file, so the P3RM1SS10NS tab updates live. pub fn emit_capabilities_snapshot(self: &Arc) { 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) { 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(); diff --git a/hive-c0re/src/dashboard/approvals.rs b/hive-c0re/src/dashboard/approvals.rs index 6a29f033..368d4f6d 100644 --- a/hive-c0re/src/dashboard/approvals.rs +++ b/hive-c0re/src/dashboard/approvals.rs @@ -105,7 +105,7 @@ pub(super) fn gc_orphans(coord: &Coordinator, approvals: Vec) -> Vec::from(a.kind), sha_short, status: "failed", note: Some(note.to_owned()), diff --git a/hive-c0re/src/dashboard/permissions.rs b/hive-c0re/src/dashboard/permissions.rs index 0ac5dc25..121324c8 100644 --- a/hive-c0re/src/dashboard/permissions.rs +++ b/hive-c0re/src/dashboard/permissions.rs @@ -50,11 +50,11 @@ pub(super) async fn get_tool_groups( ) -> axum::Json { 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, ) -> axum::Json { 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 { 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. diff --git a/hive-c0re/src/dashboard/state_snapshot.rs b/hive-c0re/src/dashboard/state_snapshot.rs index 32556ae3..6ff92329 100644 --- a/hive-c0re/src/dashboard/state_snapshot.rs +++ b/hive-c0re/src/dashboard/state_snapshot.rs @@ -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(), diff --git a/hive-c0re/src/job_queue/exec.rs b/hive-c0re/src/job_queue/exec.rs index 68045ce8..740b3c15 100644 --- a/hive-c0re/src/job_queue/exec.rs +++ b/hive-c0re/src/job_queue/exec.rs @@ -385,7 +385,7 @@ fn run_set_wanted(coord: &Arc, 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, name: &str) -> Result { - tracing::debug!(%name, wanted = wanted.as_str(), running, "reconcile: noop"); + tracing::debug!(%name, wanted = <&str>::from(wanted), running, "reconcile: noop"); None } }) diff --git a/hive-c0re/src/job_queue/mod.rs b/hive-c0re/src/job_queue/mod.rs index 961863c5..efe4fa74 100644 --- a/hive-c0re/src/job_queue/mod.rs +++ b/hive-c0re/src/job_queue/mod.rs @@ -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 diff --git a/hive-c0re/src/job_queue/model.rs b/hive-c0re/src/job_queue/model.rs index 42bf4fe5..0ee175b3 100644 --- a/hive-c0re/src/job_queue/model.rs +++ b/hive-c0re/src/job_queue/model.rs @@ -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 diff --git a/hive-c0re/src/job_queue/scheduler.rs b/hive-c0re/src/job_queue/scheduler.rs index f60f2028..cc2ff027 100644 --- a/hive-c0re/src/job_queue/scheduler.rs +++ b/hive-c0re/src/job_queue/scheduler.rs @@ -92,10 +92,11 @@ pub async fn run_worker(coord: Arc) { 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) { 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(), diff --git a/hive-c0re/src/job_queue/tests.rs b/hive-c0re/src/job_queue/tests.rs index 602d0080..a783bf91 100644 --- a/hive-c0re/src/job_queue/tests.rs +++ b/hive-c0re/src/job_queue/tests.rs @@ -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": diff --git a/hive-c0re/src/socket_server/mod.rs b/hive-c0re/src/socket_server/mod.rs index e73a0e45..fea70579 100644 --- a/hive-c0re/src/socket_server/mod.rs +++ b/hive-c0re/src/socket_server/mod.rs @@ -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, diff --git a/hive-c0re/src/stores/approvals.rs b/hive-c0re/src/stores/approvals.rs index 11b16dd9..417781db 100644 --- a/hive-c0re/src/stores/approvals.rs +++ b/hive-c0re/src/stores/approvals.rs @@ -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, diff --git a/hive-c0re/src/stores/build_logs.rs b/hive-c0re/src/stores/build_logs.rs index 07ec2434..b7ca43b9 100644 --- a/hive-c0re/src/stores/build_logs.rs +++ b/hive-c0re/src/stores/build_logs.rs @@ -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, diff --git a/hive-c0re/src/stores/power.rs b/hive-c0re/src/stores/power.rs index f50ec5ea..63b89b8e 100644 --- a/hive-c0re/src/stores/power.rs +++ b/hive-c0re/src/stores/power.rs @@ -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) } diff --git a/hive-c0re/src/workers/auto_update.rs b/hive-c0re/src/workers/auto_update.rs index 282c71eb..03ee16b0 100644 --- a/hive-c0re/src/workers/auto_update.rs +++ b/hive-c0re/src/workers/auto_update.rs @@ -173,7 +173,7 @@ fn seed_manager_tool_groups() { } let all_groups: Vec = 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)"), diff --git a/hive-forge/src/verbs/issue_edit.rs b/hive-forge/src/verbs/issue_edit.rs index 04f24e51..9120dda4 100644 --- a/hive-forge/src/verbs/issue_edit.rs +++ b/hive-forge/src/verbs/issue_edit.rs @@ -21,12 +21,6 @@ pub enum StateArg { Closed, } -impl StateArg { - fn as_str(self) -> &'static str { - self.into() - } -} - #[derive(ClapArgs)] pub struct Args { /// Issue (or PR — shares the same `/issues/` endpoint) number. @@ -74,7 +68,7 @@ pub fn run(client: &Client, args: Args) -> Result<()> { due_date: None, milestone: args.milestone.map(index).transpose()?, r#ref: None, - state: args.state.map(|s| s.as_str().to_owned()), + state: args.state.map(|s| <&str>::from(s).to_owned()), title: args.title, unset_due_date: None, updated_at: None, diff --git a/hive-sh4re/src/approvals.rs b/hive-sh4re/src/approvals.rs index d25912a4..94017ced 100644 --- a/hive-sh4re/src/approvals.rs +++ b/hive-sh4re/src/approvals.rs @@ -71,17 +71,6 @@ pub enum ApprovalKind { MergeConfigPr, } -impl ApprovalKind { - /// Wire/UI string — the same value serde's `snake_case` rename - /// produces, via the same derive (`#[strum(serialize_all = - /// "snake_case")]`) rather than a hand-rolled match a new variant - /// could silently miss. - #[must_use] - pub fn as_str(self) -> &'static str { - self.into() - } -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum ApprovalStatus { diff --git a/hive-sh4re/src/permissions.rs b/hive-sh4re/src/permissions.rs index 5baaa190..e376196c 100644 --- a/hive-sh4re/src/permissions.rs +++ b/hive-sh4re/src/permissions.rs @@ -154,15 +154,6 @@ impl ToolGroup { Self::WebTools, ]; - /// The `snake_case` wire name for this group (matches `serde(rename_all = - /// "snake_case")` serialisation) — derived (`#[strum(serialize_all = - /// "snake_case")]`) from the same convention rather than a hand-written - /// match kept in sync with it by hand. - #[must_use] - pub fn as_str(self) -> &'static str { - self.into() - } - /// Short human-readable description suitable for a tooltip or help text. #[must_use] pub fn description(self) -> &'static str { @@ -240,14 +231,6 @@ impl Capability { Self::QueryAgentState, ]; - /// Canonical `snake_case` name for this capability (matches serde) — - /// derived rather than a hand-written match, same as - /// [`ToolGroup::as_str`]. - #[must_use] - pub fn as_str(self) -> &'static str { - self.into() - } - /// Short human-readable description suitable for a tooltip or help text. #[must_use] pub fn description(self) -> &'static str { diff --git a/swarm-controller/src/main.rs b/swarm-controller/src/main.rs index c0f2e034..86c3778d 100644 --- a/swarm-controller/src/main.rs +++ b/swarm-controller/src/main.rs @@ -719,7 +719,7 @@ fn render(declaration: &swarm_queue_client::wanted::HiveWanted) -> Vec::from(wanted.state).to_owned(), }) .collect() } @@ -1000,7 +1000,7 @@ async fn get_agents_status( .get(hive)? .agents .get(&row.name) - .map(|w| w.state.as_str().to_owned()) + .map(|w| <&str>::from(w.state).to_owned()) }); } } diff --git a/swarm-controller/src/webhook.rs b/swarm-controller/src/webhook.rs index 4495131d..b17cb222 100644 --- a/swarm-controller/src/webhook.rs +++ b/swarm-controller/src/webhook.rs @@ -215,7 +215,7 @@ impl DeliveryKind { format!( "{}{ROUTE_PREFIX}{}", public_base.trim_end_matches('/'), - self.as_str() + <&str>::from(self) ) } @@ -229,18 +229,6 @@ impl DeliveryKind { fn parse(segment: &str) -> Option { segment.parse().ok() } - - /// Stable string form, used for logging. Deliberately the same spelling - /// as the path segment so a journal line can be matched against a - /// registered URL. - /// - /// ⚠️ **Not the routing key for the swarm→hive message.** That message is - /// semantic (*knowledge repo changed*, *deploy agent X at rev Y*) and is - /// addressed to the hives that need it; which hook a delivery arrived on - /// is an input to deriving it, not the thing sent. - fn as_str(self) -> &'static str { - self.into() - } } /// Why a delivery was refused. @@ -377,7 +365,7 @@ pub(super) async fn post_webhook_forge( }; tracing::info!( - kind = kind.as_str(), + kind = <&str>::from(kind), bytes = body.len(), "webhook: verified delivery" ); diff --git a/swarm-queue-client/src/wanted.rs b/swarm-queue-client/src/wanted.rs index 291a6150..4ebfcbe7 100644 --- a/swarm-queue-client/src/wanted.rs +++ b/swarm-queue-client/src/wanted.rs @@ -112,19 +112,6 @@ pub enum AgentState { Destroyed, } -impl AgentState { - /// The wire spelling, for a reader that renders rather than decodes. - /// - /// Derived (`#[strum(serialize_all = "snake_case")]`) from the same - /// convention as the `serde(rename_all)` above, rather than a - /// hand-written match kept in sync with it by hand; a test still pins - /// the two together. - #[must_use] - pub fn as_str(self) -> &'static str { - self.into() - } -} - /// Open the wanted-state bucket for writing, creating it if nothing has yet. /// /// **Controller-side only.** `history: 1` because a hive converges to the @@ -291,7 +278,7 @@ mod tests { } assert_eq!( serde_json::to_string(&state).expect("serialises"), - format!("\"{}\"", state.as_str()) + format!("\"{}\"", <&str>::from(state)) ); } } diff --git a/swarm-secret-client/src/path.rs b/swarm-secret-client/src/path.rs index 528e099a..c4f69ed5 100644 --- a/swarm-secret-client/src/path.rs +++ b/swarm-secret-client/src/path.rs @@ -55,14 +55,6 @@ impl Kind { /// than restate it — a second list is a list that drifts. pub const ALL: [Kind; 4] = [Kind::Agent, Kind::Hive, Kind::Service, Kind::Controller]; - /// The path segment, which is also what the store's grant is written - /// against. Thin wrapper over the derived `Into<&'static str>` so call - /// sites keep the same method-call shape as before. - #[must_use] - pub fn as_str(self) -> &'static str { - self.into() - } - /// What to call the name in an error — singular, because the message reads /// "hive name ... is not a single path segment". #[must_use] @@ -85,7 +77,7 @@ impl Kind { /// another's secrets. pub fn principal_prefix(kind: Kind, name: &str) -> Result { checked_segment(kind.label(), name)?; - Ok(format!("{ROOT}/{}/{name}", kind.as_str())) + Ok(format!("{ROOT}/{}/{name}", <&str>::from(kind))) } /// A path segment that cannot change the path's shape. @@ -183,7 +175,7 @@ mod tests { // without a segment here would be granted by accident rather than by // decision. Spelling each one out is what makes adding a kind a // deliberate edit. - let segments: Vec<&str> = Kind::ALL.iter().map(|k| k.as_str()).collect(); + let segments: Vec<&str> = Kind::ALL.iter().map(|k| (*k).into()).collect(); assert_eq!(segments, ["agents", "hives", "services", "controller"]); } @@ -194,7 +186,11 @@ mod tests { // make the error name the wrong one. for (i, a) in Kind::ALL.iter().enumerate() { for b in &Kind::ALL[i + 1..] { - assert_ne!(a.as_str(), b.as_str(), "{a:?} and {b:?} share a segment"); + assert_ne!( + <&str>::from(*a), + <&str>::from(*b), + "{a:?} and {b:?} share a segment" + ); assert_ne!(a.label(), b.label(), "{a:?} and {b:?} share a label"); } } diff --git a/swarm-secret-client/src/policy.rs b/swarm-secret-client/src/policy.rs index cd796346..897b45b5 100644 --- a/swarm-secret-client/src/policy.rs +++ b/swarm-secret-client/src/policy.rs @@ -54,7 +54,7 @@ pub fn hive_object_name(hive: &str) -> Result { pub fn render() -> String { format!( "path \"{MOUNT}/data/{ROOT}/{}/*\" {{\n capabilities = [\"read\"]\n}}\n", - Kind::Agent.as_str() + <&str>::from(Kind::Agent) ) }