blob: f93869352ea616fbe5ff47206003bcc284deb12c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// check-pass
use std::sync::Mutex;
use std::cell::RefCell;
use std::rc::Rc;
use std::ops::*;
//eefriedman example
struct S<'a, T:FnMut() + 'static + ?Sized>(&'a mut T);
impl<'a, T:?Sized + FnMut() + 'static> DerefMut for S<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
impl<'a, T:?Sized + FnMut() + 'static> Deref for S<'a, T> {
type Target = dyn FnMut() + 'a;
fn deref(&self) -> &Self::Target { &self.0 }
}
//Ossipal example
struct FunctionIcon {
get_icon: Mutex<Box<dyn FnMut() -> u32>>,
}
impl FunctionIcon {
fn get_icon(&self) -> impl '_ + std::ops::DerefMut<Target=Box<dyn FnMut() -> u32>> {
self.get_icon.lock().unwrap()
}
fn load_icon(&self) {
let mut get_icon = self.get_icon();
let _rgba_icon = (*get_icon)();
}
}
//shepmaster example
struct Foo;
impl Deref for Foo {
type Target = dyn FnMut() + 'static;
fn deref(&self) -> &Self::Target {
unimplemented!()
}
}
impl DerefMut for Foo {
fn deref_mut(&mut self) -> &mut Self::Target {
unimplemented!()
}
}
fn main() {
//eefriedman example
let mut f = ||{};
let mut s = S(&mut f);
s();
//Diggsey/Mark-Simulacrum example
let a: Rc<RefCell<dyn FnMut()>> = Rc::new(RefCell::new(||{}));
a.borrow_mut()();
//shepmaster example
let mut t = Foo;
t();
}
|