Skip to content

Replace custom name generator with petname - #100

Draft
tupe12334 wants to merge 1 commit into
mainfrom
moadim/replace-name-gen-with-petname
Draft

Replace custom name generator with petname#100
tupe12334 wants to merge 1 commit into
mainfrom
moadim/replace-name-gen-with-petname

Conversation

@tupe12334

Copy link
Copy Markdown
Member

Opened automatically by the moadim routine "Replace custom code with existing lib, or extract to new lib → draft PR / issue (one repo/run) → Slack".

The custom code today

src/name_gen.rs:1-43 (called from src/multi_workspace.rs:37 inside create_multi_workspace()):

const ADJECTIVES: &[&str] = &["bold", "bright", "brave", /* ...20 total */];
const NOUNS: &[&str] = &["turing", "neumann", "lovelace", /* ...20 total */];

pub fn generate_name() -> String {
    let id = Uuid::new_v4();
    let b = id.as_bytes();
    let adj = ADJECTIVES[b[0] as usize % ADJECTIVES.len()];
    let noun = NOUNS[b[1] as usize % NOUNS.len()];
    format!("{adj}_{noun}")
}

It hand-rolls a Docker/Heroku-style adjective_noun random name for each new multi-repo workspace directory, burning a full UUID v4 just to get two random bytes as array indices. Only 20×20 = 400 possible names, and the distribution is uneven since 256 isn't evenly divisible by 20.

Proposed library: petname (docs.rs)

  • Purpose-built for exactly this use case — it's the standard crate people reach for to generate Docker/Heroku-style random resource names.
  • Bigger, curated word lists and a proper RNG-backed Namer/petname() API instead of UUID-byte modulo.
  • Popularity/maintenance: ~1.7M total downloads, ~146K/month, Rename daemon subcommand to scheme, remove install action #3-ranked CLI-utility crate on lib.rs, 54 dependent crates. Latest release 3.1.0, actively maintained.
  • License: Apache-2.0 — compatible with this repo's MIT license (the standard MIT/Apache-2.0 pairing used throughout the Rust ecosystem).

What this PR does

  • Adds petname = "3" to Cargo.toml.
  • Reimplements name_gen::generate_name() on top of petname::petname(2, "_"), keeping the same function signature so the call site in multi_workspace.rs needs no change.
  • Updates the two unit tests to check the new word source's shape (two non-empty parts joined by _, and non-degenerate distinctness across draws) instead of asserting against the old hardcoded word lists.
  • uuid stays as a dependency — it's used elsewhere in the crate (hooks.rs, opener/*, issue/*) and isn't being removed.

Before/after call site (multi_workspace.rs:37, unchanged by this PR):

let root = workspaces_root.join(name_gen::generate_name());

Verified locally: cargo build succeeds and cargo test --lib name_gen passes (2/2).

Trade-offs

  • New direct dependency (petname); dependency weight is modest since uuid's v4 feature already pulls in RNG machinery.
  • Output vocabulary changes — bigger/different word lists than the old 20/20 arrays. Purely cosmetic; nothing in the crate parses or asserts on specific adjective/noun values outside the now-updated name_gen tests.
  • Cargo.toml denies clippy::pedantic/nursery/cargo and missing_docs — the new code keeps doc comments and avoids .expect() (uses unwrap_or_else instead, since expect_used is denied here) to satisfy those gates.
  • Could not run the full cargo clippy --all-targets gate in this environment — it fails on a pre-existing, unrelated allow_attributes_without_reason violation in src/issue/paths.rs that predates this change. Worth a clean clippy run before merge.

Checklist for whoever picks this up

  • Run cargo clippy --all-targets --all-features on a clean checkout and confirm no new lint violations from this diff
  • Decide on petname version pin / feature flags (default default-rng + default-words used here)
  • Skim the new word list output for anything undesirable as a directory name (petname's default lists are curated, but worth a glance)
  • Merge Cargo.lock update cleanly with any concurrent dependency changes

src/name_gen.rs re-implemented Docker-style adjective_noun name
generation by burning a UUID v4 just to index two hardcoded 20-word
arrays (400 possible names, uneven distribution since 256 % 20 != 0).
petname is the standard crate for exactly this use case: bigger
curated word lists, proper RNG, actively maintained.
@tupe12334 tupe12334 added the enhancement New feature or request label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant