fn fold_expr(expr: &syn::Expr) -> Option<u128> {
    match expr {
        Expr::Lit(ref expr_lit) => match expr_lit.lit {
            syn::Lit::Int(ref lit_int) => lit_int.base10_parse().ok(),
            _ => None,
        },
        Expr::Binary(ref expr_binary) => {
            let l = fold_expr(&expr_binary.left)?;
            let r = fold_expr(&expr_binary.right)?;
            match &expr_binary.op {
                syn::BinOp::Shl(_) => u32::try_from(r).ok().and_then(|r| l.checked_shl(r)),
                _ => None,
            }
        }
        Expr::Paren(syn::ExprParen { expr, .. }) | Expr::Group(syn::ExprGroup { expr, .. }) => {
            fold_expr(&expr)
        }
        _ => None,
    }
}
/// Try to evaluate the expression given.
Try to evaluate the expression given.
Try to evaluate the expression given .
fn fold_expr(expr: &syn::Expr) -> Option<u128> {
    match expr {
        Expr::Lit(ref expr_lit) => match expr_lit.lit {
            syn::Lit::Int(ref lit_int) => lit_int.base10_parse().ok(),
            _ => None,
        },
        Expr::Binary(ref expr_binary) => {
            let l = fold_expr(&expr_binary.left)?;
            let r = fold_expr(&expr_binary.right)?;
            match &expr_binary.op {
                syn::BinOp::Shl(_) => u32::try_from(r).ok().and_then(|r| l.checked_shl(r)),
                _ => None,
            }
        }
        Expr::Paren(syn::ExprParen { expr, .. }) | Expr::Group(syn::ExprGroup { expr, .. }) => {
            fold_expr(&expr)
        }
        _ => None,
    }
}
fn fold_expr ( expr : & syn :: Expr ) -> Option < u128 > { match expr { Expr :: Lit ( ref expr_lit ) => match expr_lit . lit { syn :: Lit :: Int ( ref lit_int ) => lit_int . base10_parse ( ) . ok ( ) , _ => None , } , Expr :: Binary ( ref expr_binary ) => { let l = fold_expr ( & expr_binary . left ) ? ; let r = fold_expr ( & expr_binary . right ) ? ; match & expr_binary . op { syn :: BinOp :: Shl ( _ ) => u32 :: try_from ( r ) . ok ( ) . and_then ( | r | l . checked_shl ( r ) ) , _ => None , } } Expr :: Paren ( syn :: ExprParen { expr , .. } ) | Expr :: Group ( syn :: ExprGroup { expr , .. } ) => { fold_expr ( & expr ) } _ => None , } }
Try to evaluate the expression given.
Try to evaluate the expression given .
expr
&syn::Expr
expr
&syn::Expr