【发布时间】:2018-10-28 14:44:30
【问题描述】:
此函数适用于类型i32,但适用于类型str:
fn getValues() -> [str; 2] {
[
"37107287533902102798797998220837590246510135740250",
"46376937677490009712648124896970078050417018260538",
]
}
我得到错误:
error[E0277]: the size for values of type `str` cannot be known at compilation time --> src/lib.rs:1:1 | 1 | / fn getValues() -> [str; 2] { 2 | | [ 3 | | "37107287533902102798797998220837590246510135740250", 4 | | "46376937677490009712648124896970078050417018260538", 5 | | ] 6 | | } | |_^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `str` = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait> = note: slice and array elements must have `Sized` type
这个错误让我觉得我需要添加大小,但我做了:大小为 2。Rust 想要什么?
【问题讨论】: