pub struct ScriptRouter { /* private fields */ }Expand description
A script-based router.
Maps URL patterns to Rhai script handlers.
Implementations§
Source§impl ScriptRouter
impl ScriptRouter
Sourcepub fn new(engine: RhaiEngine) -> Self
pub fn new(engine: RhaiEngine) -> Self
Create a new script router.
Sourcepub fn with_engine(engine: Arc<RhaiEngine>) -> Self
pub fn with_engine(engine: Arc<RhaiEngine>) -> Self
Create a new script router with a shared engine.
Sourcepub fn route(
self,
pattern: impl Into<String>,
script: impl Into<PathBuf>,
) -> Self
pub fn route( self, pattern: impl Into<String>, script: impl Into<PathBuf>, ) -> Self
Add a route for any HTTP method.
Sourcepub fn get(self, pattern: impl Into<String>, script: impl Into<PathBuf>) -> Self
pub fn get(self, pattern: impl Into<String>, script: impl Into<PathBuf>) -> Self
Add a GET route.
Sourcepub fn post(
self,
pattern: impl Into<String>,
script: impl Into<PathBuf>,
) -> Self
pub fn post( self, pattern: impl Into<String>, script: impl Into<PathBuf>, ) -> Self
Add a POST route.
Sourcepub fn put(self, pattern: impl Into<String>, script: impl Into<PathBuf>) -> Self
pub fn put(self, pattern: impl Into<String>, script: impl Into<PathBuf>) -> Self
Add a PUT route.
Sourcepub fn delete(
self,
pattern: impl Into<String>,
script: impl Into<PathBuf>,
) -> Self
pub fn delete( self, pattern: impl Into<String>, script: impl Into<PathBuf>, ) -> Self
Add a DELETE route.
Sourcepub fn patch(
self,
pattern: impl Into<String>,
script: impl Into<PathBuf>,
) -> Self
pub fn patch( self, pattern: impl Into<String>, script: impl Into<PathBuf>, ) -> Self
Add a PATCH route.
Sourcepub fn before(self, script: impl Into<PathBuf>) -> Self
pub fn before(self, script: impl Into<PathBuf>) -> Self
Add middleware that runs before handlers.
Sourcepub fn after(self, script: impl Into<PathBuf>) -> Self
pub fn after(self, script: impl Into<PathBuf>) -> Self
Add middleware that runs after handlers.
Sourcepub fn not_found(self, script: impl Into<PathBuf>) -> Self
pub fn not_found(self, script: impl Into<PathBuf>) -> Self
Set the 404 Not Found handler script.
Sourcepub fn error_handler(self, script: impl Into<PathBuf>) -> Self
pub fn error_handler(self, script: impl Into<PathBuf>) -> Self
Set the error handler script.
Sourcepub async fn handle(&self, request: HttpRequest) -> HttpResponse
pub async fn handle(&self, request: HttpRequest) -> HttpResponse
Handle a request.
Sourcepub fn engine(&self) -> &RhaiEngine
pub fn engine(&self) -> &RhaiEngine
Get the engine.
Sourcepub async fn precompile(&self) -> Result<()>
pub async fn precompile(&self) -> Result<()>
Precompile all route scripts.
Auto Trait Implementations§
impl Freeze for ScriptRouter
impl !RefUnwindSafe for ScriptRouter
impl Send for ScriptRouter
impl Sync for ScriptRouter
impl Unpin for ScriptRouter
impl !UnwindSafe for ScriptRouter
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> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging