Skip to main content

FlakeRef

Struct FlakeRef 

Source
#[non_exhaustive]
pub struct FlakeRef { /* private fields */ }
Expand description

The General Flake Ref Schema

Implementations§

Source§

impl FlakeRef

Source

pub fn new(kind: FlakeRefType) -> Self

Construct a FlakeRef around kind with no fragment and an empty LocationParameters block. Use the consuming with_* builders or the set_* mutators to fill in the rest.

Source

pub fn kind(&self) -> &FlakeRefType

Read access to the kind. Pattern-matching consumers go through this accessor rather than the (private) field directly.

Source

pub fn kind_mut(&mut self) -> &mut FlakeRefType

Mutable access to the kind for in-place edits. The consuming Self::with_kind builder is the right tool when chaining; reach for kind_mut only when you must rewrite a field on a borrowed FlakeRef.

Source

pub fn id(&self) -> Option<&str>

The repo identifier for the kind (repo for GitForge, the trailing path segment of a Resource(Git) URL); None otherwise.

Source

pub fn owner(&self) -> Option<&str>

Owner (organisation/user) for the kind, when applicable. Returns Some for GitForge and for Resource(Git) URLs that look like domain/owner/repo; None for Path, Indirect, and other resources.

Source

pub fn repo(&self) -> Option<&str>

Repository name for the kind, when applicable. See Self::owner for the kinds that produce Some.

Source

pub fn domain(&self) -> Option<&str>

Domain (host) for the kind, when applicable. Returns the canonical host string for git-forge platforms (github.com, gitlab.com, git.sr.ht) – or the ?host= override for self-hosted instances – and the host portion of a Resource(Git) URL (with :port retained when the port is non-default for the scheme); None otherwise.

Matches Nix’s per-scheme host resolution: the host attr defaults to the canonical domain.

Source

pub fn forge_identity(&self) -> Option<ForgeIdentity>

Bundled identity for git-forge kinds. Returns Some only for FlakeRefType::GitForge; Resource(Git) URLs do not have a guaranteed-parseable owner/repo/domain triple, and Path / Indirect have no identity at all.

Honours the ?host= override (matching Nix’s per-scheme host resolution); falls back to the platform’s canonical domain when no override is set. The SourceHut canonical default stays git.sr.ht rather than the apex sr.ht, which does not serve git over HTTPS.

Source

pub fn ref_(&self) -> Option<&str>

The ref_ (branch or tag name) for kinds that carry one, borrowed.

Source

pub fn rev(&self) -> Option<&str>

The rev (40-hex commit hash) for kinds that carry one, borrowed.

Source

pub fn ref_or_rev(&self) -> Option<&str>

Whichever of rev / ref_ is set, preferring rev when pinned; the typical “what does this ref resolve to?” answer. Returns borrowed &str; callers wanting an owned String use .map(str::to_owned).

Source

pub fn ref_kind(&self) -> RefKind

Discriminates which of ref_ / rev are populated; useful when the caller needs to switch on the four-way combination without writing nested Option matches.

Source

pub fn is_pinned_to_rev(&self) -> bool

true when the kind has a rev set (canonical Nix’s “pinned to a commit”). False for refs-by-name and for kinds that don’t carry rev at all.

Source

pub fn ref_source_location(&self) -> RefLocation

Where the kind’s ref/rev is rendered. Reads the kind’s RefLocation directly; Path is fixed at QueryParameter because its rev has no path-component spelling in Nix’s grammar.

Source

pub fn params(&self) -> &LocationParameters

Read-only access to the query-string parameters.

Source

pub fn fragment(&self) -> Option<&str>

Trailing #fragment retained verbatim. Nix uses fragments to select an attribute path inside a flake (e.g. github:nixos/nixpkgs#hello); the raw string is preserved without interpretation.

Source

pub fn set_ref(&mut self, new_ref: Option<String>)

Write new_ref into the kind’s typed ref_ slot. Silently no-op for kinds that do not carry ref/rev. For FlakeRefType::Resource, writing a non-None value also flips ref_location to RefLocation::QueryParameter; Resource has no path-component ref/rev representation, so leaving it as PathComponent would cause Display to drop the value silently.

Source

pub fn set_rev(&mut self, new_rev: Option<String>)

Write new_rev into the kind’s typed rev slot. See Self::set_ref for the Resource ref_location flip rationale.

Source

pub fn set_fragment(&mut self, fragment: Option<String>)

