From db3905eec39cea6429649212c5ca9a569dadbf29 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 24 Feb 2024 19:26:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0SendMessage=E7=B1=BB=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=93=BE=E5=BC=8F=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/ica_typing.py | 15 +++++++++++++-- ica-rs/src/py/class.rs | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) 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 {