/*!
-The compiler code necessary to implement the #[deriving(Encodable)]
-(and Decodable, in decodable.rs) extension. The idea here is that
-type-defining items may be tagged with #[deriving(Encodable,
-Decodable)].
+The compiler code necessary to implement the `#[deriving(Encodable)]`
+(and `Decodable`, in decodable.rs) extension. The idea here is that
+type-defining items may be tagged with `#[deriving(Encodable, Decodable)]`.
For example, a type like:
```ignore
- #[deriving(Encodable, Decodable)]
- struct Node {id: uint}
+#[deriving(Encodable, Decodable)]
+struct Node { id: uint }
```
would generate two implementations like:
+```ignore
impl<S:serialize::Encoder> Encodable<S> for Node {
fn encode(&self, s: &S) {
s.emit_struct("Node", 1, || {
})
}
}
+```
Other interesting scenarios are whe the item has type parameters or
references other non-built-in types. A type definition like:
```ignore
- #[deriving(Encodable, Decodable)]
- struct spanned<T> {node: T, span: Span}
+#[deriving(Encodable, Decodable)]
+struct spanned<T> { node: T, span: Span }
```
would yield functions like:
variants, as well as creating the method and impl ast instances.
Supported features (fairly exhaustive):
+
- Methods taking any number of parameters of any type, and returning
any type, other than vectors, bottom and closures.
- Generating `impl`s for types with type parameters and lifetimes
an identifier in the source code. For example, the `x`s in the
following snippet
-~~~notrust
+```rust
struct A { x : int }
struct B(int);
C0(int),
C1 { x: int }
}
-~~~
+```
The `int`s in `B` and `C0` don't have an identifier, so the
`Option<ident>`s would be `None` for them.
The following simplified `Eq` is used for in-code examples:
-~~~notrust
+```rust
trait Eq {
fn eq(&self, other: &Self);
}
*self == *other
}
}
-~~~
+```
Some examples of the values of `SubstructureFields` follow, using the
above `Eq`, `A`, `B` and `C`.
// except according to those terms.
/*!
-The compiler code necessary to implement the #[deriving] extensions.
+The compiler code necessary to implement the `#[deriving]` extensions.
-FIXME (#2810)--Hygiene. Search for "__" strings (in other files too).
+FIXME (#2810): hygiene. Search for "__" strings (in other files too).
We also assume "extra" is the standard library, and "std" is the core
library.