From 2fcd829b1d9c70d0981411b4f4adca9124985b54 Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Thu, 4 Jun 2015 20:23:46 +0200 Subject: Disallow table redefinitions --- src/lib.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 0196fbc..547c407 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,8 +75,24 @@ pub enum Value { /// Type representing a TOML array, payload of the Value::Array variant pub type Array = Vec; +// The bool field flag is used during parsing and construction. +// Is true if the given table was explicitly defined, false otherwise +// e.g. in a toml document: `[a.b] foo = "bar"`, Table `a` would be false, +// where table `b` (contained inside `a`) would be true. /// Type representing a TOML table, payload of the Value::Table variant -pub type Table = BTreeMap; +#[derive(Debug, Clone)] +pub struct Table (pub BTreeMap, bool); +impl Table { + /// Creates new TOML table + pub fn new(map: BTreeMap) -> Table { + Table(map, false) + } +} +impl PartialEq for Table { + fn eq(&self, other: &Table) -> bool { + self.0.eq(&other.0) + } +} impl Value { /// Tests whether this and another value have the same type. @@ -182,7 +198,7 @@ impl Value { let mut cur_value = self; for key in path.split('.') { match cur_value { - &Value::Table(ref hm) => { + &Value::Table(Table(ref hm, _)) => { match hm.get(key) { Some(v) => cur_value = v, None => return None -- cgit v1.2.3 From 8487b63c97080296269242c31f36a557a90da0cf Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Sat, 6 Jun 2015 18:11:48 +0200 Subject: Rework fix for table redefinition to avoid breaking AST-compatiblity --- src/lib.rs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 547c407..0196fbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,24 +75,8 @@ pub enum Value { /// Type representing a TOML array, payload of the Value::Array variant pub type Array = Vec; -// The bool field flag is used during parsing and construction. -// Is true if the given table was explicitly defined, false otherwise -// e.g. in a toml document: `[a.b] foo = "bar"`, Table `a` would be false, -// where table `b` (contained inside `a`) would be true. /// Type representing a TOML table, payload of the Value::Table variant -#[derive(Debug, Clone)] -pub struct Table (pub BTreeMap, bool); -impl Table { - /// Creates new TOML table - pub fn new(map: BTreeMap) -> Table { - Table(map, false) - } -} -impl PartialEq for Table { - fn eq(&self, other: &Table) -> bool { - self.0.eq(&other.0) - } -} +pub type Table = BTreeMap; impl Value { /// Tests whether this and another value have the same type. @@ -198,7 +182,7 @@ impl Value { let mut cur_value = self; for key in path.split('.') { match cur_value { - &Value::Table(Table(ref hm, _)) => { + &Value::Table(ref hm) => { match hm.get(key) { Some(v) => cur_value = v, None => return None -- cgit v1.2.3 From b70f6e53b20c8f90f525219b1db7e99f6ef417dc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 11 Aug 2015 09:18:52 -0700 Subject: Don't need to qualify String --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 0196fbc..c974cd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,6 @@ use std::collections::BTreeMap; use std::str::FromStr; -use std::string; pub use parser::{Parser, ParserError}; @@ -76,7 +75,7 @@ pub enum Value { pub type Array = Vec; /// Type representing a TOML table, payload of the Value::Table variant -pub type Table = BTreeMap; +pub type Table = BTreeMap; impl Value { /// Tests whether this and another value have the same type. -- cgit v1.2.3