#std::fs::File issues

25 messages · Page 1 of 1 (latest)

dim marsh
#

Hello, so im currently learning rust and i decided to go for simple 2d game engine. The issue im facing is due to how rust std::fs::File works. So my 'engine' is a library that i include in my sandbox app by doing engine = {path = "../engine"}. So on the screenshot below you can see my file structure. I have a function that compiles and returns me a shader program. It takes two arguments as a path to the file (vertex_path: &str, fragment_path: &str). Now in my renderer.rs I want to get that shader so i call this by doing
let shader_program = Shader::new("./src/rendering/shaders/test_vertex.glsl", "./src/rendering/shaders/test_fragment.glsl")?; although i cant get the file path to be correct, so i decided to debug it. It ended up that the path is actually in the app folder for some reason even though i call it in renderer.rs that is in engine folder. Any ideas what should i do in this case?

#

Also to check where the std::fs::File path is currently i decided to call std::fs::File::create() and it created the foo.txt that you can see on the screenshot above

cold gorge
#

When you open a file, it's relative to the "cwd" (current working directory) that you're running the app from.

On Linux, this is the directory you're in when you execute "cargo run".

dim marsh
#

oh, ok.

#

So what should i do then

#

is there any way to make the path start from the file directory

#

where it is called?

cold gorge
#

it's kinda tough because the knowledge of where your source files are, is mostly erased when you compile the final program

#

you can read files at compile time, relative to the source files, if you use include_str! but that's an entirely different API

dim marsh
#

I take a look at it

#

for now i think ill just put the shaders folder into app dir

#

and then worry about that stuff

#

thanks for help mate

#

👍🏿

cold gorge
#

yw!

wide marten
dim marsh
#

works now

#

thanks man

#

u really helped me out

#

i was stuck on this

wide marten