(expr: &syn::Expr)
| 299 | } |
| 300 | |
| 301 | pub fn expr_to_python(expr: &syn::Expr) -> String { |
| 302 | match expr { |
| 303 | // literal values |
| 304 | syn::Expr::Lit(syn::ExprLit { lit, .. }) => match lit { |
| 305 | syn::Lit::Str(s) => s.token().to_string(), |
| 306 | syn::Lit::Char(c) => c.token().to_string(), |
| 307 | syn::Lit::Int(i) => i.base10_digits().to_string(), |
| 308 | syn::Lit::Float(f) => f.base10_digits().to_string(), |
| 309 | syn::Lit::Bool(b) => { |
| 310 | if b.value() { |
| 311 | "True".to_string() |
| 312 | } else { |
| 313 | "False".to_string() |
| 314 | } |
| 315 | } |
| 316 | _ => "...".to_string(), |
| 317 | }, |
| 318 | // None |
| 319 | syn::Expr::Path(syn::ExprPath { qself, path, .. }) |
| 320 | if qself.is_none() && path.is_ident("None") => |
| 321 | { |
| 322 | "None".to_string() |
| 323 | } |
| 324 | // others, unsupported yet so defaults to `...` |
| 325 | _ => "...".to_string(), |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /// Helper struct for hard-coded identifiers used in the macro code. |
| 330 | #[derive(Clone, Copy)] |
no test coverage detected