MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / nest

Method nest

crates/bindings/src/http.rs:341–358  ·  view source on GitHub ↗

Causes requests which start with `path` to be processed by `sub_router`. `sub_router` will be used by stripping the leading `path` from the path of the request. Panics if `self` already has any handlers registered on paths which start with `path`. Panics if the `path` is [invalid](Self#paths).

(self, path: impl Into<String>, sub_router: Self)

Source from the content-addressed store, hash-verified

339 ///
340 /// Panics if the `path` is [invalid](Self#paths).
341 pub fn nest(self, path: impl Into<String>, sub_router: Self) -> Self {
342 let path = path.into();
343 assert_valid_path(&path);
344
345 // FIXME: either this check is too restrictive, or the checks in the other methods are too lenient.
346 // Do we want it to be the case that the `sub_router` effectively takes ownership of the whole route below `path`,
347 // or just the routes it actually contains?
348 if self.routes.iter().any(|route| route.path.starts_with(&path)) {
349 panic!("Cannot nest router at `{path}`; existing routes overlap with nested path");
350 }
351
352 let mut merged = self;
353 for route in sub_router.routes {
354 let nested_path = join_paths(&path, &route.path);
355 merged = merged.add_route(route.method, nested_path, route.handler);
356 }
357 merged
358 }
359
360 /// Combines all of the routes in `self` and `other_router` into a single [`Router`].
361 ///

Callers 4

execFunction · 0.45
routerFunction · 0.45
routerFunction · 0.45
into_routerMethod · 0.45

Calls 5

assert_valid_pathFunction · 0.85
join_pathsFunction · 0.85
iterMethod · 0.65
anyMethod · 0.45
add_routeMethod · 0.45

Tested by

no test coverage detected