From 8a27454a9738f077309104fde02d589d052e9f11 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 8 Aug 2024 17:03:28 +0200 Subject: [PATCH] feat: `remote::Name::to_owned()` to get a static version of it. Also, add optional `serde` support. --- gix/src/remote/mod.rs | 1 + gix/src/remote/name.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/gix/src/remote/mod.rs b/gix/src/remote/mod.rs index a4167ca8588..1a545475479 100644 --- a/gix/src/remote/mod.rs +++ b/gix/src/remote/mod.rs @@ -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. diff --git a/gix/src/remote/name.rs b/gix/src/remote/name.rs index f0081cc30df..67af8e19ca6 100644 --- a/gix/src/remote/name.rs +++ b/gix/src/remote/name.rs @@ -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> for Name<'a> {