Welcome! This is my personal blog about Web technologies, software development, open source and other related topics
The ideas and opinions expressed here are solely mine and don't represent those of others, either individuals or companies.The code snippets or references to software products or analogous are to be used without any warranty of any kind. If you enjoy the content, feel free to share it and re-use it as long as you provide a link to the original post.
A decorator class has a special class method __call__(). This method is responsible for supporting a case when an object is called. The advantage of decorator class over function is they bring the OOP feature such as inherirtance etc.
In the below code snippet the the decorated function is assigned to the self.func i.e. to the decorator. The decorator class itself calls the decorated function.
Passing a message to the decorator class. Here the message is passed from the LogDecorator and initailised in the class constructor.
The calling method is accessible in the __call__() method.
To install Rust on Windows subsystem for Linux, use this shell command-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Check the version of Rust-
rustup --version
Check the version of Rust compiler
rustc --version
To update the Rust, use following command-
rustup update
Create a main.rs file and add code to print a string
fun main(){
println!("Hello World!")
}
Compile using rust compiler
rustc main.rs
This should create a pdb and exe file
Execute the main.exe file and this should print the string
Create a Rust project using Cargo
Cargo is a build and package manager.
Helps to manage dependecies for repetable builds
Downloads and builds external libraries
calls rustc with correct parameters
Included with standard rustup installation
For creating a new Rust project using Cargo package manager-
cargo new first_rust_prj
Tip – The name of the project should be snake case. Example this will give a warning. Atlhough this will create a project.
cargo new FirstRustPrj //Warning
Creating binary (application) `FirstRustPrj` package
warning: the name `FirstRustPrj` is not snake_case or kebab-case which is recommended for package names, consider `firstrustprj`
This should create following folder structure with main.rs and Cargo.toml (configuration) file.
TOML – Tom’s Obvoius Minimal Language.
Alternatively, you can create a project without using Cargo. Create a src directory and create appropriate Cargo.toml namually. To create toml file use init command
cargo init
Building and Running Cargo project
Build the Cargo project using following command-
cargo build
To compile and run directly from the project folder, use following command-
cargo run
Error compiling the project-
error: linker link.exe not found
So the pre-requisite for windows machine is to have MS C++ build tools. Install the smae from here. It should be around 5 GB.