// Returns a path relative to from (must be a directory) which gets to to (either directory or file)
Returns a path relative to from (must be a directory) which gets to to (either directory or file)
Returns a path relative to from ( must be a directory ) which gets to to ( either directory or file )
fn calculate_relative_path<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> PathBuf {
		let mut result = String::new();
		let mut current = from.as_ref().to_path_buf();
		loop {
			match to.as_ref().strip_prefix(&current) {
				Ok(remaining) => {
					let final_result = PathBuf::from(result).join(remaining);
					return if final_result.to_string_lossy() == "" {
						PathBuf::from("./")
					} else {
						final_result
					};
				},
				Err(_) => (),
			}
			result.push_str("../");
			current.pop();
		}
	}
fn calculate_relative_path < P : AsRef < Path > , Q : AsRef < Path > > ( from : P , to : Q ) -> PathBuf { let mut result = String :: new ( ) ; let mut current = from . as_ref ( ) . to_path_buf ( ) ; loop { match to . as_ref ( ) . strip_prefix ( & current ) { Ok ( remaining ) => { let final_result = PathBuf :: from ( result ) . join ( remaining ) ; return if final_result . to_string_lossy ( ) == " " { PathBuf :: from ( " " ) } else { final_result } ; } , Err ( _ ) => ( ) , } result . push_str ( " " ) ; current . pop ( ) ; } }
Returns a path relative to from (must be a directory) which gets to to (either directory or file)
Returns a path relative to from ( must be a directory ) which gets to to ( either directory or file )
from
P
to
Q