Add a way to resize StackFutures

未关闭
#6 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust
领域
backend

调研方向

首先阅读仓库中的 StackFuture 实现和现有测试,然后跟踪其存储大小和 ownership 的表示方式。评估提议的 resize API,包括成功路径和原始 future 的错误路径;完成的标准是:可以安全地尝试使用更小或更大的 StackFuture,而无需 boxing,除非 resizing 失败。

由索引模型根据 Issue 内容生成。

描述

It'd be helpful to have a way to shrink (or less commonly, grow) a StackFuture. For example, sometimes you have an object that implements a trait and needs to forward calls to another object that implements the same trait. Right now that's impossible with StackFuture without boxing the child future because otherwise you'd have to have a future contain a future that's the same size as itself. That said, there will usually be some extra space so we might be able to dynamically shrink a StackFuture.

The signature would probably be something like:

fn resize<const NEW_SIZE: usize>(self) -> Result<StackFuture<T, NEW_SIZE>, Self>;

Then using this would look something like:

impl Foo for MyObject {
    fn bar(&self) -> StackFuture<(), 1000> {
        match self.sub_object.bar().resize::<{500}>() {
            Ok(f) => f.await,
            Err(original) => Box::pin(original).await,
        }
    }
}

The idea here is we'd try to fit the future into a smaller container, but if it doesn't fit then the resize returns the original future and we can either decide to pay the allocation cost (as we did in this example) or give up.

主要语言
Rust
星标
314
派生
17
平均合并
11 小时 50 分钟
30 天内合并 PR
1

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/stackfuture 的其他 Issue

查看 microsoft/stackfuture 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。