Mukul Latiyan has Published 474 Articles

Path Struct in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:40:28

339 Views

Path struct in Rust is used to represent the file paths in the underlying filesystem. It should also be noted that a Path in Rust is not represented as a UTF-8 string; instead, it is stored as a vector of bytes (Vec).ExampleConsider the example shown below − Live Demouse std::path::Path; ... Read More

Panic! Macro in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:38:40

193 Views

Handling critical errors in Rust is done with the help of panic! Macro. There are other ways to handle errors in Rust, but panic is unique in the sense that it is used to deal with unrecoverable errors.When we execute the panic! Macro, the whole program unwinds from the stack, ... Read More

Match in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:32:57

213 Views

Rust provides us with a match keyword that can be used for pattern matching. It is similar to the switch statement in C, and the first arm that matches is evaluated.ExampleConsider the example shown below −fn main() {    let number = 17;    println!("Tell me about {}", number);   ... Read More

Loop Keyword in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:31:52

143 Views

Rust provides a loop keyword that allows us to run an infinite loop. The infinite loop indicated by the help of the loop keyword can be broken by the use of the break keyword. Also, we can exit an iteration and continue the infinite loop with the help of the ... Read More

HashMap in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:29:00

478 Views

HashMap is an important data structure, as it allows us to store data in key-value pairs. In Rust, HashMap stores values by key.HashMap keys can be Boolean, Integer, strings or any other data type that implements the Eq and Hash traits.HashMaps can grow in size, and when the space becomes ... Read More

From and Into Traits In Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:28:03

238 Views

From and Into are two traits that Rust provides us. They are internally linked.From TraitWe make use of From trait when we want to define a trait to how to create itself from any other type. It provides a very simple mechanism with which we can convert between several types.For ... Read More

Enums in Rust Programing

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:25:50

114 Views

Also referred to as enumerations, enums are very useful in certain cases. In Rust, we use enums, as they allow us to define a type that may be one of a few different variants.Enumerations are declared with the keyword enum.Example Live Demo#![allow(unused)] #[derive(Debug)] enum Animal {    Dog,    Cat, } ... Read More

Constants in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:09:33

143 Views

Rust provides us with two types of constants. These are −const − an unchangeable valuestatic − possible mutable value with static lifetime.If we try to assign another value to an already declared const value, the compiler will throw an error.ExampleConsider the example shown below − Live Demostatic LANGUAGE: &str = "TutorialsPoint-Rust"; ... Read More

Channels in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:06:35

574 Views

Channels are a medium that allow communication to take place between two or more threads. Rust provides asynchronous channels that enable communication between threads.Channels in Rust allow a unidirectional flow of communication between two endpoints. These two endpoints are Sender and Receiver.ExampleConsider the example shown below −use std::sync::mpsc::{Sender, Receiver}; use ... Read More

Casting in Rust Programming

Mukul Latiyan

Mukul Latiyan

Updated on 03-Apr-2021 14:05:17

313 Views

Casting or explicit conversion is only allowed in Rust, there’s no implicit conversion that the compiler of Rust does for us. It is known that, in many cases, implicit conversion can lead to data losses, which is not a good thing.Rules for converting between different types is pretty similar to ... Read More

Advertisements