[Pre-RFC] Named .arguments

I just found an alternative to named arguments (admitted an “alternative” that’s not 100% serious and using unstable features) over here. It would make the hour_angle_from_elevation example look like this:

named_args!( // <- more realistically using a procedural macro

// Calculates the hour angle (in radians) at the location for the given angular elevation.
// - lat: Latitude of location in degrees
// - decl: Declination in radians
// - elev: Angular elevation angle in radians
fn hour_angle_from_elevation(lat: f64, decl: f64, elev: f64) -> f64 {
    let term: f64 = (elev.abs().cos() - lat.to_radians().sin() * decl.sin())
        / (lat.to_radians().cos() * decl.cos());
    let omega: f64 = term.acos();

    omega.copysign(-elev)
});

fn main() {
    let elev = 2.0;
    let decl = 1.0;
    let foo1 = hour_angle_from_elevation{lat: 0.0, elev, decl}();
    let foo2 = hour_angle_from_elevation(0.0, 1.0, 2.0);
    assert_eq!(foo1,foo2);
}

(playground)

3 Likes