似乎Rust编译器对where
子句有不同的行为.
mod sub {
use std::mem;
static mut FF : *const Foo = &NopFoo;
pub trait Foo: Send + Sync {
fn foo(&self);
}
pub struct NopFoo;
impl Foo for NopFoo {
fn foo(&self) { println!("Nop"); }
}
pub struct HelloFoo {
pub num: i64,
}
impl Foo for HelloFoo {
fn foo(&self) { println!("Hello, {}", self.num ); }
}
pub fn set_ff<M>(make_foo: M) -> bool
where M: FnOnce() -> Box<Foo> // <== Here
{
unsafe {
FF …
Run Code Online (Sandbox Code Playgroud) rust ×1