Skip to content

Commit 779044b

Browse files
authored
Merge pull request #60 from mvolfik/patch-1
fix guide about struct/enum impl
2 parents 245feb6 + cae7d0b commit 779044b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

user-guide/type-mapping/extendr-macro.qmd

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,36 @@ error[E0277]: the trait bound `Shape: ToVectorValue` is not satisfied
141141
|
142142
```
143143

144-
However, if an impl block is added to the `Shape` enum, it can be returned to R.
144+
However, you add the `#[extendr]` attribute to the `Shape` enum, it can be returned to R.
145145

146146
```{extendrsrc}
147147
#[derive(Debug)]
148+
#[extendr]
149+
enum Shape {
150+
Triangle,
151+
Rectangle,
152+
Pentagon,
153+
Hexagon,
154+
}
155+
156+
#[extendr]
157+
fn make_shape(shape: &str) -> Shape {
158+
match shape {
159+
"triangle" => Shape::Triangle,
160+
"rectangle" => Shape::Rectangle,
161+
"pentagon" => Shape::Pentagon,
162+
"hexagon" => Shape::Hexagon,
163+
&_ => unimplemented!()
164+
}
165+
}
166+
167+
```
168+
169+
It is also possible to add methods to structs/enums and their instances:
170+
171+
```{extendrsrc}
172+
#[derive(Debug)]
173+
#[extendr]
148174
enum Shape {
149175
Triangle,
150176
Rectangle,

0 commit comments

Comments
 (0)