Skip to main content

InMemoryBridge

Trait InMemoryBridge 

Source
pub trait InMemoryBridge: Send + Sync {
    // Required method
    fn dispatch_command(
        &self,
        method: &str,
        params: Value,
        session_id: Option<&str>,
    ) -> InMemoryBridgeResponse;
}
Expand description

InMemory 桥接 trait — 抽象 servo ScriptThread 调用。

TASK-2 用 MockInMemoryBridge 单元测试;TASK-3 用真实 servo CDPRdpBridge 实现该 trait(内部通过 servo DevtoolScriptControlMsg 等 IPC 通信)。

§设计要点

  • Send + Sync:可被 Arc 包装跨线程共享(虽然 servo ScriptThread !Send, bridge 内部用 channel 转换为 Send-safe 边界)
  • 单一方法 dispatch_command 返回 InMemoryBridgeResponse, InMemoryTransport 负责把 channel 推送的事件拼装成 CdpEvent

@trace REQ-BAO-API-002 [interface:Transport]

Required Methods§

Source

fn dispatch_command( &self, method: &str, params: Value, session_id: Option<&str>, ) -> InMemoryBridgeResponse

派发 CDP 命令到 servo,同步返回响应。

实现要点(TASK-3):

  1. 通过 servo ScriptThread sender 把命令转为 DevtoolScriptControlMsg
  2. 在 servo actor 内执行(A 类机械映射 / B 类 Eval 合成)
  3. 通过响应 channel 返回 InMemoryBridgeResponse

实现要点(测试 mock):直接返回预设响应。

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§