A method call invokes behavior through a value or type, using dot syntax such as `record.trim()`, `record.split(',')`, or `1.2_f32.ceil()`. section 1.5 section 5.4.4
Method calls appear in several practical forms:
- Chain calls to process data, as in `record.trim().len()` and `record.split(',').map(...).collect()`. section 1.5
- Call methods on numeric values, as in `1.2_f32.ceil()` and `2_f32.powf(...)`, instead of passing values to standalone functions. section 5.4.4
- Use parentheses when unary minus could be confused with method-call precedence: `(-1.0_f32).powf(0.0)` is explicit, while `-1.0_f32.powf(0.0)` is parsed differently. section 5.4.4
Processing a CSV record
A record can be trimmed, split, transformed, and collected through a readable chain: `record.trim().split(',').map(|field| field.trim()).collect()`. The resulting fields are then indexed for later processing. section 1.5
Listing 1.2 Example of Rust code showing some basic processing of CSV data
fn main() { #1
let penguin_data = "\ #2
common name,length (cm)
Little penguin,33
Yellow-eyed penguin,65
Fiordland penguin,60
Invalid,data
";
let records = penguin_data.lines();
for (i, record) in records.enumerate() {
if i == 0 || record.trim().len() == 0 { #3
continue;
}
let fields: Vec<_> = record #4
.split(',') #5
.map(|field| field.trim()) #6
.collect(); #7
if cfg!(debug_assertions) { #8
eprintln!("debug: {:?} -> {:?}",
record, fields); #9
}
let name = fields[0];
if let Ok(length) = fields[1].parse::<f32>() { #10
println!("{}, {}cm", name, length); #11
}
}
}
Inspect the complete CSV-processing program to see method calls embedded in control flow, closure-based transformation, collection, and output. section 1.5

