mirror of https://github.com/rust-lang/book
1015 B
1015 B
% Casting between types
There is a new edition of the book and this is an old link.
A type cast expression is denoted with the binary operator
as
. Executing anas
expression casts the value on the left-hand side to the type on the right-hand side.
# fn sum(values: &[f64]) -> f64 { 0.0 }
# fn len(values: &[f64]) -> i32 { 0 }
fn average(values: &[f64]) -> f64 {
let sum: f64 = sum(values);
let size: f64 = len(values) as f64;
sum / size
}
Here are the relevant sections in the new and old books: