summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzy <[email protected]>2023-10-31 02:22:53 +0000
committerzy <[email protected]>2023-10-31 02:22:53 +0000
commit4ece59583924a88fe22de1d24d5765ae6795228c (patch)
tree1e3f3d1c16eb292f7b50d50096d063f86cc2af99
parent45b95082b2da07cdf0b2267c3407ae41ee591432 (diff)
update readme
-rw-r--r--runtime.md23
1 files changed, 10 insertions, 13 deletions
diff --git a/runtime.md b/runtime.md
index 7374b8d..2f84bc1 100644
--- a/runtime.md
+++ b/runtime.md
@@ -3,6 +3,7 @@ changelog
```log
10.24 init
10.27 update
+10.30 更新 rust 1.75 版本
```
目前能运行起来,并将 plugin 编写简化成和 事件回调 基本相同水平.
@@ -15,12 +16,11 @@ plugin 必须实现 PHandle trait, 其返回值类型为 T (可也是 `()` 即�
```rust
pub(crate) trait PHandle<T: Default> {
- type EventArray: AsRef<[Event]>; // for interested_events() return type
fn get_name(&self) -> &'static str;
fn plug_events(&mut self) -> &PlugEvents;
- fn interested_events(&mut self) -> Self::EventArray;
+ fn interested_events(&mut self) -> impl AsRef<[Event]>;
fn handle_events<'a>(
&'a mut self,
@@ -36,19 +36,17 @@ pub(crate) trait PHandle<T: Default> {
```rust
pub trait PHandleExt<T: Default> {
- type ReturnFuture<'a>: Future<Output = T>
- where
- Self: 'a,
- T: 'a;
-
fn init(&mut self); // plugin.init
// plugin.handle
- fn handle<'a>(
+ async fn handle<'a>(
&'a mut self,
packet: Option<&'a Packet<'a>>, // packet as a reference, need 'a lifetime
session: Option<Rc<RefCell<Session>>>,
- ) -> <Self as PHandleExt<T>>::ReturnFuture<'_>;
+ ) -> T
+ where
+ Self: 'a,
+ T: 'a;
}
impl<A, T> PHandleExt<T> for A
@@ -59,8 +57,8 @@ where
```
PHandleExt 的 `int` 和 `handle`
-- rust 稳定版尚不能在 trait 中定义 async fn. [pull/115822](https://github.com/rust-lang/rust/pull/115822) 已合并进入主线,预计版本是 1.75. 这时 handle 应该定义为 async fn.
-- 这里用了 nightly 一个 feature (type_alias_impl_trait) ,没有 dyn 的开销.
+- rust 稳定版尚不能在 trait 中定义 async fn. [pull/115822](https://github.com/rust-lang/rust/pull/115822) 已合并进入主线,对应版本是 1.75. ~~这时 handle 应该定义为 async fn.~~ 已在更改并在 1.75 版本测试,上述代码应该能在 1.75 版本稳定版上运行.
+- ~~这里用了 nightly 一个 feature (type_alias_impl_trait) ,没有 dyn 的开销.~~ 不再定义为 type alias, 直接使用 impl trait.
## plugin
@@ -85,8 +83,7 @@ impl PHandle<()> for ExamplePulgin {
fn get_name(&self) -> &'static str {self.plugin_name}
fn plug_events(&mut self) -> &PlugEvents {&(self.plug_events)}
- type EventArray = [Event; 5];
- fn interested_events(&mut self) -> Self::EventArray {
+ fn interested_events(&mut self) -> impl AsRef<[Event]> {
[
Event::TCPOpeningEvent,
Event::TCPActiveEvent,