Skip to main content

Message

Enum Message 

Source
pub enum Message {
    Hello {
        protocol: u64,
        sdk: String,
        commands: Vec<String>,
    },
    Ready {
        protocol: u64,
        app: AppInfo,
    },
    Shutdown {
        timeout_ms: u64,
    },
    Request {
        id: u64,
        cmd: String,
        channels: BTreeMap<String, u64>,
        window: Option<String>,
        payload: Inline,
    },
    Response {
        id: u64,
        payload: Inline,
    },
    Error {
        id: u64,
        code: Option<String>,
        message: Option<String>,
        data: Option<Value>,
    },
    Cancel {
        id: u64,
        reason: String,
    },
    Event {
        event: String,
        target: Option<String>,
        window: Option<String>,
        payload: Inline,
    },
    ChannelData {
        channel: u64,
        payload: Inline,
    },
    ChannelClose {
        channel: u64,
    },
}
Expand description

帧头,即以 type 字段区分的 JSON 对象。

字段声明顺序即线上顺序,与 Python 模型一致(golden frames 依赖于此);反序列化时忽略未知字段。

Variants§

§

Hello

Python → Rust:握手首帧,声明协议版本、SDK 版本与已注册的命令。

Fields

§protocol: u64
§commands: Vec<String>
§

Ready

Rust → Python:确认握手,Python 收到后执行 ready 钩子。

Fields

§protocol: u64
§

Shutdown

Rust → Python:请求退出,timeoutMs 是 Python 取消调用并执行 shutdown 钩子的总预算。

Fields

§timeout_ms: u64
§

Request

Rust → Python:命令调用请求。

Fields

§id: u64

Rust 侧分配的调用 id,在单个 crate::bridge::Bridge 内唯一。

§channels: BTreeMap<String, u64>

参数名 → channel id。

§window: Option<String>

发起调用的 webview 标签。

§payload: Inline
§

Response

Python → Rust:调用成功的结果。

Fields

§id: u64
§payload: Inline
§

Error

Python → Rust:调用失败;缺省的 code 按 internal 处理。

Fields

§id: u64
§message: Option<String>
§

Cancel

Rust → Python:取消调用,reason 为 "client" 或 "timeout"。

Fields

§id: u64
§reason: String
§

Event

双向事件。Python → Rust 的事件携带 target,Rust → Python 的事件携带 window。

Fields

§event: String
§target: Option<String>

目标 webview 标签;缺省时广播。

§window: Option<String>

发送事件的 webview 标签。

§payload: Inline
§

ChannelData

Python → Rust:向前端 Channel 推送一条数据。

Fields

§channel: u64
§payload: Inline
§

ChannelClose

Python → Rust:关闭 channel,此后该 channel 的数据被丢弃。

Fields

§channel: u64

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'_derivative_strum> From<&'_derivative_strum Message> for &'static str

Source§

fn from(x: &'_derivative_strum Message) -> &'static str

Converts to this type from the input type.
Source§

impl From<Message> for &'static str

Source§

fn from(x: Message) -> &'static str

Converts to this type from the input type.
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Message

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<'de, D, R> CommandArg<'de, R> for D
where D: Deserialize<'de>, R: Runtime,

Source§

fn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>

Derives an instance of Self from the CommandItem. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IpcResponse for T
where T: Serialize,

Source§

fn body(self) -> Result<InvokeResponseBody, Error>

Resolve the IPC response body.
Source§

impl<T> ScopeObject for T
where T: Send + Sync + Debug + DeserializeOwned + 'static,

Source§

type Error = Error

The error type.
Source§

fn deserialize<R>( _app: &AppHandle<R>, raw: Value, ) -> Result<T, <T as ScopeObject>::Error>
where R: Runtime,

Deserialize the raw scope value.
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UserEvent for T
where T: Debug + Clone + Send + 'static,