diff options
author | Lzu Tao <taolzu@gmail.com> | 2019-08-21 16:30:19 +0700 |
---|---|---|
committer | Lzu Tao <taolzu@gmail.com> | 2019-08-21 17:54:56 +0700 |
commit | afced65eb5e08e6bf593ee98bfafd82f0e039ab3 (patch) | |
tree | b5cdb1483fa4307f9f5f90c710e2b7430cb62d33 | |
parent | 32410696228e88092ce75471238f818926f308d0 (diff) |
Remove unneeded `&` to on pattern matchings
-rw-r--r-- | src/delete.rs | 12 | ||||
-rw-r--r-- | src/insert.rs | 54 | ||||
-rw-r--r-- | src/read.rs | 4 | ||||
-rw-r--r-- | src/resolver/mut_creating_resolver.rs | 82 | ||||
-rw-r--r-- | src/resolver/mut_resolver.rs | 80 | ||||
-rw-r--r-- | src/resolver/non_mut_resolver.rs | 80 | ||||
-rw-r--r-- | src/set.rs | 54 | ||||
-rw-r--r-- | src/tokenizer.rs | 20 |
8 files changed, 193 insertions, 193 deletions
diff --git a/src/delete.rs b/src/delete.rs index 6dcc8b0..2be3e78 100644 --- a/src/delete.rs +++ b/src/delete.rs @@ -55,8 +55,8 @@ impl TomlValueDeleteExt for Value { #[inline] fn is_empty(val: Option<&Value>, default: bool) -> bool { val.map(|v| match v { - &Value::Table(ref tab) => tab.is_empty(), - &Value::Array(ref arr) => arr.is_empty(), + Value::Table(ref tab) => tab.is_empty(), + Value::Array(ref arr) => arr.is_empty(), _ => default, }) .unwrap_or(default) @@ -79,7 +79,7 @@ impl TomlValueDeleteExt for Value { if last_token.is_none() { match self { - &mut Value::Table(ref mut tab) => match tokens { + Value::Table(ref mut tab) => match tokens { Token::Identifier { ident, .. } => { if is_empty(tab.get(&ident), true) { Ok(tab.remove(&ident)) @@ -95,7 +95,7 @@ impl TomlValueDeleteExt for Value { } _ => Ok(None), }, - &mut Value::Array(ref mut arr) => match tokens { + Value::Array(ref mut arr) => match tokens { Token::Identifier { ident, .. } => Err(Error::NoIdentifierInArray(ident)), Token::Index { idx, .. } => { if is_empty(Some(arr.index(idx)), true) { @@ -123,7 +123,7 @@ impl TomlValueDeleteExt for Value { let val = resolve(self, &tokens, true)?.unwrap(); // safe because of resolve() guarantees let last_token = last_token.unwrap(); match val { - &mut Value::Table(ref mut tab) => match *last_token { + Value::Table(ref mut tab) => match *last_token { Token::Identifier { ref ident, .. } => { if is_empty(tab.get(ident), true) { Ok(tab.remove(ident)) @@ -139,7 +139,7 @@ impl TomlValueDeleteExt for Value { } Token::Index { idx, .. } => Err(Error::NoIndexInTable(idx)), }, - &mut Value::Array(ref mut arr) => match *last_token { + Value::Array(ref mut arr) => match *last_token { Token::Identifier { ident, .. } => Err(Error::NoIdentifierInArray(ident)), Token::Index { idx, .. } => { if idx > arr.len() { diff --git a/src/insert.rs b/src/insert.rs index 48ba9b3..d6815fa 100644 --- a/src/insert.rs +++ b/src/insert.rs @@ -116,12 +116,12 @@ impl TomlValueInsertExt for Value { match *last { Token::Identifier { ident, .. } => match val { - &mut Value::Table(ref mut t) => Ok(t.insert(ident, value)), + Value::Table(ref mut t) => Ok(t.insert(ident, value)), _ => Err(Error::NoIdentifierInArray(ident.clone())), }, Token::Index { idx, .. } => match val { - &mut Value::Array(ref mut a) => { + Value::Array(ref mut a) => { if a.len() > idx { a.insert(idx, value); Ok(None) @@ -167,7 +167,7 @@ mod test { ); let val = val.unwrap(); - assert!(is_match!(val, &Value::Integer(1)), "Is not one: {:?}", val); + assert!(is_match!(val, Value::Integer(1)), "Is not one: {:?}", val); } _ => panic!("What just happenend?"), } @@ -198,16 +198,16 @@ mod test { assert!(table.is_some()); let table = table.unwrap(); - assert!(is_match!(table, &Value::Table(_))); + assert!(is_match!(table, Value::Table(_))); match table { - &Value::Table(ref t) => { + Value::Table(ref t) => { assert!(!t.is_empty()); let a = t.get("a"); assert!(a.is_some()); let a = a.unwrap(); - assert!(is_match!(a, &Value::Integer(1))); + assert!(is_match!(a, Value::Integer(1))); } _ => panic!("What just happenend?"), } @@ -243,11 +243,11 @@ mod test { assert!(array.is_some()); let array = array.unwrap(); - assert!(is_match!(array, &Value::Array(_))); + assert!(is_match!(array, Value::Array(_))); match array { - &Value::Array(ref a) => { + Value::Array(ref a) => { assert!(!a.is_empty()); - assert!(is_match!(a.index(0), &Value::Integer(1))); + assert!(is_match!(a.index(0), Value::Integer(1))); } _ => panic!("What just happenend?"), } @@ -280,34 +280,34 @@ mod test { assert!(a_tab.is_some()); let a_tab = a_tab.unwrap(); - assert!(is_match!(a_tab, &Value::Table(_))); + assert!(is_match!(a_tab, Value::Table(_))); match a_tab { - &Value::Table(ref a) => { + Value::Table(ref a) => { assert!(!a.is_empty()); let b_tab = a.get("b"); assert!(b_tab.is_some()); let b_tab = b_tab.unwrap(); - assert!(is_match!(b_tab, &Value::Table(_))); + assert!(is_match!(b_tab, Value::Table(_))); match b_tab { - &Value::Table(ref b) => { + Value::Table(ref b) => { assert!(!b.is_empty()); let c_tab = b.get("c"); assert!(c_tab.is_some()); let c_tab = c_tab.unwrap(); - assert!(is_match!(c_tab, &Value::Table(_))); + assert!(is_match!(c_tab, Value::Table(_))); match c_tab { - &Value::Table(ref c) => { + Value::Table(ref c) => { assert!(!c.is_empty()); let d = c.get("d"); assert!(d.is_some()); let d = d.unwrap(); - assert!(is_match!(d, &Value::Integer(1))); + assert!(is_match!(d, Value::Integer(1))); } _ => panic!("What just happenend?"), } @@ -383,16 +383,16 @@ mod test { assert!(array.is_some()); let array = array.unwrap(); - assert!(is_match!(array, &Value::Array(_))); + assert!(is_match!(array, Value::Array(_))); match array { - &Value::Array(ref a) => { + Value::Array(ref a) => { assert!(!a.is_empty()); - assert!(is_match!(a.index(0), &Value::Integer(1))); - assert!(is_match!(a.index(1), &Value::Integer(2))); - assert!(is_match!(a.index(2), &Value::Integer(6))); - assert!(is_match!(a.index(3), &Value::Integer(3))); - assert!(is_match!(a.index(4), &Value::Integer(4))); - assert!(is_match!(a.index(5), &Value::Integer(5))); + assert!(is_match!(a.index(0), Value::Integer(1))); + assert!(is_match!(a.index(1), Value::Integer(2))); + assert!(is_match!(a.index(2), Value::Integer(6))); + assert!(is_match!(a.index(3), Value::Integer(3))); + assert!(is_match!(a.index(4), Value::Integer(4))); + assert!(is_match!(a.index(5), Value::Integer(5))); } _ => panic!("What just happenend?"), } @@ -425,16 +425,16 @@ mod test { assert!(table.is_some()); let table = table.unwrap(); - assert!(is_match!(table, &Value::Table(_))); + assert!(is_match!(table, Value::Table(_))); match table { - &Value::Table(ref t) => { + Value::Table(ref t) => { assert!(!t.is_empty()); let a = t.get("a"); assert!(a.is_some()); let a = a.unwrap(); - assert!(is_match!(a, &Value::Integer(1))); + assert!(is_match!(a, Value::Integer(1))); } _ => panic!("What just happenend?"), } diff --git a/src/read.rs b/src/read.rs index 85b51ae..24ff1e4 100644 --- a/src/read.rs +++ b/src/read.rs @@ -145,7 +145,7 @@ mod test { assert!(is_match!(val, &Value::Table(_))); match val { - &Value::Table(ref t) => assert!(t.is_empty()), + Value::Table(ref t) => assert!(t.is_empty()), _ => panic!("What just happened?"), } } @@ -239,7 +239,7 @@ mod test { assert!(is_match!(val, &Value::Table(_))); match val { - &Value::Table(ref t) => assert!(t.is_empty()), + Value::Table(ref t) => assert!(t.is_empty()), _ => panic!("What just happened?"), } } diff --git a/src/resolver/mut_creating_resolver.rs b/src/resolver/mut_creating_resolver.rs index 99ade56..ee1c753 100644 --- a/src/resolver/mut_creating_resolver.rs +++ b/src/resolver/mut_creating_resolver.rs @@ -20,7 +20,7 @@ pub fn resolve<'doc>(toml: &'doc mut Value, tokens: &Token) -> Result<&'doc mut match *tokens { Token::Identifier { ref ident, .. } => match toml { - &mut Value::Table(ref mut t) => { + Value::Table(ref mut t) => { if t.contains_key(ident) { match tokens.next() { Some(next) => resolve(t.get_mut(ident).unwrap(), next), @@ -36,13 +36,13 @@ pub fn resolve<'doc>(toml: &'doc mut Value, tokens: &Token) -> Result<&'doc mut } } } - &mut Value::Array(_) => Err(Error::NoIdentifierInArray(ident.clone())), + Value::Array(_) => Err(Error::NoIdentifierInArray(ident.clone())), _ => unimplemented!(), }, Token::Index { idx, .. } => { match toml { - &mut Value::Table(_) => Err(Error::NoIndexInTable(idx)), - &mut Value::Array(ref mut ary) => { + Value::Table(_) => Err(Error::NoIndexInTable(idx)), + Value::Array(ref mut ary) => { if ary.len() > idx { match tokens.next() { Some(next) => resolve(ary.get_mut(idx).unwrap(), next), @@ -92,9 +92,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Table(_))); + assert!(is_match!(result, Value::Table(_))); match result { - &mut Value::Table(ref tab) => assert!(tab.is_empty()), + Value::Table(ref tab) => assert!(tab.is_empty()), _ => assert!(false, "Expected Table, got something else"), } } @@ -107,7 +107,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Boolean(true))); + assert!(is_match!(result, Value::Boolean(true))); } #[test] @@ -118,7 +118,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(1))); + assert!(is_match!(result, Value::Integer(1))); } #[test] @@ -129,7 +129,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Float(_))); + assert!(is_match!(result, Value::Float(_))); assert_eq!(result.as_float(), Some(1.0)); } @@ -141,9 +141,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("string", s), + Value::String(ref s) => assert_eq!("string", s), _ => panic!("What just happened?"), } } @@ -156,9 +156,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert_eq!(ary[0], Value::Boolean(true)); assert_eq!(ary[1], Value::Boolean(false)); } @@ -174,9 +174,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert_eq!(ary[0], Value::Integer(1)); assert_eq!(ary[1], Value::Integer(1337)); } @@ -192,9 +192,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert!(is_match!(ary[0], Value::Float(_))); assert_eq!(ary[0].as_float(), Some(1.0)); assert!(is_match!(ary[1], Value::Float(_))); @@ -212,7 +212,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(1))); + assert!(is_match!(result, Value::Integer(1))); } #[test] @@ -223,7 +223,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(5))); + assert!(is_match!(result, Value::Integer(5))); } #[test] @@ -240,7 +240,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(42))); + assert!(is_match!(result, Value::Integer(42))); } #[test] @@ -261,7 +261,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(42))); + assert!(is_match!(result, Value::Integer(42))); } #[test] @@ -278,9 +278,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert!(is_match!(ary[0], Value::Float(_))); assert_eq!(ary[0].as_float(), Some(42.0)); assert!(is_match!(ary[1], Value::Float(_))); @@ -304,7 +304,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(42))); + assert!(is_match!(result, Value::Integer(42))); } #[test] @@ -327,9 +327,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("Foo", s), + Value::String(ref s) => assert_eq!("Foo", s), _ => panic!("What just happened?"), } } @@ -358,9 +358,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("apple", s), + Value::String(ref s) => assert_eq!("apple", s), _ => panic!("What just happened?"), } } @@ -373,9 +373,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Table(_))); + assert!(is_match!(result, Value::Table(_))); match result { - &mut Value::Table(ref tab) => { + Value::Table(ref tab) => { match tab.get("color") { Some(&Value::String(ref s)) => assert_eq!("red", s), _ => assert!(false), @@ -403,9 +403,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("yellow", s), + Value::String(ref s) => assert_eq!("yellow", s), _ => panic!("What just happened?"), } } @@ -423,9 +423,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Table(_))); + assert!(is_match!(result, Value::Table(_))); match result { - &mut Value::Table(ref t) => assert!(t.is_empty()), + Value::Table(ref t) => assert!(t.is_empty()), _ => panic!("What just happened?"), } } @@ -437,9 +437,9 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Table(_))); + assert!(is_match!(result, Value::Table(_))); match result { - &mut Value::Table(ref t) => assert!(t.is_empty()), + Value::Table(ref t) => assert!(t.is_empty()), _ => panic!("What just happened?"), } } @@ -455,9 +455,9 @@ mod test { //assert!(result.is_ok()); //let result = result.unwrap(); - //assert!(is_match!(result, &mut Value::Array(_))); + //assert!(is_match!(result, Value::Array(_))); //match result { - // &mut Value::Array(ref a) => assert!(a.is_empty()), + // Value::Array(ref a) => assert!(a.is_empty()), // _ => panic!("What just happened?"), //} } @@ -471,7 +471,7 @@ mod test { let result = result.unwrap(); match result { - &mut Value::Table(ref t) => assert!(t.is_empty()), + Value::Table(ref t) => assert!(t.is_empty()), _ => panic!("What just happened?"), } } @@ -485,7 +485,7 @@ mod test { let result = result.unwrap(); match result { - &mut Value::Table(ref t) => assert!(t.is_empty()), + Value::Table(ref t) => assert!(t.is_empty()), _ => panic!("What just happened?"), } } @@ -502,7 +502,7 @@ mod test { //let result = result.unwrap(); //match result { - // &mut Value::Array(ref a) => assert!(a.is_empty()), + // Value::Array(ref a) => assert!(a.is_empty()), // _ => panic!("What just happened?"), //} } diff --git a/src/resolver/mut_resolver.rs b/src/resolver/mut_resolver.rs index 0462c6e..c0097de 100644 --- a/src/resolver/mut_resolver.rs +++ b/src/resolver/mut_resolver.rs @@ -17,8 +17,8 @@ pub fn resolve<'doc>( error_if_not_found: bool, ) -> Result<Option<&'doc mut Value>> { match toml { - &mut Value::Table(ref mut t) => match tokens { - &Token::Identifier { ref ident, .. } => match t.get_mut(ident) { + Value::Table(ref mut t) => match tokens { + Token::Identifier { ref ident, .. } => match t.get_mut(ident) { None => { if error_if_not_found { Err(Error::IdentifierNotFoundInDocument(ident.to_owned())) @@ -32,26 +32,26 @@ pub fn resolve<'doc>( }, }, - &Token::Index { idx, .. } => Err(Error::NoIndexInTable(idx)), + Token::Index { idx, .. } => Err(Error::NoIndexInTable(*idx)), }, - &mut Value::Array(ref mut ary) => match tokens { - &Token::Index { idx, .. } => match tokens.next() { - Some(next) => resolve(ary.get_mut(idx).unwrap(), next, error_if_not_found), + Value::Array(ref mut ary) => match tokens { + Token::Index { idx, .. } => match tokens.next() { + Some(next) => resolve(ary.get_mut(*idx).unwrap(), next, error_if_not_found), None => { - if ary.get(idx).is_none() { - Err(Error::IndexOutOfBounds(idx, ary.len())) + if ary.get(*idx).is_none() { + Err(Error::IndexOutOfBounds(*idx, ary.len())) } else { - Ok(Some(ary.index_mut(idx))) + Ok(Some(ary.index_mut(*idx))) } } }, - &Token::Identifier { ref ident, .. } => Err(Error::NoIdentifierInArray(ident.clone())), + Token::Identifier { ref ident, .. } => Err(Error::NoIdentifierInArray(ident.clone())), }, _ => match tokens { - &Token::Identifier { ref ident, .. } => Err(Error::QueryingValueAsTable(ident.clone())), - &Token::Index { idx, .. } => Err(Error::QueryingValueAsArray(idx)), + Token::Identifier { ref ident, .. } => Err(Error::QueryingValueAsTable(ident.clone())), + Token::Index { idx, .. } => Err(Error::QueryingValueAsArray(*idx)), }, } } @@ -93,7 +93,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, Some(&mut Value::Boolean(true)))); + assert!(is_match!(result, Some(Value::Boolean(true)))); } #[test] @@ -104,7 +104,7 @@ mod test { assert!(result.is_ok()); let result = result.unwrap(); - assert!(is_match!(result, Some(&mut Value::Integer(1)))); + assert!(is_match!(result, Some(Value::Integer(1)))); } #[test] @@ -118,7 +118,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Float(_))); + assert!(is_match!(result, Value::Float(_))); assert_eq!(result.as_float(), Some(1.0)) } @@ -133,9 +133,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("string", s), + Value::String(ref s) => assert_eq!("string", s), _ => panic!("What just happened?"), } } @@ -151,9 +151,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert_eq!(ary[0], Value::Boolean(true)); assert_eq!(ary[1], Value::Boolean(false)); } @@ -172,9 +172,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert_eq!(ary[0], Value::Integer(1)); assert_eq!(ary[1], Value::Integer(1337)); } @@ -193,9 +193,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert!(is_match!(ary[0], Value::Float(_))); assert_eq!(ary[0].as_float(), Some(1.0)); assert!(is_match!(ary[1], Value::Float(_))); @@ -216,7 +216,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(1))); + assert!(is_match!(result, Value::Integer(1))); } #[test] @@ -230,7 +230,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(5))); + assert!(is_match!(result, Value::Integer(5))); } #[test] @@ -250,7 +250,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(42))); + assert!(is_match!(result, Value::Integer(42))); } #[test] @@ -274,7 +274,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(42))); + assert!(is_match!(result, Value::Integer(42))); } #[test] @@ -294,9 +294,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &mut Value::Array(ref ary) => { + Value::Array(ref ary) => { assert!(is_match!(ary[0], Value::Float(_))); assert_eq!(ary[0].as_float(), Some(42.0)); assert!(is_match!(ary[1], Value::Float(_))); @@ -323,7 +323,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Integer(42))); + assert!(is_match!(result, Value::Integer(42))); } #[test] @@ -349,9 +349,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("Foo", s), + Value::String(ref s) => assert_eq!("Foo", s), _ => panic!("What just happened?"), } } @@ -383,9 +383,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("apple", s), + Value::String(ref s) => assert_eq!("apple", s), _ => panic!("What just happened?"), } } @@ -401,9 +401,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Table(_))); + assert!(is_match!(result, Value::Table(_))); match result { - &mut Value::Table(ref tab) => { + Value::Table(ref tab) => { match tab.get("color") { Some(&Value::String(ref s)) => assert_eq!("red", s), _ => assert!(false), @@ -437,9 +437,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &mut Value::String(ref s) => assert_eq!("yellow", s), + Value::String(ref s) => assert_eq!("yellow", s), _ => panic!("What just happened?"), } } @@ -460,9 +460,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &mut Value::Table(_))); + assert!(is_match!(result, Value::Table(_))); match result { - &mut Value::Table(ref t) => assert!(t.is_empty()), + Value::Table(ref t) => assert!(t.is_empty()), _ => panic!("What just happened?"), } } diff --git a/src/resolver/non_mut_resolver.rs b/src/resolver/non_mut_resolver.rs index e86dc94..2d44548 100644 --- a/src/resolver/non_mut_resolver.rs +++ b/src/resolver/non_mut_resolver.rs @@ -17,8 +17,8 @@ pub fn resolve<'doc>( error_if_not_found: bool, ) -> Result<Option<&'doc Value>> { match toml { - &Value::Table(ref t) => match tokens { - &Token::Identifier { ref ident, .. } => match t.get(ident) { + Value::Table(ref t) => match tokens { + Token::Identifier { ref ident, .. } => match t.get(ident) { None => { if error_if_not_found { Err(Error::IdentifierNotFoundInDocument(ident.to_owned())) @@ -32,27 +32,27 @@ pub fn resolve<'doc>( }, }, - &Token::Index { idx, .. } => Err(Error::NoIndexInTable(idx)), + Token::Index { idx, .. } => Err(Error::NoIndexInTable(*idx)), }, - &Value::Array(ref ary) => match tokens { - &Token::Index { idx, .. } => match tokens.next() { - Some(next) => resolve(ary.get(idx).unwrap(), next, error_if_not_found), + Value::Array(ref ary) => match tokens { + Token::Index { idx, .. } => match tokens.next() { + Some(next) => resolve(ary.get(*idx).unwrap(), next, error_if_not_found), None => { - if ary.get(idx).is_none() { - Err(Error::IndexOutOfBounds(idx, ary.len())) + if ary.get(*idx).is_none() { + Err(Error::IndexOutOfBounds(*idx, ary.len())) } else { - Ok(Some(ary.index(idx))) + Ok(Some(ary.index(*idx))) } } }, - &Token::Identifier { ref ident, .. } => Err(Error::NoIdentifierInArray(ident.clone())), + Token::Identifier { ref ident, .. } => Err(Error::NoIdentifierInArray(ident.clone())), }, _ => match tokens { - &Token::Identifier { ref ident, .. } => Err(Error::QueryingValueAsTable(ident.clone())), + Token::Identifier { ref ident, .. } => Err(Error::QueryingValueAsTable(ident.clone())), - &Token::Index { idx, .. } => Err(Error::QueryingValueAsArray(idx)), + Token::Index { idx, .. } => Err(Error::QueryingValueAsArray(*idx)), }, } } @@ -97,7 +97,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &Value::Boolean(true))); + assert!(is_match!(result, Value::Boolean(true))); } #[test] @@ -111,7 +111,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &Value::Integer(1))); + assert!(is_match!(result, Value::Integer(1))); } #[test] @@ -125,7 +125,7 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &Value::Float(_))); + assert!(is_match!(result, Value::Float(_))); assert_eq!(result.as_float(), Some(1.0)) } @@ -140,9 +140,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &Value::String(_))); + assert!(is_match!(result, Value::String(_))); match result { - &Value::String(ref s) => assert_eq!("string", s), + Value::String(ref s) => assert_eq!("string", s), _ => panic!("What just happened?"), } } @@ -158,9 +158,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &Value::Array(ref ary) => { + Value::Array(ref ary) => { assert_eq!(ary[0], Value::Boolean(true)); assert_eq!(ary[1], Value::Boolean(false)); } @@ -179,9 +179,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &Value::Array(ref ary) => { + Value::Array(ref ary) => { assert_eq!(ary[0], Value::Integer(1)); assert_eq!(ary[1], Value::Integer(1337)); } @@ -200,9 +200,9 @@ mod test { assert!(result.is_some()); let result = result.unwrap(); - assert!(is_match!(result, &Value::Array(_))); + assert!(is_match!(result, Value::Array(_))); match result { - &Value::Array(ref ary) => { + Value::Array(ref ary) => { assert!(is_match!(ary[0], Value::Float(_))); assert_eq!(ary[0].as_float(), Some(1.0)); assert!(is_match!(ary[1], Value::Float(_))); @@ -223,7 +223,7 @@ mod test { assert!(result.is_some()); |