Gabriel Rufino
Gabriel Rufino's Blog

Gabriel Rufino's Blog

Translating TypeScript to Rust #1

Translating TypeScript to Rust #1

Gabriel Rufino's photo
Gabriel Rufino
·Jan 15, 2022·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

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

1.1 - Output some text


console.log('Hello, world!')


println!("Hello, world!");

1.2 - Define a immutable variable


const PI = 3.1415


let PI = 3.1415;

1.3 - Define a mutable variable


let count = 0


let mut count = 0;

1.4 - Define variables with types


const n: number = 10
const f: number = 7.456
const s: string = 'Gabriel Rufino'
const b: boolean = true


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;

1.5 - Define a sum function


function sum (x: number, y: number): number {
  return x + y;


fn sum(x: i32, y: i32) -> i32 {
  x + y

Did you find this article valuable?

Support Gabriel Rufino by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
Share this