[SOLVED] Learning Rust safely

About programming and getting involved with Linux Mint development
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Post Reply
Navigator
Level 1
Level 1
Posts: 10
Joined: Thu Dec 28, 2023 12:51 pm

[SOLVED] Learning Rust safely

Post by Navigator »

I have been using Linux Mint for about a year, previously using Windows 7. Thanks to the easy GUI it's been a smooth transition but I still don't know my way around the deeper system components and configurations.

I would now like to learn Rust, and I want to do it in some kind of sandbox or controlled space since all my stuff is on this machine.

As a beginner how should I install Rust? Should I use rustup.rs, the IRust Flatpak in the Software Manager, or do I need to first create a virtual machine?

What is the easiest way to create a sandbox for running Rust programs? Can I allow the programs to access specific drives or folders only, without having to copy these resources into a separate sandbox tree?

What else should I know that I don't know to ask before starting on this journey?
Last edited by Navigator on Sat Dec 30, 2023 2:05 pm, edited 1 time in total.
User avatar
JoeFootball
Level 13
Level 13
Posts: 4673
Joined: Tue Nov 24, 2009 1:52 pm
Location: /home/usa/mn/minneapolis/joe

Re: Learning Rust safely

Post by JoeFootball »

Navigator wrote: What is the easiest way to create a sandbox for running Rust programs?
I'd say the easiest is the Rust Playground, as it's online ready-to-go.

And here's some learning resources for your consideration.
Navigator
Level 1
Level 1
Posts: 10
Joined: Thu Dec 28, 2023 12:51 pm

Re: Learning Rust safely

Post by Navigator »

Thanks, that's surely a good place to start, but when I want to go a bit deeper my original questions remain.
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Learning Rust safely

Post by xenopeek »

Why do you want to run your rust programs in a sandbox?
Image
Navigator
Level 1
Level 1
Posts: 10
Joined: Thu Dec 28, 2023 12:51 pm

Re: Learning Rust safely

Post by Navigator »

xenopeek wrote: Thu Dec 28, 2023 5:23 pm Why do you want to run your rust programs in a sandbox?
I am afraid I'll do something stupid and delete or corrupt files. I would also like to be able to run and modify program examples without worry that they could be malicious or just poorly conceived. I don't want to rename all files in /home to foo.bar or something.

Is this a foolish or difficult request? It's pretty trivial under Windows with Sandboxie to keep a program's disk writes contained.
RIH
Level 9
Level 9
Posts: 2910
Joined: Sat Aug 22, 2015 3:47 am

Re: Learning Rust safely

Post by RIH »

I think if you want to be absolutely sure, & have an easy life in the future, then a virtual machine is the way to go.
I use VirtualBox downloaded directly from Oracle
https://www.virtualbox.org/wiki/Downloads
plus the Oracle VM VirtualBox Extension Pack, rather than using the instance from the Repositories.

If you create chaos with your Rust programmes then just revert back to the prior Snapshot, or delete completely and start again!!
Image
User avatar
spamegg
Level 14
Level 14
Posts: 5117
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Learning Rust safely

Post by spamegg »

You need to use Rustup from their website, don't use repository or Flatpak versions. Rustup gets updates constantly. Best learning resource is Rust Foundation's own book. https://github.com/rust-lang/book

I think your fears are unfounded; you can just use VS Code and the Rust extension, then create a project with cargo and you're not going to corrupt anything, you will be exclusively working with files inside the project directory. Please stop worrying!
Screenshot from 2023-12-29 19-03-53.jpg
Navigator
Level 1
Level 1
Posts: 10
Joined: Thu Dec 28, 2023 12:51 pm

Re: Learning Rust safely

Post by Navigator »

spamegg wrote: Fri Dec 29, 2023 12:05 pm You need to use Rustup from their website, don't use repository or Flatpak versions. Rustup gets updates constantly. Best learning resource is Rust Foundation's own book. https://github.com/rust-lang/book

I think your fears are unfounded; you can just use VS Code and the Rust extension, then create a project with cargo and you're not going to corrupt anything, you will be exclusively working with files inside the project directory. Please stop worrying!
Screenshot from 2023-12-29 19-03-53.jpg
Okay, Rustup it is. Would you please explain "you will be exclusively working with files inside the project directory." Does Cargo automatically limit scope somehow? How then do I write programs that CAN access/alter files outside of the project directory?
User avatar
Coggy
Level 5
Level 5
Posts: 642
Joined: Thu Mar 31, 2022 10:34 am

Re: Learning Rust safely

Post by Coggy »

I know nothing about rust, but I know vscode focuses on a project directory, and I think you would have to deliberately reach up and outside, with something like open("../filename").
If it really worries you, you could make a new user/login for your rust development work.
User avatar
spamegg
Level 14
Level 14
Posts: 5117
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Learning Rust safely

Post by spamegg »

Does Cargo automatically limit scope somehow?
Cargo has commands like cargo build, cargo test, cargo run etc. that only works with the project directory. Instead of asking here you should go over to Rust Community's Discourse forum. https://users.rust-lang.org/

Technically you can still do anything you want (write malicious code that messes with your system) but I don't see how that would ever come up unless you go out of your way to do it on purpose.
How then do I write programs that CAN access/alter files outside of the project directory?
Do not access / alter files outside of the project directory. Just put the files you need inside the project directory. According to Cargo defaults, they would probably go into the /tests or /examples directory.

This is how modern project management works. It should not depend on outside files, since that cannot be reproduced on other people's machines. Project structures are made with open source collaboration in mind, not your personal PC.

If you are so scared of writing over your system files, then all the more reason NOT to access outside files! Outside files are not relevant to the project anyway!

You simply need to get familiar with Cargo projects. Thousands of beginners write projects without any fear of writing over any files. It's really not an issue. You need to get over your worries.
Post Reply

Return to “Programming & Development”