dep_crusher

Crates.iodep_crusher
lib.rsdep_crusher
version0.1.2
sourcesrc
created_at2023-07-13 02:03:59.893266
updated_at2023-07-13 18:51:58.969044
descriptionStarting at a root node, traverse the dependency graph and flatten it.
homepage
repositoryhttps://github.com/Spencer1O1/dep-crusher/
max_upload_size
id914966
size6,455
Spencer Smith (Spencer1O1)

documentation

README

dep_crusher

Starting at a root node, traverse its entire dependency graph and flatten it into a top-to-bottom list. Nodes are a trait implementation, allowing dep_crusher to have generic, widespread use.

Installation

There are two easy installation options.

  1. Use Cargo from the terminal
cargo add dep_crusher
  1. Add the dependency to your Cargo.toml file
[dependencies]
dep_crusher = "0.1.0"

Usage

  1. Implement the dep_crusher::dep_node::Node trait:
struct MyStruct {
    // ...
}

impl PartialEq for MyStruct {
    fn eq(&self, other: &Self) -> bool {
        // Check equality with, for example, and ID
    }
}

impl dep_crusher::dep_node::Node for MyStruct {
    type Id = u64; // Type that implements Eq + Hash;

    fn get_id(&self) -> Self::Id {
        // Get a unique identifier of MyStruct
    }

    fn get_next(&self) -> Vec<Self> {
        // Get and return the next Vec<MyStruct>
    }
}
  1. Crush the dependencies!
let my_struct = MyStruct {
  // ...
}

let ordered_dependencies = my_struct.crush();
// OR
let ordered_dependencies = dep_crusher::crush(my_struct);

// Returns dep_crusher::result::Result<MyStruct>
// The Ok variant is Vec<MyStruct>
// The Error variant is dep_crusher::result::Error<MyStruct>

Contributing

Pull requests are very welcome. Please feel free to make this better! For major updates, please open an issue first to discuss what you want to change.

Please make sure to update tests as appropriate.

License

MIT OR Apache-2.0

Commit count: 32

cargo fmt