From 8cb11a85f1cd2312e0d7c169e6bf049f3435eb82 Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 5 Aug 2022 17:57:26 -0400 Subject: [PATCH 1/2] Initial version Signed-off-by: mulhern --- rust/set_lower_bounds/Cargo.lock | 128 ++++++++++++++++++++++++++++++ rust/set_lower_bounds/Cargo.toml | 7 ++ rust/set_lower_bounds/src/main.rs | 12 +++ 3 files changed, 147 insertions(+) create mode 100644 rust/set_lower_bounds/Cargo.lock create mode 100644 rust/set_lower_bounds/Cargo.toml create mode 100644 rust/set_lower_bounds/src/main.rs diff --git a/rust/set_lower_bounds/Cargo.lock b/rust/set_lower_bounds/Cargo.lock new file mode 100644 index 0000000..594a0f8 --- /dev/null +++ b/rust/set_lower_bounds/Cargo.lock @@ -0,0 +1,128 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "camino" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "869119e97797867fd90f5e22af7d0bd274bd4635ebb9eb68c04f3f513ae6c412" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3abb7553d5b9b8421c6de7cb02606ff15e0c6eea7d8eadd75ef013fd636bec36" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", +] + +[[package]] +name = "itoa" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" + +[[package]] +name = "proc-macro2" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "semver" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711" +dependencies = [ + "serde", +] + +[[package]] +name = "serde" +version = "1.0.142" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.142" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34b5b8d809babe02f538c2cfec6f2c1ed10804c0e5a6a041a049a4f5588ccc2e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "set_lower_bounds" +version = "0.1.0" +dependencies = [ + "cargo_metadata", +] + +[[package]] +name = "syn" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" diff --git a/rust/set_lower_bounds/Cargo.toml b/rust/set_lower_bounds/Cargo.toml new file mode 100644 index 0000000..9a80d2d --- /dev/null +++ b/rust/set_lower_bounds/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "set_lower_bounds" +version = "0.1.0" +edition = "2021" + +[dependencies] +cargo_metadata = "*" diff --git a/rust/set_lower_bounds/src/main.rs b/rust/set_lower_bounds/src/main.rs new file mode 100644 index 0000000..39ceb46 --- /dev/null +++ b/rust/set_lower_bounds/src/main.rs @@ -0,0 +1,12 @@ +use cargo_metadata::{CargoOpt, MetadataCommand}; + +fn main() { + let metadata = MetadataCommand::new() + .features(CargoOpt::AllFeatures) + .exec() + .unwrap(); + print!("Root package: {}\n", metadata.root_package().unwrap().name); + for package in metadata.packages { + print!("{}\n", package.name); + } +} From fea43f2d91ccf7bf4df64cb284820aa5503b0c4c Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 5 Aug 2022 21:03:14 -0400 Subject: [PATCH 2/2] Minor updates Signed-off-by: mulhern --- rust/set_lower_bounds/src/main.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/rust/set_lower_bounds/src/main.rs b/rust/set_lower_bounds/src/main.rs index 39ceb46..40b5207 100644 --- a/rust/set_lower_bounds/src/main.rs +++ b/rust/set_lower_bounds/src/main.rs @@ -5,8 +5,22 @@ fn main() { .features(CargoOpt::AllFeatures) .exec() .unwrap(); - print!("Root package: {}\n", metadata.root_package().unwrap().name); - for package in metadata.packages { - print!("{}\n", package.name); - } + + let resolve = metadata.resolve.as_ref().unwrap(); + + let root_package = metadata.root_package().unwrap(); + let dependency_specs = &root_package.dependencies; + + let tree_root_id = resolve.root.as_ref().unwrap(); + + assert!(&root_package.id == tree_root_id); + + let root_node = resolve + .nodes + .iter() + .find(|n| &n.id == tree_root_id) + .unwrap(); + let concrete_deps = &root_node.deps; + + assert!(concrete_deps.len() == dependency_specs.len()); }