mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-20 06:45:36 +01:00
Min codegen
This commit is contained in:
parent
244b085bcb
commit
b1ae562d4f
22 changed files with 129 additions and 1694 deletions
|
|
@ -3,8 +3,8 @@ use syn::{
|
|||
parse::{self, ParseStream},
|
||||
punctuated::Punctuated,
|
||||
spanned::Spanned,
|
||||
Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, PatType, Path,
|
||||
PathArguments, ReturnType, Token, Type, Visibility,
|
||||
Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, Path, PathArguments,
|
||||
ReturnType, Token, Type, Visibility,
|
||||
};
|
||||
|
||||
use crate::syntax::{
|
||||
|
|
@ -231,29 +231,23 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalRes
|
|||
Ok(resources)
|
||||
}
|
||||
|
||||
type ParseInputResult = Option<(Box<Pat>, Result<Vec<PatType>, FnArg>)>;
|
||||
|
||||
pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> ParseInputResult {
|
||||
pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> Option<Box<Pat>> {
|
||||
let mut inputs = inputs.into_iter();
|
||||
|
||||
match inputs.next() {
|
||||
Some(FnArg::Typed(first)) => {
|
||||
if type_is_path(&first.ty, &[name, "Context"]) {
|
||||
let rest = inputs
|
||||
.map(|arg| match arg {
|
||||
FnArg::Typed(arg) => Ok(arg),
|
||||
_ => Err(arg),
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>();
|
||||
|
||||
Some((first.pat, rest))
|
||||
} else {
|
||||
None
|
||||
// No more inputs
|
||||
if inputs.next().is_none() {
|
||||
return Some(first.pat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => None,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn type_is_bottom(ty: &ReturnType) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue