title: 'Getting started with Rust: Function, struct and ref'
date: 05 Dec 2017 00:00:00 +0000
author: Mathieu Nivoliez
draft: true
lang: en
---
Hello everyone! Today we continue on our rust serie, we are going to talk about function and struct.
## "Seems like a lot? Are we really going to cover all this?"
Yes and yes.
In order to do all that, we are going to need a variable, let's define that:
```rust
// We want to buy a fallout boy, so lets define a number of caps.
letcaps=5;
```
We just define a variable caps of value 5.
## "Wait a minute! In the previous post, didn't you said that rust was a strongly typed language?"
I did, and it's true. Let me explain you the beautiful world of type inference!
At compile time, the rust compiler will try to guess the type of `caps` from its use (assignation or operation).
I said *try* because, sometimes, the rust compiler will not succeded. For example, if the using of caps not allow to define its type.
The type inference is here to avoid writting types when it can easily be guessed.
You still can define type with this syntax:
```rust
letcaps:usize/* type define here */=5;
```
That said, a variable can be shadowed. Imagine that you got the number of caps in the form of a string, it makes senses to still call it caps. That's what shadowing is about.
Let me show you:
```rust
letcaps="five";
letcaps=get_number_from_string(caps);// caps is now 5
```
It may not be intuitive yet, but through practice, it will.
## "Ok, but what about this *get_number_from_string* thing?"
Excellent transition, it's almost like if I was writting your line.
*get_number_from_string* is a function. Let see how we can define it: