MCPcopy Index your code
hub / github.com/cargo-lambda/cargo-lambda / visit_map

Method visit_map

crates/cargo-lambda-metadata/src/cargo/watch.rs:318–367  ·  view source on GitHub ↗
(self, map: A)

Source from the content-addressed store, hash-verified

316 }
317
318 fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error>
319 where
320 A: serde::de::MapAccess<'de>,
321 {
322 let routes: HashMap<String, FunctionRoutes> =
323 Deserialize::deserialize(serde::de::value::MapAccessDeserializer::new(map))?;
324
325 let mut inner = Router::new();
326 let mut raw = Vec::new();
327
328 let mut inverse = HashMap::new();
329
330 for (path, route) in &routes {
331 inner.insert(path, route.clone()).map_err(|e| {
332 serde::de::Error::custom(format!("Failed to insert route {path}: {e}"))
333 })?;
334
335 match route {
336 FunctionRoutes::Single(function) => {
337 raw.push(Route {
338 path: path.clone(),
339 methods: None,
340 function: function.clone(),
341 });
342 }
343 FunctionRoutes::Multiple(routes) => {
344 for (method, function) in routes {
345 inverse
346 .entry((path.clone(), function.clone()))
347 .and_modify(|route: &mut Route| {
348 let mut methods = route.methods.clone().unwrap_or_default();
349 methods.push(method.clone());
350 route.methods = Some(methods);
351 })
352 .or_insert_with(|| Route {
353 path: path.clone(),
354 methods: Some(vec![method.clone()]),
355 function: function.clone(),
356 });
357 }
358 }
359 }
360 }
361
362 for (_, route) in inverse {
363 raw.push(route);
364 }
365
366 Ok(FunctionRouter { inner, raw })
367 }
368
369 fn visit_seq<A>(self, seq: A) -> Result<Self::Value, A::Error>
370 where

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
insertMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected