Skip to content

Starting at a root node, traverse its entire dependency graph and flatten it into a top-to-bottom list.

Notifications You must be signed in to change notification settings

Spencer1O1/dep-crusher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.2"

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, an 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

About

Starting at a root node, traverse its entire dependency graph and flatten it into a top-to-bottom list.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages