Mar 30 2021
RUST on RPI
even with so many soft and hardware projects open i still think i have to keep my mind openfor new things:
RUST
a programming language i want to know what it is and how i can play with it on a Raspberry Pi.
see a video about it here,
go to RUST website install
and find documentation: book
ok:
* booting up my old RPI3B+
* update
* install RUST
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
and reboot.
check:
rustc --version
cargo --version
i see here 1.51.0
start rust project with:
mkdir rust
cd rust
cargo new test_rust
cd test_rust
cargo build or directly
cargo run ( means build & run )
and now can use manual start:
./target/debug/test_rust
for edit:
nano src/main.rs
like:
fn main() { println!("Hello, KLL!"); }
even in the mini desktop version of Raspberry Pi OS
GEANY is preinstalled and that can be used ( besides 'nano' )
as editor / -IDE-
in the video also make a LED blink using
[dependencies]
rust_gpiozero = "0.2.0"
update:
instead of play and learn RUST i think ( for new year 2022 )
what could i do with RUST?
and i found ROCKET a web framework for RUST
https://en.wikipedia.org/wiki/Rocket_(web_framework)
https://api.rocket.rs/v0.5-rc/rocket/
i do on my RPI3 on a test setup USB stick for the new BULLSEYE Linux OS
where i tested RUST already
mkdir test_rocket
cd test_rocket
git clone https://github.com/SergioBenitez/Rocket
cd Rocket
cd examples/hello_world
cargo run
that's a long building...( with 2 warnings )
( using ROCKET v0.5.0-rc.1 )

no while this test of a Rust Rocket example worked well ( more here )
as a next test i try to copy one of the examples out ( to MY APP ) and had a hard time to get it build/compiled/run
must copy what sub-directories and change what path info in Cargo.toml
i started from the TO-DO example because it has already html template files and sqlite3 database
for this i add installed ( sudo apt install )
sqlite3
sqlitebrowser
while i work on that i needed a backup batch
now to learn more i follow
https://blog.rocketinsights.com/rust-web-server-from-zero-to-cloud/
where he uses https://actix.rs/
instead of ROCKET.
mkdir test_actix
cd test_actix
cargo new bee-nice
cd bee-nice
nano Cargo.toml
[package]
name = "bee-nice"
version = "0.1.0"
edition = "2018"
[dependencies]
actix-web = "3"
nano src/main.rs
use std::io;
use actix_web::{get, App, HttpResponse, HttpServer, Responder};
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello, world!")
}
#[actix_web::main]
async fn main() -> io::Result<()> {
HttpServer::new(|| App::new().service(hello))
.bind("127.0.0.1:8080")?
.run()
.await
}
cargo build
cargo run
check browser localhost:8080
( note: only works local, NOT from remote like ( 192.168.1.204:8080 ) )
and also i follow the next example what uses CSS and a template HTML file
what got little text data from main.rs variables.
after
cargo build --release
get a 10 times smaller executable in
./target/release/bee-nice

now the upper level for web- server / site would be a CMS Content Management System
checkout: https://github.com/getzola/zola
and see https://www.getzola.org/documentation/getting-started/installation/ that you could install a runable or try to build it from github source ( 12MB zip ).
for available themes see https://www.getzola.org/themes/
i needed some time to understand / find info / that this is far from my understanding of a CMS with a database
and online 'news/blog' add, edit, delete admin ( login ) pages.
basically in a directory you write / or 'ftp upload'
a 'blog_entry.md' file markup style with title / desc / blogtext
and the server code runable finds it, creates a link on the index page and shows it ( if clicked ).
so while for my feeling the Content Management features are poor its qualities might be somewhere else ?themes?HTML?CSS?
next want check on https://lib.rs/crates/create-rust-app
here my LOG:
-1- install RUST
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-2- install NODE
( on RPI4 with BULLSEYE can not install node v14..17
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo npm install --global yarn
-3- follow #https://lib.rs/crates/create-rust-app
and install:
cargo install tsync
cargo install create-rust-app
create-rust-app my-todo-app
/// asks
[create-rust-app] Running `git config user.name`
[create-rust-app] You do not have a git user name set.
Choose a name to use when committing:: test
[create-rust-app] Running `git config user.name "test"`
[create-rust-app] You do not have a git user email set.
Choose an email to use when committing:: test@gmail.com
[create-rust-app] Running `git config user.email "test@gmail.com"`
/// shows
Congratulations, your project is ready!
[create-rust-app] • Install cargo-watch (for development)
[create-rust-app] $ cargo install cargo-watch
[create-rust-app] • Install diesel (to manage the database)
[create-rust-app] $ cargo install diesel_cli --no-default-features --features "postgres"
[create-rust-app] • Begin development!
[create-rust-app] 1. Change to your project directory
[create-rust-app] $ cd "./my-todo-app"
[create-rust-app] 2. Open `.env` and set the DATABASE_URL
[create-rust-app] 3. Setup your database:
[create-rust-app] $ diesel database reset
[create-rust-app] 4. Develop! Run the following for continuous compilation:
[create-rust-app] $ cargo fullstack
[create-rust-app] • Enjoy!
///