DEV Community

Cover image for RustLings III (conditions and convert)
Blitty
Blitty

Posted on

RustLings III (conditions and convert)

Bonjour!!!

I am back... it's been a while, but lets continue!!!

Next thing in rustlings is control flow which is very easy but if u come from C maybe a bit tricky. But nothing difficult!!!

The keywords are:

if <condition> {} // first condition
else if <condition> {} // other condition
else {} // none condition is true
Enter fullscreen mode Exit fullscreen mode

nothing from another world. But you need to know that, <condition> has to be a bool, otherwise you will get an error.

Ternary conditions are weird... I like more C.

if <condition> { } else { }
Enter fullscreen mode Exit fullscreen mode

You need those {} otherwise the compiler will say something like
Not cool

The next thing I had to do was a quiz, very easy you don't miss nothing, except for one thing I have discovered!!

When u are using, say i8 and u want to return or you need it to be i32. There are two ways:

  • into
let i: i8 = 0;
let x: i32 = i.into();
Enter fullscreen mode Exit fullscreen mode
  • from
let i: i8 = 0;
// u don't even need to specify here xd
let x: i32 = i32::from(i);
Enter fullscreen mode Exit fullscreen mode

from is recommended by the docs


Follow me!

(I liked more the red bird :_()
🐦 Twitter
πŸ™ GitHub
πŸ‘₯ LinkdIn


Top comments (0)