Repository: toml-rs/toml (language: rust)

Issue:
Inconsistent .len() on Array and ArrayOfTables
Should we return values.len() or values.filter(!is_none).len()?


Discussion / hints:

Fix patch:
diff --git a/src/array_of_tables.rs b/src/array_of_tables.rs
index c7315853..298c99f0 100644
--- a/src/array_of_tables.rs
+++ b/src/array_of_tables.rs
@@ -43,10 +43,13 @@ impl ArrayOfTables {
         self.values.clear()
     }
 
+    /// Returns the length of the underlying Vec.
+    /// To get the actual number of items use `a.iter().count()`.
     pub fn len(&self) -> usize {
-        self.values.iter().filter(|i| i.is_table()).count()
+        self.values.len()
     }
 
+    /// Return true iff `self.len() == 0`
     pub fn is_empty(&self) -> bool {
         self.len() == 0
     }
diff --git a/src/value.rs b/src/value.rs
index 24768bb3..343ad0b1 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -73,10 +73,13 @@ pub(crate) enum ValueType {
 pub type ArrayIter<'a> = Box<Iterator<Item = &'a Value> + 'a>;
 
 impl Array {
+    /// Returns the length of the underlying Vec.
+    /// To get the actual number of items use `a.iter().count()`.
     pub fn len(&self) -> usize {
         self.values.len()
     }
 
+    /// Return true iff `self.len() == 0`
     pub fn is_empty(&self) -> bool {
         self.len() == 0
     }
@@ -137,7 +140,7 @@ pub type InlineTableIter<'a> = Box<Iterator<Item = (&'a str, &'a Value)> + 'a>;
 
 impl InlineTable {
     pub fn len(&self) -> usize {
-        self.items.len()
+        self.iter().count()
     }
 
     pub fn is_empty(&self) -> bool {


Test patch: