Skip to main content

slugify_string

Function slugify_string 

Source
pub fn slugify_string(input: &str) -> String
Expand description

String-level slug helper used by slugify_for_palace.

Why: exposed separately so the CLI can slugify an arbitrary repo name (e.g. from --to my_project) without re-deriving from a path. As of #1348 the implementation lives in trusty-common as the single source of truth (shared with trusty-controller’s tctl ensure); this is a re-export shim kept so the many trusty_memory::messaging::slugify_string call sites do not churn. What: re-exports trusty_common::slugify_string verbatim. Test: canonical cases pinned in trusty-common (slug::tests); parity re-asserted here in tests::slug_derivation_cases. Canonicalise an arbitrary string into a stable project slug.

Why: a project’s palace name / index id must be derived deterministically so re-running derivation (across renames, casing differences, or underscore-vs-hyphen typing) yields the same token — otherwise two callers produce two different palaces for the same project, or the trusty-memory daemon’s validate_palace_name rejects creation because the controller’s slug disagrees with the daemon’s. This is the single source of truth for that rule (issue #1348). What: lower-cases the trimmed input, strips a trailing .git, then maps each character: [a-z0-9] pass through verbatim; _, -, space, and tab each become a single - (runs collapse to one, never leading); every other character (including /, !, and non-ASCII) is stripped entirely. Leading and trailing - are trimmed. A pure-unicode input yields an empty string — callers must guard that case. Test: slug::tests::slug_derivation_cases.