MCPcopy Create free account
hub / github.com/Wulf/tsync / check_expression_is_path

Function check_expression_is_path

src/utils.rs:44–49  ·  view source on GitHub ↗

Ensures that a parsed expression is a valid Rust module-like path and the path contains valid segments. # Example ```rust let expression: syn::Result = syn::parse_str("std::mem::replace"); assert!(expression.is_ok()); let exp_path = expression.unwrap(); let is_path = match exp_path { syn::Expr::Path(path_expression) if !path_expression.path.segments.is_empty() => Some(path_expression),

(expr: Expr)

Source from the content-addressed store, hash-verified

42/// assert_eq!(path.path.segments.len(), 3);
43/// ```
44fn check_expression_is_path(expr: Expr) -> Option<ExprPath> {
45 match expr {
46 Expr::Path(expr_path) if !expr_path.path.segments.is_empty() => Some(expr_path),
47 _ => None,
48 }
49}
50
51fn check_token(token: proc_macro2::TokenTree, arg: &str) -> Option<String> {
52 // this detects the '(...)' part in #[serde(rename_all = "UPPERCASE", tag = "type")]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected