DEV Community

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

Posted on

2 2

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


Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay