These are chat archives for rust-lang/rust

18th
May 2019
Frederic
@FredericChang
May 18 08:20
pub fn is_leap_year(year: u64) -> bool {
if (year % 4) == 0 {
if (year % 100) == 0 {
if (year % 400) == 0 {
return Ture;
}
}
}
}
image.png
somebody can tell me what's wrong with this function
thank you
Siddhant Sanyam
@siddhant3s
May 18 08:21
It never returns false
laurent bernabé
@loloof64
May 18 08:21
"return Ture" ?
Siddhant Sanyam
@siddhant3s
May 18 08:21
I mean it never talks about the else part
^^ And that.
Frederic
@FredericChang
May 18 08:22
ok i check else first
thank u
laurent bernabé
@loloof64
May 18 08:28
I think that it was because, on Rust, both branches must have the same types : and Nothing is can't be the same as bool.
Frederic
@FredericChang
May 18 08:29
great to know
Siddhant Sanyam
@siddhant3s
May 18 08:29
That's right. Also if the else part is missing, the result of the expression is automatically Unit.
laurent bernabé
@loloof64
May 18 08:29
ah right, Unit, and not Nothing
Frederic
@FredericChang
May 18 09:45
image.png
Is it right way to import lib.rs??
Aleksandrov Vladimir
@invis87
May 18 09:52
зуб не дам, может в тестах и не надо так, но по идее external crate leap; и потом use leap::* (а шрифты у вас вырви глаз просто)
Frederic
@FredericChang
May 18 10:14
image.png
thanks
I did iy
I did it.
Aleksandrov Vladimir
@invis87
May 18 10:59
а не проще ли is_leap_year написать так { year % 400 == 0 }
Denis Lisov
@tanriol
May 18 11:03
@invis87 Please note that this is the global rust-lang/rust channel and talking in English is more polite here.