Skip to main content

Ref

Enum Ref 

Source
pub enum Ref {
    Local {
        name: String,
    },
    Remote {
        remote: String,
        name: String,
    },
    Collection {
        id: String,
        name: String,
    },
}
Expand description

One ref of a repository.

A ref has three cases, and each case has a text form:

  • NAME is the local ref Ref::Local, at refs/heads/NAME.
  • REMOTE:NAME is the remote ref Ref::Remote, at refs/remotes/REMOTE/NAME.
  • @ID:NAME is the collection ref Ref::Collection, at refs/mirrors/ID/NAME. A repository whose [core] collection-id is ID keeps the ref at refs/heads/NAME, so @ID:NAME and NAME name the same ref there. canonical gives the local form.

No valid ref name holds @ or :, so the three forms do not overlap.

The constructors do not check the value. validate checks it, and a ref store checks it before it reads or writes a file. FromStr reads the text and checks it. Display gives the same text back.

§Examples

use ostrya_core::Ref;

let r: Ref = "@org.example.Os:os/x86_64".parse()?;
assert_eq!(r, Ref::collection("org.example.Os", "os/x86_64"));
assert_eq!(r.name(), "os/x86_64");
assert_eq!(r.to_string(), "@org.example.Os:os/x86_64");
assert_eq!("origin:main".parse::<Ref>()?, Ref::remote("origin", "main"));
assert!("@org.example.Os:a:b".parse::<Ref>().is_err());

Variants§

§

Local

A local ref, at refs/heads/<name>.

Fields

§name: String

The ref name, which can contain /.

§

Remote

A remote ref, at refs/remotes/<remote>/<name>.

Fields

§remote: String

The name of the remote.

§name: String

The ref name, which can contain /.

§

Collection

A collection ref, at refs/mirrors/<id>/<name>, or at refs/heads/<name> when id is the [core] collection-id of the repository.

Fields

§id: String

The collection id.

§name: String

The ref name, which can contain /.

Implementations§

Source§

impl Ref

Source

pub fn local(name: impl Into<String>) -> Ref

Creates a local ref. The call does not check the name.

Source

pub fn remote(remote: impl Into<String>, name: impl Into<String>) -> Ref

Creates a remote ref. The call does not check the values.

Source

pub fn collection(id: impl Into<String>, name: impl Into<String>) -> Ref

Creates a collection ref. The call does not check the values.

Source

pub fn name(&self) -> &str

Returns the ref name, without the remote or the collection id.

Source

pub fn canonical(self, own: Option<&str>) -> Ref

Returns the canonical form of the ref in a repository whose [core] collection-id is own.

A collection ref of own is the local ref of the same name, because the repository keeps it at refs/heads/<name>. Each other ref is returned unchanged, and so is each ref if own is None. The call does not check the ref or own.

Source

pub fn in_collection(self, id: &str) -> Result<Ref, Ref>

Puts a local ref in the collection id.

A local ref NAME becomes @ID:NAME. A collection ref of id stays, and so does a remote ref. The call does not check the ref or id.

§Errors

Gives back the ref unchanged if it is a collection ref of another id.

Source

pub fn namespace(&self) -> RefNamespace<'_>

Returns the namespace of the ref: the local refs, the refs of one remote, or the refs of one collection id.

The call does not canonicalize the ref. A collection ref of the own id of a repository is in the namespace of its local refs only after canonical.

Source

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

Returns true if the refs self and other are in one namespace: both local, both of one remote, or both of one collection id.

Source

pub fn collection_conflict<'a>( refs: impl IntoIterator<Item = &'a Ref>, ) -> Option<(&'a Ref, &'a Ref)>

Returns the first ref of refs that is in another collection than an earlier ref of refs, with that earlier ref.

The refs that are not collection refs are ignored. The call returns None if the collection refs of refs hold one collection id.

Source

pub fn validate(&self) -> Result<(), ParseRefError>

Checks the ref against the ref-name rule.

The ref name must pass is_ref_name in each case. The remote of Ref::Remote must pass is_ref_name_component. The id of Ref::Collection must pass is_collection_id and be at most MAX_COLLECTION_ID_LEN bytes. So the path of a valid ref stays inside the refs/ tree.

§Errors

ParseRefError if a part fails its rule. The error holds the text of the ref.

Trait Implementations§

Source§

impl Clone for Ref

Source§

fn clone(&self) -> Self

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

Source§

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

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

impl Eq for Ref

Source§

impl FromStr for Ref

Source§

fn from_str(text: &str) -> Result<Ref, ParseRefError>

Reads the text form of a ref and checks it with validate.

Text that starts with @ is a collection ref, split at the first : after the @. Other text with a : is a remote ref, split at the first :. Text with no : is a local ref.

§Errors

ParseRefError if the text has no form or a part fails its rule. The error holds the text as given.

Source§

type Err = ParseRefError

The associated error which can be returned from parsing.
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 Ord for Ref

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Ref

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Ref

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Ref

Auto Trait Implementations§

§

impl Forget for Ref

§

impl Freeze for Ref
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for Ref

§

impl RefUnwindSafe for Ref

§

impl Send for Ref
where RawVecInner: Send,

§

impl Sync for Ref
where RawVecInner: Sync,

§

impl Unpin for Ref
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Ref

§

impl UnwindSafe for Ref
where RawVecInner: UnwindSafe,

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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.