Skip to content

Commit d4da3f5

Browse files
committed
stdlib: Use if/alt expressions in std::int
1 parent d85447c commit d4da3f5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/lib/int.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ iter range(int lo, int hi) -> int {
3232
fn to_str(int n, uint radix) -> str
3333
{
3434
assert (0u < radix && radix <= 16u);
35-
if (n < 0) {
36-
ret "-" + uint::to_str((-n) as uint, radix);
35+
ret if (n < 0) {
36+
"-" + uint::to_str((-n) as uint, radix)
3737
} else {
38-
ret uint::to_str(n as uint, radix);
39-
}
38+
uint::to_str(n as uint, radix)
39+
};
4040
}
4141

4242
fn pow(int base, uint exponent) -> int {
4343

44-
if (exponent == 0u) {
45-
ret 1;
44+
ret if (exponent == 0u) {
45+
1
4646
} else if (base == 0) {
47-
ret 0;
47+
0
4848
} else {
4949
auto accum = base;
5050
auto count = exponent;
5151
while (count > 1u) {
5252
accum *= base;
5353
count -= 1u;
5454
}
55-
ret accum;
56-
}
55+
accum
56+
};
5757
}
5858

5959
// Local Variables:

0 commit comments

Comments
 (0)