# Translating TypeScript to Rust #1

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

**TypeScript**
```ts
console.log('Hello, world!')
```

**Rust**
```rs
println!("Hello, world!");
```

### 1.2 - Define a immutable variable

**TypeScript**
```ts
const PI = 3.1415
```

**Rust**
```rs
let PI = 3.1415;
```

### 1.3 - Define a mutable variable

**TypeScript**
```ts
let count = 0
```

**Rust**
```rs
let mut count = 0;
```

### 1.4 - Define variables with types

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

**Rust**
```rs
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

**TypeScript**
```ts
function sum (x: number, y: number): number {
  return x + y;
}
```

**Rust**
```rs
fn sum(x: i32, y: i32) -> i32 {
  x + y
}
```
