Translating TypeScript to Rust #1

Search for a command to run...

Keep going i learned a lot from you
**Remember that every translation is subject to inaccuracies in some cases**. Feel free to correct or suggest better translations in the comments
Remember that every translation is subject to inaccuracies in some cases. Feel free to correct or suggest better translations in the comments. 2.1 - The if statement TypeScript const condition: boolean = true if (condition) { console.log('Print me!...
Sorting algorithms are essential for understanding computer science and solving numerous practical problems. Among them, Selection Sort stands out as a straightforward algorithm, often used for educational purposes due to its simplicity. In this arti...

In Rust, the Default trait is a widely used standard library trait that provides a way to create default values for types. This can be incredibly useful for initializing structs, enums, and other data types when explicit values are not provided. In t...

In this article, we will walk through the implementation of a basic stack data structure in Rust, leveraging generics to make it versatile for various types. The stack follows a "Last In, First Out" (LIFO) principle, meaning the last added element is...

In the world of Node.js development, UUIDs (Universally Unique Identifiers) have been a staple for creating unique identifiers. Traditionally, developers have relied on external packages like uuid to generate these identifiers. However, with the adve...

How you can use Symbol.toPrimitive to customize the conversion to primitives

This is the first post of a series of many posts translating TypeScript into Rust language. The idea is pretty simple like this: help those who know TypeScript but it's learning Rust with two code snippets, one in TypeScript and one for Rust.
Remember that every translation is subject to inaccuracies in some cases. Feel free to correct or suggest better translations in the comments
TypeScript
console.log('Hello, world!')
Rust
println!("Hello, world!");
TypeScript
const PI = 3.1415
Rust
let PI = 3.1415;
TypeScript
let count = 0
Rust
let mut count = 0;
TypeScript
const n: number = 10
const f: number = 7.456
const s: string = 'Gabriel Rufino'
const b: boolean = true
Rust
let n1: i8 = 10;
let n2: i16 = -20;
let n3: i32 = 30;
let n4: i64 = -40;
let n5: u8 = 10;
let n6: u16 = 20;
let n7: u32 = 30;
let n8: u64 = 40;
let f1: f32 = 3.14;
let f2: f64 = 3.1415;
let s: String = String::from("Gabriel Rufino");
let b: bool = true;
TypeScript
function sum (x: number, y: number): number {
return x + y;
}
Rust
fn sum(x: i32, y: i32) -> i32 {
x + y
}