Skip to content

Commit 78acafe

Browse files
authored
Merge pull request #328 from rust-lang/fix-example
Fix function like example
2 parents d591618 + a5fbc1e commit 78acafe

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

posts/2018-10-25-Rust-1.30.0.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,30 @@ thing the attribute is attached to, in this case, `fn index() {}` and the rest
7373
of the function's body.
7474

7575
Function-like macros define macros that look like function calls. For
76-
example, an `sql!` macro:
76+
example, the [`gnome-class` crate](https://gitlab.gnome.org/federico/gnome-class)
77+
has a procedural macro that defines `GObject` classes in Rust:
7778

7879
```rust
79-
let sql = sql!(SELECT * FROM posts WHERE id=1);
80+
gobject_gen!(
81+
class MyClass: GObject {
82+
foo: Cell<i32>,
83+
bar: RefCell<String>,
84+
}
85+
86+
impl MyClass {
87+
virtual fn my_virtual_method(&self, x: i32) {
88+
// ... do something with x ...
89+
}
90+
}
91+
)
8092
```
8193

82-
This macro would parse the SQL statement inside of it and check that it's
83-
syntactically correct. This macro would be defined like this:
94+
This looks like a function that is taking a bunch of code as an argument.
95+
This macro would be defined like this:
8496

8597
```
8698
#[proc_macro]
87-
pub fn sql(input: TokenStream) -> TokenStream {
99+
pub fn gobject_gen(input: TokenStream) -> TokenStream {
88100
```
89101

90102
This is similar to the derive macro's signature: we get the tokens that

0 commit comments

Comments
 (0)