Skip to content

Commit

Permalink
move dep rewrite fns to bottom of lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
hdoordt committed Nov 4, 2024
1 parent 8b8293c commit 4a8f85c
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,6 @@ impl AutoInheritMetadata {
}
}

/// Rewrites a `path` dependency as being absolute, based on a given path
fn rewrite_dep_paths_as_absolute<'a, P: AsRef<std::path::Path>>(
deps: impl Iterator<Item = &'a mut Dependency>,
parent: P,
) {
deps.for_each(|dep| {
if let Dependency::Detailed(detail) = dep {
detail.path = detail.path.as_mut().map(|path| {
parent
.as_ref()
.join(path)
.canonicalize()
.expect("Error rewriting dependency path as absolute: unable to canonicalize paths.")
.to_str()
.expect("Error rewriting dependency path as absolute: absolute path is not UTF-8.")
.to_string()
})
}
});
}

/// Rewrites a `path` dependency as being relative, based on a given path
fn rewrite_dep_path_as_relative<P: AsRef<std::path::Path>>(dep: &mut Dependency, parent: P) {
if let Dependency::Detailed(detail) = dep {
detail.path = detail.path.as_mut().map(|path| {
pathdiff::diff_paths(path, parent.as_ref())
.expect(
"Error rewriting dependency path as relative: unable to determing path diff.",
)
.to_str()
.expect("Error rewriting dependency path as relative: path diff is not UTF-8.")
.to_string()
})
}
}

// Gets the first entry out of the document as a table if it exists,
// or gets the second one if it doesn't. If that doesn't exist
// either, then it returns an error.
Expand Down Expand Up @@ -668,3 +632,39 @@ fn dep2toml_item(dependency: &Dependency) -> toml_edit::Item {
}
}
}

/// Rewrites a `path` dependency as being absolute, based on a given path
fn rewrite_dep_paths_as_absolute<'a, P: AsRef<std::path::Path>>(
deps: impl Iterator<Item = &'a mut Dependency>,
parent: P,
) {
deps.for_each(|dep| {
if let Dependency::Detailed(detail) = dep {
detail.path = detail.path.as_mut().map(|path| {
parent
.as_ref()
.join(path)
.canonicalize()
.expect("Error rewriting dependency path as absolute: unable to canonicalize paths.")
.to_str()
.expect("Error rewriting dependency path as absolute: absolute path is not UTF-8.")
.to_string()
})
}
});
}

/// Rewrites a `path` dependency as being relative, based on a given path
fn rewrite_dep_path_as_relative<P: AsRef<std::path::Path>>(dep: &mut Dependency, parent: P) {
if let Dependency::Detailed(detail) = dep {
detail.path = detail.path.as_mut().map(|path| {
pathdiff::diff_paths(path, parent.as_ref())
.expect(
"Error rewriting dependency path as relative: unable to determing path diff.",
)
.to_str()
.expect("Error rewriting dependency path as relative: path diff is not UTF-8.")
.to_string()
})
}
}

0 comments on commit 4a8f85c

Please sign in to comment.