Relative path in Rust

Rust is completely different with other languages such as Python, Java, Ruby..

Image for post
Image for post
Photo by Zbysiu Rodak on Unsplash

If you’re coming from Python, to open a file you would like to write something like below in Rust:

But this will not work because the type of the argument in open accept is Path.

If the file we’re working on is in the default directory of Rust (where Cargo.toml lies), we don’t need to define the path.

But if we’re talking about some file in different directory, we have to create path variable.

This will work.

Hope it helps.

~~ PEACE ~~

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store