MCPcopy Create free account
hub / github.com/dxx/feignhttp / parse_url

Function parse_url

codegen/src/util.rs:58–85  ·  view source on GitHub ↗

Parse and validate the url.

(url_expr: &syn::Expr)

Source from the content-addressed store, hash-verified

56
57/// Parse and validate the url.
58pub fn parse_url(url_expr: &syn::Expr) -> syn::Result<proc_macro2::TokenStream> {
59 return match url_expr {
60 // An assignment url: url = xxx.
61 syn::Expr::Assign(assign) => {
62 let left = &assign.left;
63 if let syn::Expr::Path(ref k) = **left {
64 let key = k.path.segments.last().unwrap().ident.to_string();
65 if key != "url" {
66 return Err(syn::Error::new(
67 proc_macro2::Span::call_site(),
68 "metadata url not specified",
69 ));
70 }
71 }
72 let right = &assign.right;
73 Ok(right.to_token_stream())
74 }
75 // A literal url: `"http://xxx"`.
76 syn::Expr::Lit(lit) => Ok(lit.to_token_stream()),
77 // A variable url: URL.
78 syn::Expr::Path(path) => Ok(path.to_token_stream()),
79 syn::Expr::Field(field) => Ok(field.to_token_stream()),
80 _ => Err(syn::Error::new(
81 proc_macro2::Span::call_site(),
82 "metadata url is invalid",
83 )),
84 };
85}
86
87pub fn remove_url_attr(attr: &str) -> String {
88 let attrs = attr.split(",");

Callers 1

parse_url_streamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected