Руководство по стилю кода

Форматирование

fn calculation(some_long_variable_a: i8, some_long_variable_b: i8) -> bool {
    let x = some_long_variable_a * some_long_variable_b
        - some_long_variable_b / some_long_variable_a
        + sqrt(some_long_variable_a) - sqrt(some_long_variable_b);
    x > 10
}
fn calculate(
    some_long_variable_a: f32,
    some_long_variable_b: f32,
    some_long_variable_c: f32,
) -> f32 {
    (-some_long_variable_b + sqrt(
        // two parens open, but since we open & close them both on the
        // same line, only one indent level is used
        some_long_variable_b * some_long_variable_b
        - 4 * some_long_variable_a * some_long_variable_c
    // both closed here at beginning of line, so back to the original indent
    // level
    )) / (2 * some_long_variable_a)
}
// OK
fn foo(
    really_long_parameter_name_1: SomeLongTypeName,
    really_long_parameter_name_2: SomeLongTypeName,
    shrt_nm_1: u8,
    shrt_nm_2: u8,
) {
   ...
}

// NOT OK
fn foo(really_long_parameter_name_1: SomeLongTypeName, really_long_parameter_name_2: SomeLongTypeName,
    shrt_nm_1: u8, shrt_nm_2: u8) {
    ...
}
{
    // Complex line (not just a function call, also a let statement). Full
    // structure.
    let (a, b) = bar(
        really_long_parameter_name_1,
        really_long_parameter_name_2,
        shrt_nm_1,
        shrt_nm_2,
    );

    // Long, simple function call.
    waz(
        really_long_parameter_name_1, 
        really_long_parameter_name_2,
        shrt_nm_1, 
        shrt_nm_2,
    );

    // Short function call. Inline.
    baz(a, b);
}
struct Point<T> {
    x: T,
    y: T,    // <-- Multiline comma-delimited lists end with a trailing ,
}

// Single line comma-delimited items do not have a trailing `,`
enum Meal { Breakfast, Lunch, Dinner };
if condition {
    return 1    // <-- no ; here
}
match meal {
    Meal::Breakfast => "eggs",
    Meal::Lunch => { check_diet(); recipe() },
//    Meal::Dinner => { return Err("Fasting") }   // WRONG
    Meal::Dinner => return Err("Fasting"),
}

Стиль

let mut target_path = 
    self.path().expect(
        "self is instance of DiskDirectory;\
        DiskDirectory always returns path;\
        qed"
    );