【发布时间】:2015-01-27 16:41:52
【问题描述】:
我正在尝试返回向量的值:
fn merge<'a>(left: &'a [i32], right: &'a [i32]) -> [i32] {
let mut merged: Vec<i32> = Vec::new();
// push elements to merged
*merged
}
我收到错误消息:
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
--> src/lib.rs:1:52
|
1 | fn merge<'a>(left: &'a [i32], right: &'a [i32]) -> [i32] {
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `[i32]`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: the return type of a function must have a statically known size
我不知道如何解决这个问题。
【问题讨论】:
标签: rust