remove as_str() legacy wrappers, callers use .into() directly
This commit is contained in:
parent
299add158f
commit
46456f75ce
25 changed files with 46 additions and 128 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(", ")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)"),
|
||||
|
|
|
|||
|
|
@ -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/<n>` 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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -719,7 +719,7 @@ fn render(declaration: &swarm_queue_client::wanted::HiveWanted) -> Vec<AgentDecl
|
|||
.iter()
|
||||
.map(|(agent, wanted)| AgentDeclaration {
|
||||
agent: agent.clone(),
|
||||
state: wanted.state.as_str().to_owned(),
|
||||
state: <&str>::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())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Self> {
|
||||
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"
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, Error> {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ pub fn hive_object_name(hive: &str) -> Result<String, Error> {
|
|||
pub fn render() -> String {
|
||||
format!(
|
||||
"path \"{MOUNT}/data/{ROOT}/{}/*\" {{\n capabilities = [\"read\"]\n}}\n",
|
||||
Kind::Agent.as_str()
|
||||
<&str>::from(Kind::Agent)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue