Rust start-user first project idea

Hi there everyone everywhere,
and many thanks for let me be part of and join the Rust revolution :slight_smile:
I am very new to the Rust programming language and my idea for a starting project is coding a "file class" resp a "file struct".

Is there already something like a "file"?
(e.g. like the class "FileInfo" in .net)

many regards
Oliver

Welcome to the Rust user forum :grinning:

You might be looking for std::fs, if not take a look at crates.io.

1 Like

It sounds like you're looking for the std::fs::File struct. The source code for rustc and the entire standard library is available on GitHub, in particular the std::fs::File type is defined here.

I've found the standard library to have really readable code, although sometimes it can get a bit complex when it needs to provide cross-platform abstractions or do low-level unsafe things.

If you're wanting to implement your own File type on Windows as a learning exercise (I assume you're on Windows because you mention .NET), you can see how the standard library did it in src/libstd/sys/windows/fs.rs. Unfortunately, because interacting with the OS can only be done with its C API, a non-trivial amount of unsafe code would probably be involved :disappointed:

That said, feel free to post to this forum if you ever get stuck and we'll try to help out. The winapi crate also provides declarations for underlying OS functions like CreateFileA().

To add to @Michael-F-Bryan's post, the documentation pages all have a [src] button beside each item, so you can quickly look at the implementation for the item you're looking at.

hi, many thanks for the answers, that helps alot, yeah there is already a file struct, so i will try it to see if it fits my needs. the [src]-button is very helpful indeed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.