Skip to main content

compute_relative_path

Function compute_relative_path 

Source
pub fn compute_relative_path(target: &Path, module_root: &Path) -> String
Expand description

Compute relative path from module root to target directory.

Returns "." if the paths are equal or if stripping fails.

ยงExamples

use std::path::Path;
use cuenv_core::cue::discovery::compute_relative_path;

let module_root = Path::new("/repo");
let target = Path::new("/repo/services/api");
assert_eq!(compute_relative_path(target, module_root), "services/api");

// Same path returns "."
assert_eq!(compute_relative_path(module_root, module_root), ".");