pub struct IpcRouter { /* private fields */ }Expand description
HTTP-like IPC Router
Routes incoming IPC requests to appropriate handlers based on URL patterns. Supports static paths, path parameters, query strings, and multiple body formats.
Implementations§
Source§impl IpcRouter
impl IpcRouter
Sourcepub fn builder() -> IpcRouterBuilder
pub fn builder() -> IpcRouterBuilder
Create a new router builder
Sourcepub fn register(
&mut self,
method: &str,
pattern: &str,
handler: Box<dyn RouteHandler>,
)
pub fn register( &mut self, method: &str, pattern: &str, handler: Box<dyn RouteHandler>, )
Registers a new route handler
§Arguments
method- HTTP method (informational, e.g., “GET”, “POST”)pattern- URL pattern with optional parameters (e.g., “/user/:id”)handler- Boxed handler implementing RouteHandler trait
§Example
ⓘ
router.register("POST", "/form/submit", Box::new(FormSubmitHandler));
router.register("GET", "/user/:id", Box::new(GetUserHandler));Sourcepub fn dispatch(&self, raw_request: &Value) -> IpcResponse
pub fn dispatch(&self, raw_request: &Value) -> IpcResponse
Sourcepub fn list_routes(&self) -> Vec<(String, String)>
pub fn list_routes(&self) -> Vec<(String, String)>
Returns a list of all registered routes
Useful for debugging and introspection.
Sourcepub fn start(&self)
pub fn start(&self)
Start the IPC message handler loop
This method sets up the eval channel and automatically handles incoming IPC requests, dispatching them to registered routes and sending responses back.
§Example
ⓘ
use dioxus::prelude::*;
use dioxus_ipc_bridge::prelude::*;
fn app() -> Element {
let router = use_signal(|| {
let mut r = IpcRouter::new();
r.register("POST", "/greeting", Box::new(GreetingHandler));
r
});
use_effect(move || {
router.read().start();
});
rsx! { /* ... */ }
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for IpcRouter
impl !RefUnwindSafe for IpcRouter
impl Send for IpcRouter
impl Sync for IpcRouter
impl Unpin for IpcRouter
impl UnsafeUnpin for IpcRouter
impl !UnwindSafe for IpcRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.