git-ref-format: Component::from_refstr

Improve Component::from_refstring by redefining it as
Component::from_refstr. This allows the use of `RefStr` or `RefString`
instead of just RefString.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2022-11-16 13:47:22 +00:00
parent 629191f55a
commit d6c7bb29ab
+4 -3
View File
@@ -9,7 +9,7 @@ use std::{
ops::Deref,
};
use super::{RefStr, RefString};
use super::RefStr;
use crate::lit;
pub type Iter<'a> = std::str::Split<'a, char>;
@@ -52,9 +52,10 @@ pub struct Component<'a>(Cow<'a, RefStr>);
impl<'a> Component<'a> {
#[inline]
pub fn from_refstring(r: RefString) -> Option<Self> {
pub fn from_refstr(r: impl Into<Cow<'a, RefStr>>) -> Option<Self> {
let r = r.into();
if !r.contains('/') {
Some(Self(Cow::Owned(r)))
Some(Self(r))
} else {
None
}