Skip to content

Commit

Permalink
refactor(value): Improve API stability
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 19, 2018
1 parent d6e1aea commit 9c04abc
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions liquid-value/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ impl Value {
}
}

/// All keys
pub fn keys(&self) -> Vec<Scalar> {
match *self {
/// Keys available for lookup.
pub fn keys(&self) -> Keys {
let v = match *self {
Value::Array(ref x) => {
let start: i32 = 0;
let end = x.len() as i32;
Expand All @@ -231,7 +231,8 @@ impl Value {
}
}).collect(),
_ => vec![],
}
};
Keys(v.into_iter())
}

/// Access a contained `Value`.
Expand All @@ -255,6 +256,36 @@ impl Value {
}
}

/// Iterator over a `Value`s keys.
#[derive(Debug)]
pub struct Keys(::std::vec::IntoIter<Scalar>);

impl Iterator for Keys {
type Item = Scalar;

#[inline]
fn next(&mut self) -> Option<Scalar> {
self.0.next()
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}

#[inline]
fn count(self) -> usize {
self.0.count()
}
}

impl ExactSizeIterator for Keys {
#[inline]
fn len(&self) -> usize {
self.0.len()
}
}

fn convert_index(index: i32, max_size: usize) -> usize {
let index = index as isize;
let max_size = max_size as isize;
Expand Down

0 comments on commit 9c04abc

Please sign in to comment.