Gabriel Rufino
Gabriel Rufino's Blog

Gabriel Rufino's Blog

Translating TypeScript to Rust #3

Translating TypeScript to Rust #3

Gabriel Rufino's photo
Gabriel Rufino
·May 9, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Remember that every translation is subject to inaccuracies in some cases. Feel free to correct or suggest better translations in the comments.

3.1 - Tuples

TypeScript

const position: [number, number] = [23.45348, 24.92868];

Rust

let position: (f32, f32) = (23.45348, 24.92868);

3.2 - Arrays

TypeScript

const array = [1, 2, 3, 4];

Rust

let array = [1, 2, 3, 4];

3.3 - Building (Transpiling & Compiling)

TypeScript

$ npx tsc

Rust

$ cargo build

3.4 - Ternary operator

TypeScript

const condition: boolean = true;
const result: number = condition ? 1 : 2;

Rust

let condition: bool = true;
let result: i32 = if condition { 1 } else { 2 };
 
Share this