Crates.io | named_return |
lib.rs | named_return |
version | 0.1.1 |
source | src |
created_at | 2019-04-12 14:54:17.266493 |
updated_at | 2019-04-13 13:08:05.468858 |
description | Derives a wrapper function which insert the named return variables. |
homepage | |
repository | https://github.com/swfsql/named_return |
max_upload_size | |
id | 127471 |
size | 22,444 |
Declares a proc-macro that enables return types to be named.
Mostly re-defining structures from syn
for parsing.
The macro also:
#![feature(proc_macro_hygiene)]
use named_return::named_return;
#
# #[derive(Debug, PartialEq, Eq)]
# pub struct A;
# #[derive(Debug, PartialEq, Eq)]
# pub struct B;
named_return!(
fn f() -> (a: A, b: B) {
a = A;
b = B;
(a, b)
});
assert_eq!(f(), (A, B));
The intended syntax were to be used with a proc-macro-attr, such as:
#[named_return]
fn f() -> (a: A, b: B) {
a = A;
b = B;
(a, b)
}
But it seems that Rust parses the original function syntax before executing the proc-macro-attr and so it refuses the invalid syntax.
This is a draft and is based on this suggestion: https://github.com/rust-lang/rfcs/issues/2638