I tried using this abomination:
let current_dir = env::current_dir().unwrap();
let dir_components = current_dir.components();
let dir_components_vec = dir_components.collect::<Vec<_>>();
let last_components =
dir_components_vec.iter()
.rev()
.take(n)
.collect::<Vec<_>>()
.into_iter()
.map(|&dir| dir.as_os_str().to_str())
.collect::<Vec<_>>()
.join('/'));
but it returns this error:
join method cannot be called on `Vec<Option<&str>>` due to unsatisfied trait bounds
note: the following trait bounds were not satisfied:
[Option<&str>]: Join<_>
I tried using .try_into but the compiler told me to specify a type and I had know idea what type I need to convert the value into