History

refactor

Sebastian Thiel committed 4 years ago

Commit 957356b1 parent 1bdf2e13 files · +22 −16Browse files

Unified · Split

3 files
  1. git-attributes/src/lib.rs +18 −2
  2. git-attributes/src/match_group.rs +0 −11
  3. git-attributes/src/parse/attribute.rs +4 −3
git-attributes/src/lib.rs+18−2
@@ -10,7 +10,7 @@ pub use git_glob as glob; · 9 unmodified lines
1010 /// The state an attribute can be in, referencing the value.
1111 ///
1212 /// Note that this doesn't contain the name.
13−#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
13+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
1414 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
1515 pub enum StateRef<'a> {
1616 /// The attribute is listed, or has the special value 'true'
@@ -37,7 +37,7 @@ pub enum State { · 20 unmodified lines
3737 Unset,
3838 /// The attribute is set to the given value, which followed the `=` sign.
3939 /// Note that values can be empty.
40− Value(CompactString),
40+ Value(CompactString), // TODO: use `kstring`, maybe it gets a binary string soon
4141 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
4242 Unspecified,
4343 }
@@ -100,6 +100,22 @@ pub struct PatternMapping<T> { · 56 unmodified lines
100100 pub sequence_number: usize,
101101 }
102102
103+mod state {
104+ use crate::{State, StateRef};
105+ use bstr::ByteSlice;
106+
107+ impl<'a> From<StateRef<'a>> for State {
108+ fn from(s: StateRef<'a>) -> Self {
109+ match s {
110+ StateRef::Value(v) => State::Value(v.to_str().expect("no illformed unicode").into()),
111+ StateRef::Set => State::Set,
112+ StateRef::Unset => State::Unset,
113+ StateRef::Unspecified => State::Unspecified,
114+ }
115+ }
116+ }
117+}
118+
103119 pub mod name {
104120 use bstr::BString;
105121
git-attributes/src/match_group.rs+0−11
@@ -6,17 +6,6 @@ use std::{ · 5 unmodified lines
66 path::{Path, PathBuf},
77 };
88
9−impl<'a> From<StateRef<'a>> for State {
10− fn from(s: StateRef<'a>) -> Self {
11− match s {
12− StateRef::Value(v) => State::Value(v.to_str().expect("no illformed unicode").into()),
13− StateRef::Set => State::Set,
14− StateRef::Unset => State::Unset,
15− StateRef::Unspecified => State::Unspecified,
16− }
17− }
18−}
19−
209 fn attrs_to_assignments<'a>(
2110 attrs: impl Iterator<Item = Result<crate::NameRef<'a>, crate::name::Error>>,
2211 ) -> Result<Vec<Assignment>, crate::name::Error> {
git-attributes/src/parse/attribute.rs+4−3
@@ -169,7 +169,7 @@ impl<'a> NameRef<'a> { · 168 unmodified lines
169169 }
170170
171171 pub fn state(&self) -> StateRef<'a> {
172− self.1.clone()
172+ self.1
173173 }
174174 }
175175
@@ -180,11 +180,12 @@ impl<'a> From<NameRef<'a>> for Name { · 4 unmodified lines
180180 }
181181
182182 impl Name {
183− pub fn name(&self) -> &BString {
184− &self.0
183+ pub fn name(&self) -> &BStr {
184+ self.0.as_bstr()
185185 }
186186
187187 pub fn state(&self) -> &State {
188+ // TODO: StateRef<'_>
188189 &self.1
189190 }
190191 }