Write fragment (the #suffix) into the typed slot.

Source

pub fn set_ref_location(&mut self, loc: RefLocation)

Set RefLocation on the kind’s ref_location slot. Renamed from set_location, which was easy to misread as “modify the URL location string”; this method writes the routing tag that controls whether ref/rev render as ?ref= or as a path component.

Source

pub fn set_dir(&mut self, dir: Option<String>)

Typed mutator for the dir query parameter.

Source

pub fn set_host(&mut self, host: Option<String>)

Typed mutator for the host query parameter.

Source

pub fn set_shallow(&mut self, shallow: bool)

Typed mutator for the shallow query parameter. true enables a shallow clone (mapped to ?shallow=1 on Display); false writes ?shallow=0. Pass through LocationParameters::set_shallow to clear the slot entirely.

Source

pub fn set_submodules(&mut self, submodules: bool)

Typed mutator for the submodules query parameter; behaves like Self::set_shallow.

Source

pub fn set_nar_hash(&mut self, hash: Option<String>)

Typed mutator for the narHash query parameter.

Source

pub fn set_last_modified(&mut self, ts: Option<String>)

Typed mutator for the lastModified query parameter.

Source

pub fn set_rev_count(&mut self, count: Option<String>)

Typed mutator for the revCount query parameter.

Source

pub fn with_ref(self, r: Option<String>) -> Self

Consuming builder variant of Self::set_ref. Silently no-ops on kinds without a ref_ slot (FlakeRefType::Path); see Self::try_with_ref for the loud opt-in alternative that surfaces a typed error instead.

Source

pub fn with_rev(self, r: Option<String>) -> Self

Consuming builder variant of Self::set_rev. See Self::try_with_rev for the fallible variant kept for API symmetry with Self::try_with_ref.

Source

pub fn try_with_ref(self, new_ref: Option<String>) -> Result<Self, NixUriError>

Fallible variant of Self::with_ref: returns NixUriError::Unsupported when the kind cannot carry a ref per Nix’s per-scheme attribute rules.

Surfaces UnsupportedReason::Field for kinds outside the ref-bearing set (FlakeRefType::Path, ResourceType::File and ResourceType::Tarball). Setting a ref on these kinds via Self::with_ref is a silent no-op (Path) or renders a string the parser would reject (File/Tarball, breaking the round-trip invariant); try_with_ref lets callers diagnose the mismatch at the call site.

try_with_ref(None) is always Ok: clearing has no Nix-level implications.

Source

pub fn try_with_rev(self, new_rev: Option<String>) -> Result<Self, NixUriError>

Fallible variant of Self::with_rev. All current kinds permit rev per Nix’s per-scheme attribute rules, so this method always returns Ok. It exists for API symmetry with Self::try_with_ref so callers can write the same fallible-builder shape regardless of which slot they are writing.

Source

pub fn with_fragment(self, fragment: Option<String>) -> Self

Consuming builder variant of Self::set_fragment.

Source

pub fn with_kind(self, kind: FlakeRefType) -> Self

Consuming builder that sets the kind in a chain.

Source

pub fn with_params(self, params: LocationParameters) -> Self

Consuming builder that installs a fresh LocationParameters block. For incremental edits, use the typed set_* mutators instead.

Source

pub fn without_pin(self) -> Self

Clear the rev slot (the “pin”); leaves ref_ alone. Useful when the caller wants the named branch/tag rather than a specific commit.

Source

pub fn pin_to_rev(self, rev: String) -> Self

Pin to a specific commit, clearing any pre-existing ref_ first.

with_rev(Some(rev)) writes only the rev slot, leaving any ref_ already on the kind in place. The GitForge Display arm renders ref_.or(rev) when RefLocation::PathComponent is active, so a ref_-bearing forge URL with a freshly written rev round-trips back to the named ref and silently drops the pinned commit. pin_to_rev is the atomic builder that performs the clear-ref-then-set-rev sequence callers want.

For kinds without a ref_ slot (FlakeRefType::Path), this only writes the rev; there is no ref to clear.

Source

pub fn into_uri(self) -> String

Consume and render to a String; the same output as to_string but without an intermediate clone when the caller already owns self.

Source

pub fn to_canonical_string(&self) -> String

Canonical wire form of this FlakeRef, matching the URL Nix would emit for the same input.

Pairs with Display (and the equivalent Self::into_uri), which preserves the input verbatim for byte-stable round-trips. to_canonical_string instead emits the form Nix would produce, normalising every shape that Nix collapses on the way out:

  • GitForge (github: / gitlab: / sourcehut:): renders as <scheme>:<owner>/<repo>[/<ref-or-rev>] regardless of where the parsed value came from. rev wins over ref_ when both are populated, matching Nix’s behaviour (Nix asserts that ref and rev are never both set on a git-archive URL, so the both-set case is nonsensical for consumers). The query carries only host and narHash when set.
  • Resource(Git): emits ref and rev always when set, and the typed booleans (shallow, lfs, submodules, exportIgnore, verifyCommit) only for the truthy branch. allRefs is never emitted because Nix’s git scheme does not include it on canonical output. narHash, lastModified, revCount, dir, host, and arbitrary keys are dropped.
  • Resource(Mercurial): emits only ref and rev.
  • Indirect, Path, Resource(File), Resource(Tarball): delegated to Display; their existing form already matches Nix byte-for-byte.

Use this when handing a string to a Nix consumer that expects the canonical spelling; reach for Display / Self::into_uri when round-tripping a user-supplied URL byte-for-byte.

Trait Implementations§

Source§

impl Clone for FlakeRef

Source§

fn clone(&self) -> FlakeRef

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 FlakeRef

Source§

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

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

impl Default for FlakeRef

Source§

fn default() -> FlakeRef

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for FlakeRef

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 Display for FlakeRef

Source§

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

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

impl FromStr for FlakeRef

Source§

type Err = NixUriError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for FlakeRef

Source§

fn eq(&self, other: &FlakeRef) -> 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 FlakeRef

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 TryFrom<&str> for FlakeRef

Source§

type Error = NixUriError

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for FlakeRef

Source§

impl StructuralPartialEq for FlakeRef

Auto Trait Implementations§

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, 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,