为什么 pin-project 是安全的 #[repr(packed)] !Unpin project_replace pinned_drop UnsafeUnpin pin-project-lite Pin API Pin 用作方法接收者 Pin #[fundamental] Pin #[repr(transparent)] End 这篇文章将介绍被Pin包裹的Unpin结构如何安全的去修改内部字段,Pin的API、字段投影、与 pin-project ...
structPinnedWriteHelloFile{// 使用 pin_project 属性#[pin]future:implFuture<Output=()>,// 不需要 pin 的字段name:String,}implFutureforPinnedWriteHelloFile{fnpoll(self:Pin<&mutSelf>,cx:&mutContext<'_>)->Poll<Self::Output>{// 安全地访问被 pin 的字段letfuture=self.project().future;future....
它叫做pin-project,很棒。我们唯一要做的就是改下我们的定义。 #[pin_project::pin_project]// This generates a `project` methodpub struct TimedWrapper<Fut:Future>{// For each field, we need to choose whether `project` returns an// unpinned (&mut T) or pinned (Pin<&mut T>) reference t...
也有一些方法能够对固定栈上提供一些安全保证,但是现在我们使用pin_project这个包来实现这一点。 Pinning的一些实用规则 针对T:UnPin(这是默认值),Pin<'a,T>完全定价与&'a mut T. 换句话说:UnPin意味着这个类型即使在固定时也可以移动,所以Pin对这...
source\server\buff\target\debug\deps\libactix_codec-ee8ecfda01da0d64.rlib" "D:\00.source\server\buff\target\debug\deps\libpin_project-2df53e4fa00b36f8.rlib" "D:\00.source\server\buff\target\debug\deps\libactix-2c 7043dd9e6a7c52.rlib" "D:\00.source\server\buff\target\debug\deps...
{"reason":"compiler-artifact","package_id":"pin-project-internal 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)","target":{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/sherlock/.cargo/registry/src/github.com-1ecc629...
Pin<P<Target = Bar>>, whereBaris a field ofFoo. Fortunately, we have been able to codify a set of rules which can help users determine if such a projection is safe: It is only safe to pin project if(Foo: Unpin) implies (Bar: Unpin): that ...
"pin-project", "socket2", "time", "tokio", "tower-service", "tracing", "want", ] [[package]] name = "idna" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8...
总之Pin<&mut T>不是数据的 owner,也没法获得&mut T,所以就不能移动 T。 注意,Pin拿住的是一个可以解引用成 T 的指针类型 P,而不是直接拿原本的类型 T。Pin 本身是可 move 的,T 被 pin 住,不能 move。 async runtime的内部实现 要运行异步函数,必须将最外层的Future提交给 executor。 executor 负责...
Compiling demo v0.1.0(E:\project\rust\demo)error:linkingwith`x86_64-w64-mingw32-gcc`failed:exit code:1|=note:"x86_64-w64-mingw32-gcc""-fno-use-linker-plugin""-Wl,--dynamicbase""-Wl,--disable-auto-image-base""-m64""-Wl,--high-entropy-va""E:\\tools\\rust\\rustup\\toolchains...