diff --git a/Cargo.lock b/Cargo.lock index 5a210a4..3dd4841 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,6 +175,15 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +[[package]] +name = "kstring" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b310ccceade8121d7d77fee406160e457c2f4e7c7982d589da3499bc7ea4526" +dependencies = [ + "serde", +] + [[package]] name = "lexical-core" version = "0.4.8" @@ -409,14 +418,14 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.3.1" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d30834716e93eef7db510648299f647427858e7e2c0beeec2699ea2289c7739" +checksum = "94217a6d6a89fb646cbc9f28283cf4745f77eb0b04c4f680c4b3ae4450e3a473" dependencies = [ "combine", "indexmap", "itertools", - "vec1", + "kstring", ] [[package]] @@ -443,12 +452,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -[[package]] -name = "vec1" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bda7c41ca331fe9a1c278a9e7ee055f4be7f5eb1c2b72f079b4ff8b5fce9d5c" - [[package]] name = "vec_map" version = "0.8.1" diff --git a/Cargo.toml b/Cargo.toml index 774036b..1e36ed8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,4 @@ nom = "5" serde = "1.0" serde_json = "1.0" structopt = "0.3" -toml_edit = "0.3" +toml_edit = "0.12.6" diff --git a/src/main.rs b/src/main.rs index 1c2f318..84a0285 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ fn get(path: PathBuf, query: &str, opts: GetOpts) -> Result<(), Error> { if opts.output_toml { print_toml_fragment(&doc, &tpath); } else { - let item = walk_tpath(&doc.root, &tpath); + let item = walk_tpath(doc.as_item(), &tpath); // TODO: support shell-friendly output like `jq -r` println!("{}", serde_json::to_string(&JsonItem(item))?); } @@ -88,7 +88,7 @@ fn get(path: PathBuf, query: &str, opts: GetOpts) -> Result<(), Error> { fn print_toml_fragment(doc: &Document, tpath: &[TpathSegment]) -> () { use TpathSegment::{Name, Num}; - let mut item = &doc.root; + let mut item = doc.as_item(); let mut breadcrumbs = vec![]; for seg in tpath { breadcrumbs.push((item, seg)); @@ -125,8 +125,7 @@ fn print_toml_fragment(doc: &Document, tpath: &[TpathSegment]) -> () { _ => panic!("UNIMPLEMENTED: --output-toml inside inline data"), // TODO } } - let mut doc = Document::new(); - doc.root = item; + let doc = Document::from(item.into_table().unwrap()); print!("{}", doc.to_string()); } @@ -134,7 +133,7 @@ fn set(path: PathBuf, query: &str, value_str: &str) -> Result<(), Error> { let tpath = parse_query_cli(query)?.0; let mut doc = read_parse(path)?; - let mut item = &mut doc.root; + let mut item = doc.as_item_mut(); let mut already_inline = false; let mut tpath = &tpath[..]; use TpathSegment::{Name, Num};