Mukul Latiyan

Mukul Latiyan

363 Articles Published

Articles by Mukul Latiyan

Page 21 of 37

Loop Keyword in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 240 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 continue keyword.ExampleConsider the example shown below −fn main() {    let mut count = 0u32;    println!("Infinite loop begins!!");    // Infinite loop    loop {       count += 1;       if count == 4 {          println!("four");          continue; ...

Read More

Match in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 349 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);    match number {       1 => println!("One!")       2 | 3 | 5 | 7 | 11 => println!("A prime"),       13..=19 => println!("A teen"),       _ => println!("Ain't special"),    } }In the above example, we are trying to use a ...

Read More

Panic! Macro in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 353 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, and hence, it quits. Because of this manner with which the program quits, we commonly use panic! for unrecoverable errors.SyntaxThe syntax of calling a panic looks like this −panic!("An error was encountered");We usually pass a custom message inside the parentheses.ExampleConsider the code shown below as a reference −fn drink(beverage: &str) ...

Read More

Path Struct in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 468 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 −use std::path::Path; fn main() {    // Create a `Path` from an `&'static str`    let path = Path::new(".");    // The `display` method returns a `Show`able structure    let display = path.display();    // Check if the path exists    if path.exists() {       println!("{} exists", display);    }   ...

Read More

Unsafe Operation in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 277 Views

Unsafe Operations are done when we want to ignore the norm that Rust provides us. There are different unsafe operations that we can use, mainly:dereferencing raw pointersaccessing or modifying static mutable variablescalling functions or methods which are unsafeThough it is not recommended by Rust that we should use unsafe operations at all, we should use them only when we want to bypass the protections that are put in by the compiler.Raw Pointers In Rust, the raw pointers * and the references &T perform almost the same thing, but references are always safe, as they are guaranteed by the compiler to point ...

Read More

Vectors in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 489 Views

Vectors in Rust are like re-sizable arrays. They are used to store objects that are of the same type and they are stored contiguously in memoryLike Slices, their size is not known at compile-time and can grow or shrink accordingly. It is denoted by Vec in RustThe data stored in the vector is allocated on the heap.ExampleIn the below example, a vector named d is created using the Vec::new(); function that Rust provides.fn main() {    let mut d: Vec = Vec::new();    d.push(10);    d.push(11);    println!("{:?}", d);    d.pop();    println!("{:?}", d); }We push the elements into a ...

Read More

While and For Range in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 240 Views

We know that Rust provides a loop keyword to run an infinite loop. But the more traditional way to run loops in any programming language is with either making use of the while loop or the for range loop.While LoopThe while loop is used to execute a code of block until a certain condition evaluates to true. Once the condition becomes false, the loop breaks and anything after the loop is then evaluated. In Rust, it is pretty much the same.ExampleConsider the example shown below:fn main() {    let mut z = 1;    while z < 20 {   ...

Read More

string.sub() function in Lua

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 81K+ Views

Another important function of the Lua’s string library is the string.sub() function. The string.sub() function is used to extract a piece of the string.The string.sub() function takes three arguments in general, the first argument being the name of the string from which we want to extract a piece, the second argument is the i-th index or say, the starting index of the string piece that we want, and the third and the last argument is the j-th index of the last index of the string piece we want.It should be noted that both the starting index and the ending index, ...

Read More

How to check if a file exists in Golang?

Mukul Latiyan
Mukul Latiyan
Updated on 01-Nov-2023 43K+ Views

In order to check if a particular file exists inside a given directory in Golang, we can use the Stat() and the isNotExists() function that the os package of Go's standard library provides us with.The Stat() function is used to return the file info structure describing the file. Let's first use the Stat() function only and see whether it will be enough to detect the presence of a file in Go.Example 1Consider the code shown below.package main import(    "fmt"    "os" ) func main() {    if _, err := os.Stat("sample.txt"); err == nil {       fmt.Printf("File ...

Read More

How to Concatenate Column Values in a Pandas DataFrame?

Mukul Latiyan
Mukul Latiyan
Updated on 28-Sep-2023 8K+ Views

Pandas is a powerful library for data manipulation and analysis in Python. It provides a variety of functions and tools for handling and transforming data, including the ability to concatenate column values in a Pandas DataFrame. In a Pandas DataFrame, columns represent variables or features of the data. Concatenating column values involves combining the values of two or more columns into a single column. This can be useful for creating new variables, merging data from different sources, or formatting data for analysis. To concatenate column values in a Pandas DataFrame, you can use the pd.Series.str.cat() method. This method concatenates two ...

Read More
Showing 201–210 of 363 articles
« Prev 1 19 20 21 22 23 37 Next »
Advertisements