Skip to main content

CommandExtension

Trait CommandExtension 

Source
pub trait CommandExtension:
    Send
    + Sync
    + Debug {
    // Required methods
    fn handles_msg_type(&self, ty: MsgType) -> bool;
    fn try_dispatch(&self, args: &[&[u8]]) -> Option<Vec<u8>>;

    // Provided method
    fn try_intercept_hset(&self, _args: &[&[u8]]) -> HsetOutcome { ... }
}
Expand description

Pluggable command-dispatch hook.

Implementors short-circuit dispatcher routing for the command families they own; everything else falls through to the standard substrate. See the module-level docs for the lifecycle and the standard-library hook used by dynomite-search.

Required Methods§

Source

fn handles_msg_type(&self, ty: MsgType) -> bool

True when the parsed MsgType is one this extension wants to dispatch. The dispatcher only invokes Self::try_dispatch when this returns true.

Source

fn try_dispatch(&self, args: &[&[u8]]) -> Option<Vec<u8>>

Try to dispatch a command. args is the parsed RESP argument vector starting with the command keyword (e.g. [b"FT.SEARCH", b"idx", ...]).

Returns Some(resp_bytes) when the extension produced a complete RESP reply for the client; None to fall through to the standard dispatch path. The dispatcher only consults this method after Self::handles_msg_type returns true, so a well-behaved implementation may safely assume the command keyword is one of the families it advertised.

Provided Methods§

Source

fn try_intercept_hset(&self, _args: &[&[u8]]) -> HsetOutcome

Inspect an HSET argument list and, if it matches a registered prefix / shape, perform any side-effects the extension wants. args is [key, f1, v1, f2, v2, ...] (without the leading HSET keyword).

See HsetOutcome for the response shape. The default impl returns HsetOutcome::NotIndexed so trait implementors that do not care about HSET interception only need to implement Self::try_dispatch.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§