All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to sort a vector in Rust

In Rust, there are 2 ways to sort a vector. Using sort Method The sort(&mut self) method sorts the slice. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. For example, fn main() { let mut v = [3, -5, ...
Tomoki

How to Remove an Element from a Vector in Rust

In Rust, there are 2 ways to remove an element from a vector. Using retain Function The vec::retain() function retains only the elements specified by the predicate. For example, fn main() { let mut v = vec![1, 3, 2, 3, 4]; v.retain(|&x| x ...
aweis

How to Find the Index of an Element in a Vector in Rust

In Rust, using the position function is the easiest way to find the index of an element in a vector. Using position Method The position() method searches for an element in an iterator, returning its index. position() is short-circuiting; in other ...
pooriabt

How to Convert Vec to a String in Rust

In Rust, there are 2 ways to convert Vec to a string. Using collect Function The collect() function transforms an iterator into a collection. collect() can take anything iterable, and turn it into a relevant collection. This is one of the more powe...
Patcher56

How to Make a Reverse Ordered For Loop in Rust

In Rust, using the rev() function is the easiest way to make a reverse ordered for loop. Using rev Function The .rev() function reverses an iterator’s direction. Usually, iterators iterate from left to right. After using rev(), an iterator will ins...
aweis

How to Iterate Over a String by Character in Rust

In Rust, there are 3 ways to iterate over a string by character. Using chars Method The chars() method returns an iterator over the chars of a string slice. See the following example: fn main() { let s = "abc"; for c in s.chars() { pr...
pooriabt

How to Concatenate Vectors in Rust

In Rust, there are 2 ways to concatenate vectors . Using append Method The method append() moves all the elements of other into Self, leaving other empty. See the following example: fn main() { let mut a = vec![1, 2]; let mut b = vec![3, 4]...
Unused

How to Access Command Line Parameters in Rust

In Rust, there are 2 ways to access command line parameters. Using std::env::args Function This function actually returns the arguments that this program was started with. See the following example: use std::env; fn main() { for arg in env::...
Patcher56

How to Split a String in Rust

In Rust, there are 3 ways to split a string. Using split Function An iterator over substrings of this string slice, separated by characters matched by a pattern. See the following example: fn main() { let s = "abc1bcd2e"; let _split = s.sp...
ada

How To Make a For Loop and Range in Rust

In Rust, there are 3 ways to support For Loop expression.Using while Expression A while loop begins by evaluating the boolean loop conditional operand. fn main() { let mut i = 0; while i < 3 { println!("{}", i); i += 1; } // Vec ...
ada

How to convert string to json in Rust

In Rust, there are 3 ways to convert string to json. Using Serde JSON Serde is a framework for serializing and deserializing Rust data structures efficiently and generically. Adding dependencies In Cargo.toml file we’ll add this information. [de...
Patcher56

How to install Babylon.js

Babylon.js is a real time 3D engine using a JavaScript library for displaying 3D graphics in a web browser via HTML5. The source code is available on GitHub and distributed under the Apache License 2.0.--pname-- is a powerful, beautiful, simple, and ...

How to install Three.js

Three.js is a cross-browser JavaScript library and application programming interface (API) used to create and display animated 3D computer graphics in a web browser using WebGL.The aim of the project is to create an easy to use, lightweight, 3D libra...