Skip to content

Commit

Permalink
feat: remote::Name::to_owned() to get a static version of it.
Browse files Browse the repository at this point in the history
Also, add optional `serde` support.
  • Loading branch information
Byron committed Aug 8, 2024
1 parent b0668fb commit 8a27454
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions gix/src/remote/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl Direction {

/// The name of a remote, either interpreted as symbol like `origin` or as url as returned by [`Remote::name()`][crate::Remote::name()].
#[derive(Debug, PartialEq, Eq, Clone, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Name<'repo> {
/// A symbolic name, like `origin`.
/// Note that it has not necessarily been validated yet.
Expand Down
8 changes: 8 additions & 0 deletions gix/src/remote/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ impl Name<'_> {
Name::Symbol(_) => None,
}
}

/// Return a fully-owned copy of this instance.
pub fn to_owned(&self) -> Name<'static> {
match self {
Name::Symbol(s) => Name::Symbol(s.clone().into_owned().into()),
Name::Url(s) => Name::Url(s.clone().into_owned().into()),
}
}
}

impl<'a> TryFrom<Cow<'a, BStr>> for Name<'a> {
Expand Down

0 comments on commit 8a27454

Please sign in to comment.