pub struct Doi(/* private fields */);Expand description
A validated DOI string.
Construct via Doi::parse(s) (Phase 1+). The inner field is intentionally
pub(crate) to forbid bypass construction; tests inside doiget-core may
still use Doi(s) for fixture purposes.
Wire format: bare string (#[serde(transparent)]), e.g. "10.1234/example".
Implementations§
Source§impl Doi
impl Doi
Sourcepub fn prefix(&self) -> &str
pub fn prefix(&self) -> &str
The DOI registrant prefix — everything before the first /, e.g.
"10.1103" for 10.1103/PhysRevLett.116.061102.
Used to scope publisher-specific Tier-3 TDM sources to the DOIs
their publisher actually registered (#442). Doi is only ever
constructed through Doi::parse, which requires the
10.<registrant>/<suffix> shape, so the / is always present;
the fallback returns the whole string rather than panicking.
Sourcepub fn parse(s: &str) -> Result<Self, RefParseError>
pub fn parse(s: &str) -> Result<Self, RefParseError>
Parses and validates a DOI string per docs/SECURITY.md §1.1.
Accepts:
- Bare DOIs:
10.<registrant>/<suffix>where<registrant>is 4–9 digits and<suffix>is a non-empty sequence of characters drawn from[A-Za-z0-9._/():-](the:covers legacy Kluwer10.1023/A:NNNNand EDP Sciences10.1051/jphys:NNNNDOIs). - The
doi:URI scheme prefix; it is stripped before validation, so the stored value never carries a scheme. (Matches the convention established indocs/SAFEKEY.md§3 step 0.)
Rejects:
- Inputs missing the literal
10.prefix (after optional scheme strip). - Suffixes longer than
DOI_SUFFIX_MAX_LENbytes. - Empty suffixes.
- Any character outside the suffix charset above (including control characters, whitespace, and non-ASCII).
§Errors
Returns a RefParseError variant that names the specific rejection
category. Tier 1+ callers should map any RefParseError to
ErrorCode::InvalidRef when surfacing to MCP / CLI.