File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -641,7 +641,7 @@ pin模块用于将数据固定在内存位置上。
641641
642642直接` await ` 一个` future ` 会隐式的固定它。
643643
644- ` pin ` 通过固定的时指针指向的数据 ,如` Pin<Box<SomeType>> ` 固定的是` SomeType ` 。` Box ` 指针仍可移动。
644+ 通过 ` pin ` 固定的是指针指向的数据 ,如` Pin<Box<SomeType>> ` 固定的是` SomeType ` 。` Box ` 指针仍可移动。
645645
646646#### 关于future
647647
@@ -651,7 +651,7 @@ pin模块用于将数据固定在内存位置上。
651651
652652### unpin
653653
654- ` Unpin ` 是一个标记trait,有 ` Unpin ` 标记的类型,可以被安全的移动 ,不论它是否被` pin ` 。
654+ ` Unpin ` 是一个标记trait,类型实现 ` Unpin ` ,表示其可以被安全的移动 ,不论它是否被` pin ` 。
655655
656656没有自引用的类型都会自动实现` Unpin ` 。
657657
@@ -661,4 +661,6 @@ pin模块用于将数据固定在内存位置上。
661661
662662至此可以解释为什么把` future ` 放到` join_all() ` 中会报错了。因为:
663663
664- ` future ` 中可能包含自引用,因此其实现的是` !Unpin ` ,不能被安全的移动。所以需要` pin ` 住它,确保它能被安全的移动。
664+ 因为` future ` 中可能包含自引用,因此其实现的是` !Unpin ` ,不能被安全的移动。所以需要` pin ` 住它,` future ` 被` pin ` 后,就不会被移动了,但其指针仍然可以移动,通过移动其指针仍可以实现创建` Vec ` 而不报错。
665+
666+ 一般是通过创建` Pin<Box<T>> ` 的类型,保证` T ` 即` Future ` 不被移动,只移动` Pin ` 和` Box ` 。
You can’t perform that action at this time.
0 commit comments