(String, usize) { let length = s.len(); // len() returns the length of a String (s, length) }"> (String, usize) { let length = s.len(); // len() returns the length of a String (s, length) }"> (String, usize) { let length = s.len(); // len() returns the length of a String (s, length) }">

<aside> 💡

Notion Tip: Tag pages to let collaborators know what they can expect to use the page for. You can add one or many tags to any page in a wiki.

</aside>

fn main() {
    println!("Hello, world!");

    another_function();
    another_function2(12);
    print_labeled_measurement(2, 'G');
    let s1 = String::from("hello");

    let (s2, len) = calculate_length(s1);

    println!("The length of '{}' is {}.", s2, len);
}

fn another_function() {
    println!("Another function.");
}

fn another_function2(x: i32) {
    println!("The value of x is: {x}");
}

fn print_labeled_measurement(value: i32, unit_label: char) {
    println!("The measurement is: {value}{unit_label}");
}

fn calculate_length(s: String) -> (String, usize) {
    let length = s.len(); // len() returns the length of a String

    (s, length)
}

Contoh lain :

fn five() -> i32 {
    5 + 4
}
let x = five();