-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
83 lines (75 loc) · 1.75 KB
/
main.rs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::ops::Deref;
use a::*;
#[derive(Debug, Copy, Clone)]
pub struct Float2 {
pub x: f32,
pub y: f32,
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct SwizzlesExprData {
x: Expr<f32>,
y: Expr<f32>,
}
impl FromNode for SwizzlesExprData {
fn from_node(_node: NodeRef) -> Self {
SwizzlesExprData {
x: Expr::from_node(NodeRef::new()),
y: Expr::from_node(NodeRef::new()),
}
}
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct SwizzlesVarData {
x: Var<f32>,
y: Var<f32>,
}
impl FromNode for SwizzlesVarData {
fn from_node(_node: NodeRef) -> Self {
SwizzlesVarData {
x: Var::from_node(NodeRef::new()),
y: Var::from_node(NodeRef::new()),
}
}
}
impl Value for Float2 {
type ExprData = SwizzlesExprData;
type VarData = SwizzlesVarData;
type Expr = Float2ExprProxy;
type Var = Float2VarProxy;
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct Float2ExprProxy {
node: NodeRef,
pub x: Expr<f32>,
pub y: Expr<f32>,
}
unsafe impl HasExprLayout<SwizzlesExprData> for Float2ExprProxy {}
impl ExprProxy for Float2ExprProxy {
type Value = Float2;
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct Float2VarProxy {
node: NodeRef,
pub x: Var<f32>,
pub y: Var<f32>,
}
unsafe impl HasVarLayout<SwizzlesVarData> for Float2VarProxy {}
impl Deref for Float2VarProxy {
type Target = Expr<Float2>;
fn deref(&self) -> &Self::Target {
Var::<Float2>::from_proxy(self)._deref()
}
}
impl VarProxy for Float2VarProxy {
type Value = Float2;
}
fn main() {
let f = Float2 { x: 1.0, y: 2.0 }.as_expr();
f.x.do_float_thing();
let v = Var::<Float2>::from_node(NodeRef::new());
v.y.do_float_thing();
}