rustwasm/wasm_game_of_life: A Rust and WebAssembly tutorial implementing the Game of Life
Conway’s Game of life in Rust. Links https://github.com/rustwasm/wasm_game_of_life
Conway’s Game of life in Rust. Links https://github.com/rustwasm/wasm_game_of_life
Rust Ratatui components style example. Links https://github.com/ratatui/templates/tree/main/component
Parsing in Rust. Links https://depth-first.com/articles/2021/12/16/a-beginners-guide-to-parsing-in-rust/
Simple parser in Rust. Links https://adriann.github.io/rust_parser.html
Rust is a modern, general-purpose programming language known for its emphasis on performance, memory safety, and concurrency. It is designed to build reliable and efficient software, particularly in areas where performance is critical, such as systems programming, game engines, databases, and operating systems. Key characteristics of Rust include: Performance Rust offers speed and memory efficiency without requiring a runtime or garbage collector, making it suitable for low-level systems programming. Memory Safety Rust’s unique ownership model and borrow checker enforce memory safety at compile time, preventing common errors like null pointer dereferences and data races without the overhead of a garbage collector. ...
Data types forrust. Scalar Types Integers Floating Points Boolean Type Character Type Compound Types Tuple Type Array Type Backlinks rust variables
Structs are similar to tuples, in that both hold multiple related values. Like tuples, the pieces of a struct can be different types. Unlike with tuples, in a struct you’ll name each piece of data so it’s clear what the values mean. Adding these names means that structs are more flexible than tuples: you don’t have to rely on the order of the data to specify or access the values of an instance. ...
Creating vector in rust. let mut v = Vec::new(); v.push(5); v.push(6); v.push(7); v.push(8); println!("{:?}", v) [5, 6, 7, 8] Reading Elements of Vectors let v = vec![1, 2, 3, 4, 5]; let third: &i32 = &v[2]; println!("The third element is {third}"); let third: Option<&i32> = v.get(2); match third { Some(third) => println!("The third element is {third}"), None => println!("There is no third element."), } println!("{:?}", v) The third element is 3 The third element is 3 [1, 2, 3, 4, 5] Option<T> is an enum that represents the presence or absence of a value. It is a fundamental type in Rust’s approach to handling nullable values and potential errors, promoting explicit handling rather than implicit null pointers found in other languages. ...
Example of daemonizing in Rust use daemonize::Daemonize; fn main() { let daemonize = Daemonize::new() .pid_file("/tmp/my_daemon.pid") // Optional: Write PID to file .chown_pid_file(true) // Optional: Change ownership .working_directory("/tmp") // Optional: Set working directory .privileged_action(|| "Executed before drop privileges"); match daemonize.start() { Ok(_) => { // Daemon logic goes here println!("Daemon started successfully!"); loop { // Do daemon work std::thread::sleep(std::time::Duration::from_secs(5)); } }, Err(e) => eprintln!("Error, {}", e), } }
Getting Environment variables In Rust, we use std::env use std::env; fn main() { let x = env::vars(); for (a, b) in x { println!("{:?} {:?}", a, b) } } "ALTERNATE_EDITOR" "emacsclient -c " "BASH_FUNC_pathappend%%" "() { pathremove \"${1}\" \"${2}\";\n local PATHVARIABLE=${2:-PATH};\n export \"$PATHVARIABLE\"=\"${!PATHVARIABLE:+${!PATHVARIABLE}:}$1\"\n}" "BASH_FUNC_pathprepend%%" "() { pathremove \"${1}\" \"${2}\";\n local PATHVARIABLE=${2:-PATH};\n export \"$PATHVARIABLE\"=\"$1${!PATHVARIABLE:+:${!PATHVARIABLE}}\"\n}" "BASH_FUNC_pathremove%%" "() { local IFS=':';\n local NEWPATH;\n local DIR;\n local PATHVARIABLE=${2:-PATH};\n for DIR in ${!PATHVARIABLE};\n do\n if [ \"${DIR}\" != \"${1}\" ]; then\n NEWPATH=${NEWPATH:+$NEWPATH:}$DIR;\n fi;\n done;\n export \"$PATHVARIABLE\"=\"${NEWPATH}\"\n}" "BROWSER" "firefox" "CARGO" "/home/alexforsale/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" "CARGO_HOME" "/home/alexforsale/.cargo" "CARGO_MANIFEST_DIR" "/tmp/babel-5iTIx3/cargoDOdDFj" "CARGO_MANIFEST_PATH" "/tmp/babel-5iTIx3/cargoDOdDFj/Cargo.toml" "CARGO_PKG_AUTHORS" "" "CARGO_PKG_DESCRIPTION" "" "CARGO_PKG_HOMEPAGE" "" "CARGO_PKG_LICENSE" "" "CARGO_PKG_LICENSE_FILE" "" "CARGO_PKG_NAME" "cargoDOdDFj" "CARGO_PKG_README" "" "CARGO_PKG_REPOSITORY" "" "CARGO_PKG_RUST_VERSION" "" "CARGO_PKG_VERSION" "0.1.0" "CARGO_PKG_VERSION_MAJOR" "0" "CARGO_PKG_VERSION_MINOR" "1" "CARGO_PKG_VERSION_PATCH" "0" "CARGO_PKG_VERSION_PRE" "" "CLICOLOR" "1" "DBUS_SESSION_BUS_ADDRESS" "unix:path=/run/user/1000/bus" "DEBUGINFOD_URLS" "https://debuginfod.archlinux.org " "DESKTOP_SESSION" "i3" "DISPLAY" ":0" "DISTRO" "arch" "DISTROVER" "rolling" "EDITOR" "emacsclient -t " "FILE" "emacsclient -c -e (dired-jump)" "GOPATH" "/home/alexforsale/.local" "GPG_TTY" "/dev/tty1" "GTK2_RC_FILES" "/home/alexforsale/.config/gtk-2.0/gtkrc" "GTK_MODULES" "canberra-gtk-module" "GTK_RC_FILES" "/home/alexforsale/.config/gtk-1.0/gtkrc" "GTK_THEME" "Breeze-Dark" "HG" "/usr/bin/hg" "HISTFILE" "/home/alexforsale/.local/share/bash/bash_history" "HOME" "/home/alexforsale" "I3SOCK" "/run/user/1000/i3/ipc-socket.2313" "LANG" "en_US.UTF-8" "LD_LIBRARY_PATH" "/tmp/babel-5iTIx3/cargoDOdDFj/target/debug/deps:/tmp/babel-5iTIx3/cargoDOdDFj/target/debug:/home/alexforsale/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib:/home/alexforsale/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib" "LOGNAME" "alexforsale" "LS_COLORS" "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.7z=01;31:*.ace=01;31:*.alz=01;31:*.apk=01;31:*.arc=01;31:*.arj=01;31:*.bz=01;31:*.bz2=01;31:*.cab=01;31:*.cpio=01;31:*.crate=01;31:*.deb=01;31:*.drpm=01;31:*.dwm=01;31:*.dz=01;31:*.ear=01;31:*.egg=01;31:*.esd=01;31:*.gz=01;31:*.jar=01;31:*.lha=01;31:*.lrz=01;31:*.lz=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.lzo=01;31:*.pyz=01;31:*.rar=01;31:*.rpm=01;31:*.rz=01;31:*.sar=01;31:*.swm=01;31:*.t7z=01;31:*.tar=01;31:*.taz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tgz=01;31:*.tlz=01;31:*.txz=01;31:*.tz=01;31:*.tzo=01;31:*.tzst=01;31:*.udeb=01;31:*.war=01;31:*.whl=01;31:*.wim=01;31:*.xz=01;31:*.z=01;31:*.zip=01;31:*.zoo=01;31:*.zst=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.jxl=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:" "MAIL" "/var/spool/mail/alexforsale" "MAIL_APP" "thunderbird" "MM_CHARSET" "en_US.UTF-8" "MONITOR1" "DP-1" "MOTD_SHOWN" "pam" "PATH" "/home/alexforsale/.local/perl5/bin:/home/alexforsale/.ghcup/bin:/home/alexforsale/.cargo/bin:/home/alexforsale/.cabal/bin:/home/alexforsale/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin" "PERL5LIB" "/home/alexforsale/.local/perl5/lib/perl5" "PERL_LOCAL_LIB_ROOT" "/home/alexforsale/.local/perl5" "PERL_MB_OPT" "--install_base \"/home/alexforsale/.local/perl5\"" "PERL_MM_OPT" "INSTALL_BASE=/home/alexforsale/.local/perl5" "PWD" "/tmp/babel-5iTIx3/cargoDOdDFj" "QT_XCB_GL_INTEGRATION" "none" "RUSTUP_HOME" "/home/alexforsale/.rustup" "RUSTUP_TOOLCHAIN" "stable-x86_64-unknown-linux-gnu" "RUST_BACKTRACE" "0" "RUST_RECURSION_COUNT" "1" "SCREENDIR" "/home/alexforsale/.config/screen" "SCREENRC" "/home/alexforsale/.config/screen/config" "SHELL" "/usr/bin/bash" "SHLVL" "2" "SSH_AGENT_PID" "2186" "SSH_ASKPASS" "ssh-askpass" "SSH_AUTH_SOCK" "/tmp/ssh-XXXXXXZtMjDO/agent.2185" "SSL_CERT_DIR" "/etc/ssl/certs" "SSL_CERT_FILE" "/etc/ssl/cert.pem" "SUDO_ASKPASS" "/home/alexforsale/.local/bin/ssh-askpass" "TERM" "ansi" "TERMINAL" "alacritty" "USER" "alexforsale" "VISUAL" "emacsclient -c " "WINDOWPATH" "1" "XAUTHORITY" "/home/alexforsale/.Xauthority" "XCURSOR_PATH" ":/usr/share/icons:/home/alexforsale/.local/share/icons" "XCURSOR_SIZE" "24" "XCURSOR_THEME" "Bibata-Modern-Classic" "XDG_CACHE_HOME" "/home/alexforsale/.cache" "XDG_CONFIG_HOME" "/home/alexforsale/.config" "XDG_DATA_DIRS" "/usr/share:/usr/local/share" "XDG_DATA_HOME" "/home/alexforsale/.local/share" "XDG_DESKTOP_DIR" "/home/alexforsale/Desktop" "XDG_DOCUMENTS_DIR" "/home/alexforsale/Documents" "XDG_DOWNLOAD_DIR" "/home/alexforsale/Downloads" "XDG_MUSIC_DIR" "/home/alexforsale/Music" "XDG_PICTURES_DIR" "/home/alexforsale/Pictures" "XDG_PUBLICSHARE_DIR" "/home/alexforsale/Public" "XDG_RUNTIME_DIR" "/run/user/1000" "XDG_SEAT" "seat0" "XDG_SESSION_CLASS" "user" "XDG_SESSION_ID" "1" "XDG_SESSION_TYPE" "tty" "XDG_TEMPLATES_DIR" "/home/alexforsale/Templates" "XDG_VIDEOS_DIR" "/home/alexforsale/Videos" "XDG_VTNR" "1" "_" "/usr/bin/emacs" "npm_config_prefix" "/home/alexforsale/.local" Specific Variable std::env::var returns a Result<String, VarError>. ...