encodable.rs for more.
*/
+use ast;
use ast::{MetaItem, Item, Expr, MutMutable, Ident};
use codemap::Span;
use ext::base::ExtCtxt;
span: span,
attributes: Vec::new(),
path: Path::new_(vec!("serialize", "Decodable"), None,
- vec!(~Literal(Path::new_local("__D"))), true),
+ vec!(~Literal(Path::new_local("__D")),
+ ~Literal(Path::new_local("__E"))), true),
additional_bounds: Vec::new(),
generics: LifetimeBounds {
lifetimes: Vec::new(),
- bounds: vec!(("__D", vec!(Path::new(vec!("serialize", "Decoder"))))),
+ bounds: vec!(("__D", ast::StaticSize, vec!(Path::new_(
+ vec!("serialize", "Decoder"), None,
+ vec!(~Literal(Path::new_local("__E"))), true))),
+ ("__E", ast::StaticSize, vec!()))
},
methods: vec!(
MethodDef {
explicit_self: None,
args: vec!(Ptr(~Literal(Path::new_local("__D")),
Borrowed(None, MutMutable))),
- ret_ty: Self,
- inline: false,
+ ret_ty: Literal(Path::new_(vec!("std", "result", "Result"), None,
+ vec!(~Self, ~Literal(Path::new_local("__E"))), true)),
+ attributes: Vec::new(),
const_nonmatching: true,
- combine_substructure: decodable_substructure,
+ combine_substructure: combine_substructure(|a, b, c| {
+ decodable_substructure(a, b, c)
+ }),
})
};
substr.type_ident,
summary,
|cx, span, name, field| {
- cx.expr_method_call(span, blkdecoder, read_struct_field,
- vec!(cx.expr_str(span, name),
- cx.expr_uint(span, field),
- lambdadecode))
+ cx.expr_try(span,
+ cx.expr_method_call(span, blkdecoder, read_struct_field,
+ vec!(cx.expr_str(span, name),
+ cx.expr_uint(span, field),
+ lambdadecode)))
});
+ let result = cx.expr_ok(trait_span, result);
cx.expr_method_call(trait_span,
decoder,
cx.ident_of("read_struct"),
parts,
|cx, span, _, field| {
let idx = cx.expr_uint(span, field);
- cx.expr_method_call(span, blkdecoder, rvariant_arg,
- vec!(idx, lambdadecode))
+ cx.expr_try(span,
+ cx.expr_method_call(span, blkdecoder, rvariant_arg,
+ vec!(idx, lambdadecode)))
});
arms.push(cx.arm(v_span,
arms.push(cx.arm_unreachable(trait_span));
- let result = cx.expr_match(trait_span, cx.expr_ident(trait_span, variant), arms);
+ let result = cx.expr_ok(trait_span,
+ cx.expr_match(trait_span,
+ cx.expr_ident(trait_span, variant), arms));
let lambda = cx.lambda_expr(trait_span, vec!(blkarg, variant), result);
let variant_vec = cx.expr_vec(trait_span, variants);
let result = cx.expr_method_call(trait_span, blkdecoder,