playdate
playdate copied to clipboard
tests for `abs_or_rel_crate_existing`
tests for abs_or_rel_crate_existing
https://github.com/boozook/playdate/blob/28d376f18b4c23db5c9ac2083b2f69af752bd6a5/support/build/src/assets/plan.rs#L203
/ Make path relative to `crate_root` if it isn't absolute, checking existence.
/ Returns `None` if path doesn't exist.
Source of this issue
}
// TODO: tests for `abs_or_rel_crate_existing`
/// Make path relative to `crate_root` if it isn't absolute, checking existence.
/// Returns `None` if path doesn't exist.
pub fn abs_or_rel_crate_existing<'t, P1, P2>(path: P1, root: P2) -> std::io::Result<Option<Cow<'t, Path>>>
where P1: 't + AsRef<Path> + Into<Cow<'t, Path>>,
P2: AsRef<Path> {
let p = if path.as_ref().is_absolute() && path.as_ref().try_exists()? {
Some(path.into())
} else {
let abs = root.as_ref().join(path);
if abs.try_exists()? {
Some(Cow::Owned(abs))
} else {