IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Named parameters in Rust

    金庆发表于 2021-11-18 05:14:00
    love 0

    Named parameters in Rust

    (Jin Qing's Column, Nov. 18, 2021)

    There is no "named function parameters" in Rust, but there is an idiom for this case. If a function needs many parameters, we can define a type with all these parameters as fields, and implement Default trait for this type. Then we can input this type as the function parameter, with some of the fields specified and others using default.

    foo(Config {
        a: 123,
        b: bool,
        ...Default::default(),
    });
    


    金庆 2021-11-18 13:14 发表评论


沪ICP备19023445号-2号
友情链接