diff --git a/ica-rs/ica_typing.py b/ica-rs/ica_typing.py index b732c71..7ab5559 100644 --- a/ica-rs/ica_typing.py +++ b/ica-rs/ica_typing.py @@ -38,7 +38,18 @@ class ReplyMessage: class SendMessage: - ... + @property + def content(self) -> str: + ... + @content.setter + def content(self, value: str) -> None: + ... + def with_content(self, content: str) -> "SendMessage": + """ + 为了链式调用, 返回自身 + """ + self.content = content + return self class NewMessage: @@ -64,7 +75,7 @@ class IcaClient: @staticmethod async def send_message_a(client: "IcaClient", message: SendMessage) -> bool: """ - 仅作占位 + 仅作占位, 不能使用 (因为目前来说, rust调用 Python端没法启动一个异步运行时 所以只能 tokio::task::block_in_place 转换成同步调用) """ diff --git a/ica-rs/src/py/class.rs b/ica-rs/src/py/class.rs index 11cd42c..981a8a4 100644 --- a/ica-rs/src/py/class.rs +++ b/ica-rs/src/py/class.rs @@ -182,6 +182,20 @@ impl SendMessagePy { pub fn __str__(&self) -> String { format!("{:?}", self.msg) } + /// 设置消息内容 + /// 用于链式调用 + pub fn with_content(&mut self, content: String) -> Self { + self.msg.content = content; + self.clone() + } + #[getter] + pub fn get_content(&self) -> String { + self.msg.content.clone() + } + #[setter] + pub fn set_content(&mut self, content: String) { + self.msg.content = content; + } } impl SendMessagePy {