Rust 程序设计语言 简体中文版 1.85.0
^^^^^^^^^^^^^^ expected `&String`, found `&{integer}` | | | arguments to this method are incorrect | = note: expected reference `&String` found reference 我们可以定义为拥有 参数(parameters)的函数,参数是特殊变量,是函数签名的一部分。 当函数拥有参数(形参)时,可以为这些参数提供具体的值(实参)。技术上讲,这些具体值 被称为参数(arguments),但是在日常交流中,人们倾向于不区分使用 parameter 和 argument 来表示函数定义中的变量或调用函数时传入的具体值。 在这版 another_function 中,我们增加了一个参数: fn new(args: &[String]) -> Config { if args.len() < 3 { panic!("not enough arguments"); } // --snip-- 示例 12-8:增加一个参数数量检查 这类似于示例 9-13 中的 Guess::new 函数,那里如果 value 参数超出了有效值的范围就调用0 码力 | 562 页 | 3.23 MB | 8 天前3
共 1 条
- 1