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


AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay