Struct git_attributes::NameRef
source · pub struct NameRef<'a>(_);
Expand description
Holds a validated attribute name as a reference
Implementations§
source§impl<'a> NameRef<'a>
impl<'a> NameRef<'a>
sourcepub fn to_owned(self) -> Name
pub fn to_owned(self) -> Name
Turn this ref into its owned counterpart.
Examples found in repository?
More examples
src/parse/attribute.rs (line 148)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
fn parse_line(line: &BStr, line_number: usize) -> Option<Result<(Kind, Iter<'_>, usize), Error>> {
if line.is_empty() {
return None;
}
let (line, attrs): (Cow<'_, _>, _) = if line.starts_with(b"\"") {
let (unquoted, consumed) = match git_quote::ansi_c::undo(line) {
Ok(res) => res,
Err(err) => return Some(Err(err.into())),
};
(unquoted, &line[consumed..])
} else {
line.find_byteset(BLANKS)
.map(|pos| (line[..pos].as_bstr().into(), line[pos..].as_bstr()))
.unwrap_or((line.into(), [].as_bstr()))
};
let kind_res = match line.strip_prefix(b"[attr]") {
Some(macro_name) => check_attr(macro_name.into())
.map(|name| Kind::Macro(name.to_owned()))
.map_err(|err| Error::MacroName {
line_number,
macro_name: err.attribute,
}),
None => {
let pattern = git_glob::Pattern::from_bytes(line.as_ref())?;
if pattern.mode.contains(git_glob::pattern::Mode::NEGATIVE) {
Err(Error::PatternNegation {
line: line.into_owned(),
line_number,
})
} else {
Ok(Kind::Pattern(pattern))
}
}
};
let kind = match kind_res {
Ok(kind) => kind,
Err(err) => return Some(Err(err)),
};
Ok((kind, Iter::new(attrs), line_number)).into()
}
Trait Implementations§
source§impl<'a> Ord for NameRef<'a>
impl<'a> Ord for NameRef<'a>
1.21.0 · 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<'a> PartialEq<NameRef<'a>> for NameRef<'a>
impl<'a> PartialEq<NameRef<'a>> for NameRef<'a>
source§impl<'a> PartialOrd<NameRef<'a>> for NameRef<'a>
impl<'a> PartialOrd<NameRef<'a>> for NameRef<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more