pub trait Resource:
Send
+ Sync
+ 'static {
Show 16 methods
// Required method
fn name(&self) -> &str;
// Provided methods
fn is_default(&self) -> bool { ... }
fn attribute_names(&self) -> Option<Arc<Vec<String>>> { ... }
fn extends_table(&self) -> Option<&str> { ... }
fn method_overrides(&self) -> MethodOverrides { ... }
fn supports_method(&self, _method: &Method) -> bool { ... }
fn allow_read(&self, ctx: &Context) -> bool { ... }
fn allow_create(&self, ctx: &Context) -> bool { ... }
fn allow_update(&self, ctx: &Context) -> bool { ... }
fn allow_delete(&self, ctx: &Context) -> bool { ... }
fn allow_subscribe(&self, ctx: &Context) -> bool { ... }
fn allow_connect(&self, ctx: &Context) -> bool { ... }
fn is_public_connect(&self) -> bool { ... }
fn handle(&self, _ctx: Context) -> ResourceFuture { ... }
fn subscribe(&self, _ctx: Context) -> SubscriptionFuture { ... }
fn connect(&self, _ctx: Context) -> ConnectionFuture { ... }
}Expand description
The non-verb-dispatch surface of a resource. Read-only metadata (name, routing flags, schema-backed attribute list) plus per-verb permission predicates.
All methods are sync, take &self, and read from a borrowed
Context where they need request state. They never touch the
request body or perform I/O.
Required Methods§
Provided Methods§
Sourcefn is_default(&self) -> bool
fn is_default(&self) -> bool
Whether this resource is a default/catch-all handler.
Sourcefn attribute_names(&self) -> Option<Arc<Vec<String>>>
fn attribute_names(&self) -> Option<Arc<Vec<String>>>
Return the attribute/field names for this resource (if schema-backed).
Sourcefn extends_table(&self) -> Option<&str>
fn extends_table(&self) -> Option<&str>
If this resource extends a table, return the table name.
Sourcefn method_overrides(&self) -> MethodOverrides
fn method_overrides(&self) -> MethodOverrides
Declare which methods this resource overrides (for table extenders).
Default: no overrides. Override this in table extender resources to specify which methods delegate to the custom resource vs. the table.
Sourcefn supports_method(&self, _method: &Method) -> bool
fn supports_method(&self, _method: &Method) -> bool
Whether this resource handles the given HTTP method.
Default: accept all methods (legacy behavior — native Rust resources
match on ctx.method() inside their own Service::call and return 405
themselves for unsupported verbs). WASM resources override this to
fast-reject routes that don’t match their declared methods catalog,
avoiding the dispatch round-trip when the verb isn’t supported.
Sourcefn allow_read(&self, ctx: &Context) -> bool
fn allow_read(&self, ctx: &Context) -> bool
Check if this request is allowed to read.
Sourcefn allow_create(&self, ctx: &Context) -> bool
fn allow_create(&self, ctx: &Context) -> bool
Check if this request is allowed to create.
Sourcefn allow_update(&self, ctx: &Context) -> bool
fn allow_update(&self, ctx: &Context) -> bool
Check if this request is allowed to update.
Sourcefn allow_delete(&self, ctx: &Context) -> bool
fn allow_delete(&self, ctx: &Context) -> bool
Check if this request is allowed to delete.
Sourcefn allow_subscribe(&self, ctx: &Context) -> bool
fn allow_subscribe(&self, ctx: &Context) -> bool
Check if this request is allowed to subscribe.
Sourcefn allow_connect(&self, ctx: &Context) -> bool
fn allow_connect(&self, ctx: &Context) -> bool
Check if this request is allowed to connect (WebSocket/SSE).
Sourcefn is_public_connect(&self) -> bool
fn is_public_connect(&self) -> bool
Whether this resource allows unauthenticated WebSocket/SSE connections.
This is the no-Context equivalent of allow_connect for the public-access
case. The router calls this before constructing a per-request Context so it
can answer “is this a public endpoint?” without a dummy empty-auth Context.
Default: false. Schema-backed resources (TableResource) override this
to reflect the @export(public: [connect]) / @export(public: [read])
directive. Custom resources override it when they intend to allow anonymous
WebSocket connections.
Sourcefn handle(&self, _ctx: Context) -> ResourceFuture
fn handle(&self, _ctx: Context) -> ResourceFuture
Dispatch an HTTP verb request — the single verb-dispatch entry point.
ADR-015 merged the former tower::Service<Context> impl into this
trait: permissions, realtime, and verb dispatch now live on one
Resource. &self (not tower’s &mut self), so the router holds one
Arc<dyn Resource> and never clones a boxed service per request.
Default returns 405 — a metadata-only resource (e.g. a permission-
declaring table extender) inherits it unchanged; resources with verb
bodies (TableResource, WasmResource, macro output) override it.
Sourcefn subscribe(&self, _ctx: Context) -> SubscriptionFuture
fn subscribe(&self, _ctx: Context) -> SubscriptionFuture
Subscribe to real-time updates (SSE handler entrypoint).
Sourcefn connect(&self, _ctx: Context) -> ConnectionFuture
fn connect(&self, _ctx: Context) -> ConnectionFuture
Handle WebSocket or SSE connection.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".