Skip to main content

Resource

Trait Resource 

Source
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§

Source

fn name(&self) -> &str

Resource name (used in routing).

Provided Methods§

Source

fn is_default(&self) -> bool

Whether this resource is a default/catch-all handler.

Source

fn attribute_names(&self) -> Option<Arc<Vec<String>>>

Return the attribute/field names for this resource (if schema-backed).

Source

fn extends_table(&self) -> Option<&str>

If this resource extends a table, return the table name.

Source

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.

Source

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.

Source

fn allow_read(&self, ctx: &Context) -> bool

Check if this request is allowed to read.

Source

fn allow_create(&self, ctx: &Context) -> bool

Check if this request is allowed to create.

Source

fn allow_update(&self, ctx: &Context) -> bool

Check if this request is allowed to update.

Source

fn allow_delete(&self, ctx: &Context) -> bool

Check if this request is allowed to delete.

Source

fn allow_subscribe(&self, ctx: &Context) -> bool

Check if this request is allowed to subscribe.

Source

fn allow_connect(&self, ctx: &Context) -> bool

Check if this request is allowed to connect (WebSocket/SSE).

Source

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.

Source

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.

Source

fn subscribe(&self, _ctx: Context) -> SubscriptionFuture

Subscribe to real-time updates (SSE handler entrypoint).

Source

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".

Implementors§