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