pub enum Ref {
Doi(Doi),
Arxiv(ArxivId),
}Expand description
A reference to a paper, either by DOI or arXiv id.
See docs/SECURITY.md §1.1 for input-validation rules.
Variants§
Implementations§
Source§impl Ref
impl Ref
Sourcepub fn promote(
&self,
resolver_profile: &str,
version: Option<&str>,
) -> CanonicalRef
pub fn promote( &self, resolver_profile: &str, version: Option<&str>, ) -> CanonicalRef
Promote a Ref to a CanonicalRef under the given resolver
profile and optional version (ADR-0021 §1).
resolver_profile MUST be the resolver key that produced (or is
about to produce) the audit identity — e.g. "crossref" for
Crossref metadata, "oa-publisher" for the publisher-side OA
PDF leg, "arxiv" for arXiv. The string is byte-for-byte fed
into the SHA-256 input.
version is the optional source-specific version token (arXiv
"v2", Crossref snapshot date). None selects the empty-bytes
branch of the digest algorithm.
Source§impl Ref
impl Ref
Sourcepub fn parse(s: &str) -> Result<Self, RefParseError>
pub fn parse(s: &str) -> Result<Self, RefParseError>
Parses a string into a Ref, auto-detecting DOI vs arXiv.
Detection rules:
- If the input begins with the case-insensitive
doi:scheme, the remainder is parsed as a DOI. - If the input begins with the
arxiv:orarXiv:scheme, the remainder is parsed as an arXiv id. - Otherwise, if the input starts with
10.it is treated as a bare DOI; this matches the heuristic indocs/SAFEKEY.md§4 (Julia reference) and is stable because DOIs always begin10.. - Failing all of the above, parsing falls back to arXiv.
The returned Ref never carries the URI scheme — as_str() on the
inner Doi / ArxivId is always the bare identifier.
§Errors
Returns a RefParseError from the underlying Doi::parse or
ArxivId::parse call. When the input has an explicit scheme
(doi: / arxiv:), the matching parser is dispatched and its error
surfaces directly. When the input is bare and ambiguous, the
heuristic in rule 3/4 selects the parser; an unparsable bare input
surfaces the arXiv parser’s error (a non-10. ref that also fails
arXiv validation is never a valid DOI).
Source§impl Ref
impl Ref
Sourcepub fn as_input_str(&self) -> &str
pub fn as_input_str(&self) -> &str
Returns the bare identifier string usable as a provenance ref field.
Equivalent to Doi::as_str / ArxivId::as_str dispatched on the
variant — the URI scheme (doi: / arxiv:) is never present in the
inner identifiers (it is stripped at parse time), so the result is
always the bare DOI or arXiv id. Used by the CLI / MCP orchestrators
to populate the ref column of provenance log rows
(docs/PROVENANCE_LOG.md §3) without re-matching the variant.
Sourcepub fn safekey(&self) -> Safekey
pub fn safekey(&self) -> Safekey
Derives a deterministic, filesystem-safe key from this reference.
The algorithm is the NORMATIVE binding spec in docs/SAFEKEY.md §3.
Both Rust and Julia implementations MUST produce bit-identical output
for every entry in tests/fixtures/safekey/vectors.json.
§Algorithm summary
- Prefix with
doi_orarxiv_(per variant). - Replace any character outside
[A-Za-z0-9._-]with_. - Collapse consecutive
_runs to a single_. - Trim leading/trailing
_. - If the result exceeds 192 bytes, take the first 192 bytes plus
_plus the first 8 hex chars ofSHA-256(raw)(whererawis the step-1 output, before escaping).
The bound on as_str() after step 4 is pure ASCII (steps 1-3 produce
only ASCII bytes), so the byte-slice in step 5 cannot split a
multibyte char.