alnoda-workspaces/workspaces/rust-workspace/README.md

114 lines
2.3 KiB
Markdown
Raw Permalink Normal View History

2022-05-15 00:27:05 +12:00
# Rust workspace
2022-05-15 00:25:02 +12:00
2022-07-19 04:46:58 +12:00
Containerized isolated development environment for Rust programming language.
2022-05-15 00:25:02 +12:00
## Start
```
2023-07-06 03:36:02 +12:00
docker run --name space-1 -d -p 8020-8040:8020-8040 --restart=always alnoda/rust-workspace
2022-05-15 00:25:02 +12:00
```
2023-07-06 03:36:02 +12:00
open [localhost:8020](http://localhost:8020) in browser.
2022-05-15 00:25:02 +12:00
## Features
2023-07-06 03:36:02 +12:00
- [**Rust programming language**](https://www.rust-lang.org/)
- [**Cargo**](https://doc.rust-lang.org/cargo/) -s Rust package manager
- [**Rustup**](https://rustup.rs/) - installer for the systems programming language Rust
- [**Openvscode workspace features**](https://github.com/bluxmit/alnoda-workspaces/tree/main/workspaces/openvscode-workspace)
2023-07-09 06:26:55 +12:00
## Links
[__Alnoda docs__](https://docs.alnoda.org/)
[__Alnoda Hub__](https://alnoda.org)
2023-07-06 03:36:02 +12:00
## Hello world
Check Rust version
```
rustc --version
```
Create new project folder
```
cargo new my_example
cd my_example
```
The new project is created together, with hello-world app in `src` sub-folder
```
cat src/main.rs
```
Compile it
```
cargo build
```
And then run it
```
./target/debug/my_example
```
We can also compile and then run it, all in one step
```
cargo run
```
## Rustup
[Rustup](https://rustup.rs/) - is a toolchain is a specific version of the collection of programs needed to compile a Rust application.
It includes, but is not limited to:
- The compiler, rustc
- The dependency manager and build tool, cargo
- The documentation generator, rustdoc
Rustup provides ways to install, remove, update, select and otherwise manage these toolchains and their associated pieces.
Install specific version of Rust toolchain
```
rustup install 1.30.0
```
Show toolchains
```
rustup show
```
Change default toolchain
```
rustup default 1.30.0
```
## Project with dependencies
[Cargo](https://doc.rust-lang.org/cargo/) is Rust package manager. It is a tool that allows Rust packages to declare their
various dependencies and ensure that youll always get a repeatable build.
Clone example repo
```
git clone https://github.com/rdesarz/rust-http-server.git
cd rust-http-server
```
Build and start the server
```
cd example
cargo run --package http-server --bin http-server 0.0.0.0:8026
```
You will see that before cargo builds the package, it installs all the dependencies from the file `Cargo.toml`.
Then you can open workspace UI "My app on port 8026" and add `/hello.html` to the URL path.