Skip to content

sahil-blulabs/learning_rust

 
 

Repository files navigation

Readme

Rust community

https://users.rust-lang.org/

Using rustmon

rustmon fileName.rs or rmon fileName.rs

For e.g., let say you have a rust program myprogram.rs then you'd need to run rustmon myprogram from the cli to run it in monitor mode.

Global rustfmt.toml file location => PR: rust-lang/rustfmt#3280 .

An ideal Cargo.toml file should be place in the root of folder opened in vscode i.e.,

(Bcoz Vscode's rust extension using command cargo fmt --all to format the code and throws error if the Cargo.toml file isn't formatted properly.)

[package]
name = "a-small-rust-app"
version = "0.1.0"

[[bin]]
name = "general"
path = "01_println.rs"

Formatter with vscode on code save

Simply install this extension and make sure that you have a cargo.toml file in the root of folder that you have opened in vscode to make format on save works!

Updating rustc via rustup

rustup update

more..

Tips:

  1. Tutorial here.

0.5. Was here.

  1. Whenever you see something like car::bike::scooter means that car is a module and bike is nested module inside car and scooter is a module nested inside bike.

  2. strings: amazing article, or read from amazing docs :LOL:.

  3. Gitignore.

  4. Primitives.

  5. Reqwest

  6. Rustler thing(popular idk why..): 1. @docs, 2. @github, @crates.io site.

MISSION: → → → → → → finish till vid-42.

**Continue the vid-35 tutorial/and making this gist. @ here

todo: Findout most popular web server from crate.io for rust??

Follow a different course, and it feel good too

Rust important links:

Creating rust projects with cargo (source)

$ cargo new hello-world-cargo --bin  # --bin tells the cargo to create a application project, not a library project.
$ cd hello-world-cargo
$ cargo run # This will output `Hello world!`. Congrats!!
$ `cargorun` or `cw` will run cargo in dev mode just like nodemon does, yikes!

The cargo application has entry point from src/main.rs file. All rust programs begin with a main function.

Firstly, anytime you make changes to src/main.rs, you need to run cargo run from cli. Secondly, cargo.toml file is similar to package.json file, as you'll find project info and dependencies there. Thirdly, you'll get a git initiated project with pre-made .gitignore file.

Compile and run with rustc

// File, main.rs
fn main(){
  println!("Hello world!")
}

Compile rust program via rustc main.rs and run it via ./main (from bash) or main.exe (from command prompt).

--bin
Create a package with a binary target (src/main.rs). This is the default behavior.
--lib
Create a package with a library target (src/lib.rs).

Snippets from the official rust vscode extension

src: https://github.com/rust-lang/vscode-rust#snippets

## Snippets
Snippets are code templates which expand into common boilerplate. IntelliSense includes snippet names as options when you type; select one by pressing enter. You can move to the next snippet 'hole' in the template by pressing tab. We provide the following snippets:

for - a for loop
macro_rules - declare a macro
if let - an if let statement for executing code only when a pattern matches
spawn - spawn a thread
extern crate - insert an extern crate statement
This extension is deliberately conservative about snippets and doesn't include too many. If you want more, check out Trusty Rusty Snippets.

So, fun.. below extension provides many rust snippets and officially recommended from rust vscode extension for snippets.

https://marketplace.visualstudio.com/items?itemName=polypus74.trusty-rusty-snippets

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 99.9%
  • Shell 0.1%