id

Two-tone entity identifier display for terminal output.

struct Component

source

pub struct Component<'a>

Displays a truncated, two-tone entity identifier (highlighted prefix + dimmed suffix).

At most 8 characters are shown. The first prefix_len characters are rendered in the id.prefix style and the remainder in id.rest.

Use min_unique_prefix to compute the shortest prefix that uniquely identifies each ID in a set.

Field Type Description
prefix_len usize Number of leading characters in the prefix style; clamped to the shown length.
value &'a str Full identifier; only its first 8 characters are shown.

Implements Display.

Component::new

source

pub fn new(value: &'a str) -> Self

Create an id display, showing at most 8 characters with a 2-char highlighted prefix.

Parameter Type Description
value &'a str the full identifier
returns Self The display, with a 2-character prefix highlighted.

Component::prefix_len

source

pub fn prefix_len(self, len: usize) -> Self

Set the number of highlighted prefix characters.

Parameter Type Description
len usize the prefix length, usually from [unique_prefix_lengths]
returns Self The display with the new prefix length.

fn prefix_lengths_two_tier

source

pub fn prefix_lengths_two_tier(active_ids: &[&str], all_ids: &[&str]) -> Vec<usize>

Compute two-tier prefix lengths: active IDs are resolved against the active pool only, while archived IDs (those in all_ids but not in active_ids) are resolved against the full pool.

Parameter Type Description
active_ids &[&str] the IDs of active entities; a subset of all_ids
all_ids &[&str] every ID, active and archived, in display order
returns Vec<usize> A Vec<usize> aligned to all_ids.

fn unique_prefix_length_for_id

source

pub fn unique_prefix_length_for_id(target: &str, pool: &[&str]) -> usize

Compute the shortest prefix that distinguishes a single target ID from every other ID in the pool (each ID is first truncated to 8 chars).

The pool may optionally contain target; entries whose full string equals target are skipped once so callers can pass pools assembled via a narrow LIKE query without special-casing the target’s own row. Pool entries whose 8-char prefix collides with target’s but whose full IDs differ are treated like any other colliding entry and drive the result up to the 8-char cap.

Parameter Type Description
target &str the ID to shorten
pool &[&str] the IDs it must be told apart from; it may contain target itself
returns usize The prefix length, at least 1 and at most 8.

fn unique_prefix_lengths

source

pub fn unique_prefix_lengths(ids: &[&str]) -> Vec<usize>

Compute the shortest prefix that distinguishes each ID from every other ID in the input slice (each ID is first truncated to 8 chars).

Parameter Type Description
ids &[&str] the IDs to shorten together
returns Vec<usize> An index-aligned Vec<usize> — one prefix length per input ID. Each length is at least 1 and at most 8.