I don't understand why the code below does not compile. It seems like rust is just not 'expanding' the type parameter, since it looks like it matches to me.
Code (rust playpen: http://is.gd/gC82I4)
use std::sync::{Arc, Mutex};
struct Data{
func: Option<Box<FnMut(String) + Send>>
}
fn newData<F>(func: Option<Box<F>>) -> Data
where F: FnMut(String) + Send{
Data{
func: func
}
}
fn main(){
let _ = newData(Some(Box::new(|msg|{})));
}
Error
<anon>:10:15: 10:19 error: mismatched types:
expected `core::option::Option<Box<core::ops::FnMut(collections::string::String) + Send>>`,
found `core::option::Option<Box<F>>`
(expected trait core::ops::FnMut,
found type parameter) [E0308]
<anon>:10 func: func
^~~~
error: aborting due to previous error
playpen: application terminated with error code 101
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…