| 116 | return self |
| 117 | |
| 118 | def to_rust(self): |
| 119 | decl = super().to_rust() |
| 120 | |
| 121 | for t1, t2 in [(self.type.c_name, self.type.orig_name), (self.type.orig_name, self.type.c_name)]: |
| 122 | start = s(f'''\ |
| 123 | impl Into<{t2}> for {t1} {{ |
| 124 | fn into(self) -> {t2} {{ |
| 125 | match self {{ |
| 126 | ''') |
| 127 | |
| 128 | body = '' |
| 129 | for variant,_ in self.variants: |
| 130 | body += f'{t1}::{variant} => {t2}::{variant},\n' |
| 131 | body += f'_ => {t2}::{self.variants[0][0]},\n' |
| 132 | |
| 133 | |
| 134 | end = s(f'''\ |
| 135 | }} |
| 136 | }} |
| 137 | }} |
| 138 | ''') |
| 139 | |
| 140 | decl += start + s(body, indent=12) + end |
| 141 | |
| 142 | methods = '\n'.join(m.to_rust() for m in self.methods) |
| 143 | |
| 144 | return decl + methods |
| 145 | |
| 146 | def to_c(self): |
| 147 | methods = '\n'.join(m.to_c() for m in self.methods) |