pub struct BranchName(/* private fields */);Expand description
A branch name git would accept for refs/heads/, whose components are therefore safe
directory names.
Implementations§
Source§impl BranchName
impl BranchName
Sourcepub fn parse(name: &str) -> Result<Self>
pub fn parse(name: &str) -> Result<Self>
Validate a branch name by git’s reference rules, offline.
use majordomus_cli::worktree::BranchName;
assert!(BranchName::parse("feature/improve-cli").is_ok());
assert!(BranchName::parse("feature/providers/openai-streaming").is_ok());
assert!(BranchName::parse("žluťoučký/kůň").is_ok());
for bad in ["", "/", "a/", "/a", "a//b", "a/../b", "..", ".hidden", "a/.b", "a.lock",
"a b", "a~b", "a^b", "a:b", "a?b", "a*b", "a[b", "a\\b", "a@{b", "-x",
"a.", "a/b.lock/c", "a\u{7f}b", "a\nb"] {
assert!(BranchName::parse(bad).is_err(), "{bad:?} should be refused");
}Sourcepub fn relative_path(&self) -> PathBuf
pub fn relative_path(&self) -> PathBuf
The relative path under the container: the name’s components, one directory each.
use majordomus_cli::worktree::BranchName;
use std::path::PathBuf;
let b = BranchName::parse("fix/cockpit/reconnect").unwrap();
assert_eq!(b.relative_path(), PathBuf::from("fix/cockpit/reconnect"));Sourcepub fn components(&self) -> impl Iterator<Item = &str>
pub fn components(&self) -> impl Iterator<Item = &str>
The components, in order.
Trait Implementations§
Source§impl Clone for BranchName
impl Clone for BranchName
Source§fn clone(&self) -> BranchName
fn clone(&self) -> BranchName
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BranchName
impl Debug for BranchName
Source§impl Display for BranchName
impl Display for BranchName
impl Eq for BranchName
Source§impl Hash for BranchName
impl Hash for BranchName
Source§impl Ord for BranchName
impl Ord for BranchName
Source§fn cmp(&self, other: &BranchName) -> Ordering
fn cmp(&self, other: &BranchName) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for BranchName
impl PartialEq for BranchName
Source§fn eq(&self, other: &BranchName) -> bool
fn eq(&self, other: &BranchName) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for BranchName
impl PartialOrd for BranchName
impl StructuralPartialEq for BranchName
Auto Trait Implementations§
impl Freeze for BranchName
impl RefUnwindSafe for BranchName
impl Send for BranchName
impl Sync for BranchName
impl Unpin for BranchName
impl UnsafeUnpin for BranchName
impl UnwindSafe for BranchName
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.