我写了以下代码:
use std::io::{IoResult, Writer};
use std::io::stdio;
fn main() {
let h = |&: w: &mut Writer| -> IoResult<()> {
writeln!(w, "foo")
};
let _ = h.handle(&mut stdio::stdout());
}
trait Handler<W> where W: Writer {
fn handle(&self, &mut W) -> IoResult<()>;
}
impl<W, F> Handler<W> for F
where W: Writer, F: Fn(&mut W) -> IoResult<()> {
fn handle(&self, w: &mut W) -> IoResult<()> { (*self)(w) }
}
Run Code Online (Sandbox Code Playgroud)
然后rustc在我的终端:
$ rustc writer_handler.rs
writer_handler.rs:8:15: 8:43 error: the trait `core::marker::Sized` is not …Run Code Online (Sandbox Code Playgroud) 我试图使用以下代码返回向量的值.我收到错误消息.
fn merge<'a>(left: &'a [i32], right: &'a [i32]) -> [i32] {
let mut merged: Vec<i32> = Vec::new();
// push elements to merged
*merged
}
Run Code Online (Sandbox Code Playgroud)
test.rs:19:52:19:57错误:
core::marker::Sized类型[i32]test.rs:19 fn merge <'a>(左:&'a [i32],右:&'a [i32] ) - > [i32] {
我不能为我的生活找到我如何解决这个问题
rust ×2