Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Note that `as_bstring()` cannot happens as `as` implies a cheap and
trivial conversion, usually no more than a reference to something.
  • Loading branch information
Byron committed Jul 24, 2022
1 parent 7b61506 commit 1cbc142
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion git-attributes/src/match_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Pattern for Attributes {
let (pattern, value) = match pattern_kind {
crate::parse::Kind::Macro(macro_name) => (
git_glob::Pattern {
text: macro_name.as_bstring(),
text: macro_name.as_str().into(),
mode: git_glob::pattern::Mode::all(),
first_wildcard_pos: None,
},
Expand Down
12 changes: 8 additions & 4 deletions git-attributes/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ impl<'a> NameRef<'a> {
pub fn as_str(&self) -> &str {
self.0
}
}

pub fn as_bstring(self) -> BString {
self.0.into()
impl AsRef<str> for NameRef<'_> {
fn as_ref(&self) -> &str {
self.0
}
}

Expand All @@ -23,9 +25,11 @@ impl<'a> Name {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}

pub fn as_bstring(self) -> BString {
self.0.as_str().into()
impl AsRef<str> for Name {
fn as_ref(&self) -> &str {
self.0.as_str()
}
}

Expand Down
2 changes: 1 addition & 1 deletion git-attributes/tests/parse/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fn expand(
) -> Result<ExpandedAttribute<'_>, parse::Error> {
let (pattern, attrs, line_no) = input?;
let attrs = attrs
.map(|r| r.map(|attr| (attr.name.as_bstring(), attr.state)))
.map(|r| r.map(|attr| (attr.name.as_str().into(), attr.state)))
.collect::<Result<Vec<_>, _>>()
.map_err(|e| parse::Error::AttributeName {
attribute: e.attribute,
Expand Down
2 changes: 1 addition & 1 deletion git-pathspec/tests/pathspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod parse {
attributes: p
.attributes
.into_iter()
.map(|attr| (attr.name.as_bstring(), attr.state))
.map(|attr| (attr.name.as_str().into(), attr.state))
.collect(),
}
}
Expand Down

0 comments on commit 1cbc142

Please sign in to comment.