How do I write the path.join in Rust. I tried multiple examples but couldn't get it.
const exeDirectory = path.join(__dirname, '..', 'bin', 'openvpn.exe');
const processFile = path.join(__dirname, '..', '1');
I want to convert these lines of JS into Rust.
Use Path which has the .join
method
Path::new("..").join("bin").join("openvpn.exe");
Another option is collecting an iterator of string into a PathBuf
:
let path: PathBuf = ["..", "bin", "openvpn.exe"].iter().collect();
This is equivalent to creating a new PathBuf
and calling .push()
for each string in the iterator. To add multiple new components to an existing PathBuf
, you can use the extend()
method:
let mut path = PathBuf::from(dir_name);
path.extend(&["..", "bin", "openvpn.exe"]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With