pub struct ResourceRoutes {
pub index: Option<MethodRouter>,
pub create: Option<MethodRouter>,
pub store: Option<MethodRouter>,
pub show: Option<MethodRouter>,
pub edit: Option<MethodRouter>,
pub update: Option<MethodRouter>,
pub destroy: Option<MethodRouter>,
}Expand description
RESTful 资源路由的 7 个标准 handler(每个可选)
借鉴 Rails resources :users + Laravel Route::resource,一行注册
全部标准 RESTful 路由。
§标准路由映射
| Method | Path | Handler | 说明 |
|---|---|---|---|
| GET | /{name} | index | 列表 |
| GET | /{name}/create | create | 新建表单(PHP 风格) |
| POST | /{name} | store | 保存 |
| GET | /{name}/{id} | show | 详情 |
| GET | /{name}/{id}/edit | edit | 编辑表单 |
| PUT | /{name}/{id} | update | 更新 |
| DELETE | /{name}/{id} | destroy | 删除 |
§用法
ⓘ
use sz_rust_router_facade::router::{resource, ResourceRoutes};
use axum::routing::{get, post, put, delete};
let routes = ResourceRoutes {
index: Some(get(|| async { "list" })),
show: Some(get(|| async { "show" })),
store: Some(post(|| async { "create" })),
update: Some(put(|| async { "update" })),
destroy: Some(delete(|| async { "delete" })),
..Default::default()
};
let router = resource("users", routes);Fields§
§index: Option<MethodRouter>GET /{name} — 列表
create: Option<MethodRouter>GET /{name}/create — 新建表单
store: Option<MethodRouter>POST /{name} — 保存
show: Option<MethodRouter>GET /{name}/{id} — 详情
edit: Option<MethodRouter>GET /{name}/{id}/edit — 编辑表单
update: Option<MethodRouter>PUT /{name}/{id} — 更新
destroy: Option<MethodRouter>DELETE /{name}/{id} — 删除
Implementations§
Source§impl ResourceRoutes
impl ResourceRoutes
Sourcepub fn new() -> ResourceRoutes
pub fn new() -> ResourceRoutes
创建空 routes(所有 handler 都为 None)
Trait Implementations§
Source§impl Default for ResourceRoutes
impl Default for ResourceRoutes
Source§fn default() -> ResourceRoutes
fn default() -> ResourceRoutes
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for ResourceRoutes
impl !UnwindSafe for ResourceRoutes
impl Freeze for ResourceRoutes
impl Send for ResourceRoutes
impl Sync for ResourceRoutes
impl Unpin for ResourceRoutes
impl UnsafeUnpin for ResourceRoutes
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.