diff --git a/Cargo.toml b/Cargo.toml index b0459e2..ea768ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,6 @@ license = "MIT/Apache-2.0" description = "The missing YAML 1.2 parser for rust" repository = "https://github.com/chyh1990/yaml-rust" -[features] -preserve_order = ["linked-hash-map"] - [dependencies] clippy = { version = "^0.*", optional = true } -linked-hash-map = { version = ">=0.0.9, <0.4", optional = true } +linked-hash-map = ">=0.0.9, <0.4" diff --git a/src/emitter.rs b/src/emitter.rs index e56fc14..9571e80 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -278,7 +278,6 @@ fn need_quotes(string: &str) -> bool { #[cfg(test)] mod tests { use super::*; - use yaml::*; #[test] fn test_emit_simple() { diff --git a/src/lib.rs b/src/lib.rs index 6bdde1f..aa35e47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,6 @@ #![cfg_attr(feature="clippy", warn(cyclomatic_complexity))] #![cfg_attr(feature="clippy", allow(match_same_arms))] -#[cfg(feature = "preserve_order")] extern crate linked_hash_map; pub mod yaml; diff --git a/src/yaml.rs b/src/yaml.rs index d9f63d4..94f60bf 100644 --- a/src/yaml.rs +++ b/src/yaml.rs @@ -2,11 +2,11 @@ use std::collections::BTreeMap; use std::ops::Index; use std::string; use std::i64; -use std::str::FromStr; use std::mem; use std::vec; use parser::*; use scanner::{TScalarStyle, ScanError, TokenType, Marker}; +use linked_hash_map::LinkedHashMap; /// A YAML node is stored as this `Yaml` enumeration, which provides an easy way to /// access your YAML document. @@ -37,16 +37,9 @@ pub enum Yaml { Boolean(bool), /// YAML array, can be accessed as a `Vec`. Array(self::Array), - /// YAML hash, can be accessed as a `BTreeMap`. + /// YAML hash, can be accessed as a `LinkedHashMap`. /// - /// If the order of keys is meaningful, enable the `preserve_order` feature to - /// store hashes as a `LinkedHashMap` intead of `BTreeMap`. When using a - /// `LinkedHashMap`, the itertion order will match the order of insertion into - /// the map. - /// - /// ```toml - /// yaml-rust = { version = "*", features = ["preserve_order"] } - /// ``` + /// Itertion order will match the order of insertion into the map. Hash(self::Hash), /// Alias, not fully supported yet. Alias(usize), @@ -59,11 +52,7 @@ pub enum Yaml { } pub type Array = Vec; - -#[cfg(not(feature = "preserve_order"))] -pub type Hash = BTreeMap; -#[cfg(feature = "preserve_order")] -pub type Hash = ::linked_hash_map::LinkedHashMap; +pub type Hash = LinkedHashMap; pub struct YamlLoader { docs: Vec, @@ -587,4 +576,20 @@ a1: &DEFAULT assert_eq!(doc.next().unwrap().into_i64().unwrap(), 63); assert_eq!(doc.next().unwrap().into_i64().unwrap(), 12345); } + + #[test] + fn test_hash_order() { + let s = "--- +b: ~ +a: ~ +c: ~ +"; + let out = YamlLoader::load_from_str(&s).unwrap(); + let first = out.into_iter().next().unwrap(); + let mut iter = first.into_hash().unwrap().into_iter(); + assert_eq!(Some((Yaml::String("b".to_owned()), Yaml::Null)), iter.next()); + assert_eq!(Some((Yaml::String("a".to_owned()), Yaml::Null)), iter.next()); + assert_eq!(Some((Yaml::String("c".to_owned()), Yaml::Null)), iter.next()); + assert_eq!(None, iter.next()); + } }