Allow returning Result from functions

This commit adds support for exporting a function defined in Rust that returns a
`Result`, translating the `Ok` variant to the actual return value and the `Err`
variant to an exception that's thrown in JS.

The support for return types and descriptors was rejiggered a bit to be a bit
more abstract and more well suited for this purpose. We no longer distinguish
between functions with a return value and those without a return value.
Additionally a new trait, `ReturnWasmAbi`, is used for converting return values.
This trait is an internal implementation detail, however, and shouldn't surface
itself to users much (if at all).

Closes #841
This commit is contained in:
Alex Crichton
2018-09-17 18:26:45 -07:00
parent ccced83b0e
commit 7cf4213283
17 changed files with 292 additions and 266 deletions

View File

@ -726,13 +726,14 @@ impl<'a> MacroParse<(Option<BindgenAttrs>, &'a mut TokenStream)> for syn::Item {
}
let comments = extract_doc_comments(&f.attrs);
f.to_tokens(tokens);
let opts = opts.unwrap_or_default();
program.exports.push(ast::Export {
class: None,
method_self: None,
constructor: None,
comments,
rust_name: f.ident.clone(),
function: f.convert(opts.unwrap_or_default())?,
function: f.convert(opts)?,
});
}
syn::Item::Struct(mut s) => {