Skip to content

ident: make Name's inner Vec private - #170

Closed
pcnofelt wants to merge 1 commit into
NetSys:mainfrom
pcnofelt:name-private-field
Closed

pcnofelt wants to merge 1 commit into
NetSys:mainfrom
pcnofelt:name-private-field

Conversation

@pcnofelt

Copy link
Copy Markdown
Collaborator

What

Makes Name's inner Vec<String> private.

Why

The field was public, so a caller could construct Name(vec![]) and end
up with a Name that violates the "always at least one label" invariant
that first_label() and the other label accessors rely on. FromStr
never yields an empty Name (split('.') always produces at least one
label and empty labels are rejected), so making the field private rules
out the empty case across the whole crate — the invariant now holds by
construction.

Also switches first_label()'s last().expect() to assert() to match
the house assertion style.

Scope

No code outside ident.rs constructs Name(...) as a tuple or reads
.0, so the change is contained.

🤖 Generated with Claude Code

I made the inner Vec on Name private. It was public before, so a caller
could write Name(vec![]) and end up with a Name that breaks the
"always at least one label" invariant that first_label() and friends
rely on. You can't get an empty Name through FromStr anyway, so once the
field is private that case just can't happen.

While I was in there I switched first_label()'s last().expect() over to
assert() to line up with how we handle these invariants elsewhere.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pcnofelt pcnofelt closed this Jun 21, 2026
@pcnofelt
pcnofelt deleted the name-private-field branch June 21, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant