Skip to main content

Ref

Enum Ref 

Source
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§

§

Doi(Doi)

A DOI (e.g., 10.1234/example).

§

Arxiv(ArxivId)

An arXiv id (e.g., 2401.12345).

Implementations§

Source§

impl Ref

Source

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

Source

pub fn parse(s: &str) -> Result<Self, RefParseError>

Parses a string into a Ref, auto-detecting DOI vs arXiv.

Detection rules:

  1. If the input begins with the case-insensitive doi: scheme, the remainder is parsed as a DOI.
  2. If the input begins with the arxiv: or arXiv: scheme, the remainder is parsed as an arXiv id.
  3. Otherwise, if the input starts with 10. it is treated as a bare DOI; this matches the heuristic in docs/SAFEKEY.md §4 (Julia reference) and is stable because DOIs always begin 10..
  4. 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

Source

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.

Source

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
  1. Prefix with doi_ or arxiv_ (per variant).
  2. Replace any character outside [A-Za-z0-9._-] with _.
  3. Collapse consecutive _ runs to a single _.
  4. Trim leading/trailing _.
  5. If the result exceeds 192 bytes, take the first 192 bytes plus _ plus the first 8 hex chars of SHA-256(raw) (where raw is 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.

Trait Implementations§

Source§

impl Clone for Ref

Source§

fn clone(&self) -> Ref

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ref

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Ref

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for Ref

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Ref

Source§

fn eq(&self, other: &Ref) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Ref

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Ref

Source§

impl StructuralPartialEq for Ref

Auto Trait Implementations§

§

impl Freeze for Ref

§

impl RefUnwindSafe for Ref

§

impl Send for Ref

§

impl Sync for Ref

§

impl Unpin for Ref

§

impl UnsafeUnpin for Ref

§

impl UnwindSafe for Ref

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,