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
10/// The state an attribute can be in, referencing the value.10/// The state an attribute can be in, referencing the value.
11///11///
12/// Note that this doesn't contain the name.12/// 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)]
14#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]14#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
15pub enum StateRef<'a> {15pub enum StateRef<'a> {
16 /// The attribute is listed, or has the special value 'true'16 /// The attribute is listed, or has the special value 'true'
@@ -37,7 +37,7 @@ pub enum State { · 20 unmodified lines
37 Unset,37 Unset,
38 /// The attribute is set to the given value, which followed the `=` sign.38 /// The attribute is set to the given value, which followed the `=` sign.
39 /// Note that values can be empty.39 /// Note that values can be empty.
40 Value(CompactString),40 Value(CompactString), // TODO: use `kstring`, maybe it gets a binary string soon
41 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.41 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
42 Unspecified,42 Unspecified,
43}43}
@@ -100,6 +100,22 @@ pub struct PatternMapping<T> { · 56 unmodified lines
100 pub sequence_number: usize,100 pub sequence_number: usize,
101}101}
102 102
103mod 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
103pub mod name {119pub mod name {
104 use bstr::BString;120 use bstr::BString;
105 121
git-attributes/src/match_group.rs+0−11
@@ -6,17 +6,6 @@ use std::{ · 5 unmodified lines
6 path::{Path, PathBuf},6 path::{Path, PathBuf},
7};7};
8 8
9impl<'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
20fn attrs_to_assignments<'a>(9fn attrs_to_assignments<'a>(
21 attrs: impl Iterator<Item = Result<crate::NameRef<'a>, crate::name::Error>>,10 attrs: impl Iterator<Item = Result<crate::NameRef<'a>, crate::name::Error>>,
22) -> Result<Vec<Assignment>, crate::name::Error> {11) -> 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
169 }169 }
170 170
171 pub fn state(&self) -> StateRef<'a> {171 pub fn state(&self) -> StateRef<'a> {
172 self.1.clone()172 self.1
173 }173 }
174}174}
175 175
@@ -180,11 +180,12 @@ impl<'a> From<NameRef<'a>> for Name { · 4 unmodified lines
180}180}
181 181
182impl Name {182impl Name {
183 pub fn name(&self) -> &BString {183 pub fn name(&self) -> &BStr {
184 &self.0184 self.0.as_bstr()
185 }185 }
186 186
187 pub fn state(&self) -> &State {187 pub fn state(&self) -> &State {
188 // TODO: StateRef<'_>
188 &self.1189 &self.1
189 }190 }
190}191}