Skip to main content

detect_cycle

Function detect_cycle 

Source
pub fn detect_cycle(index: &Index, from_id: &str, to_id: &str) -> Result<bool>
Expand description

Detect whether adding an edge from from_id to to_id would create a cycle.

Returns true if the proposed edge would introduce a cycle. Use this before calling add_dep to pre-validate the addition.

§Errors

  • Returns an error only on unexpected graph traversal failures.

§Example

use mana_core::api::{load_index, detect_cycle};
use std::path::Path;

let mana_dir = Path::new("/project/.mana");
let index = load_index(mana_dir).unwrap();
if detect_cycle(&index, "3", "1").unwrap() {
    eprintln!("Cannot add that dependency — would create a cycle");
}