skima/
ext.rs

1use castaway::cast;
2
3use crate::dont_panic;
4
5struct Context<E> {
6	ext: E,
7}
8
9impl<T: 'static, A: 'static> AsRef<T> for Context<(A,)> {
10	fn as_ref(&self) -> &T {
11		if let Ok(t) = cast!(&self.ext.0, &T) {
12			return t;
13		}
14
15		dont_panic!()
16	}
17}
18
19impl<T: 'static, A: 'static, B: 'static> AsRef<T> for Context<(A, B)> {
20	fn as_ref(&self) -> &T {
21		if let Ok(t) = cast!(&self.ext.0, &T) {
22			return t;
23		} else if let Ok(t) = cast!(&self.ext.1, &T) {
24			return t;
25		}
26
27		dont_panic!()
28	}
29}
30
31struct Arena {}
32
33impl<E> Context<E> {
34	fn arena(&self)
35	where
36		Self: AsRef<Arena>,
37	{
38		let a: &Arena = self.as_ref();
39	}
40}
41
42fn test(cx: Context<(Arena,)>) {
43	cx.arena()
44}