microsoft / microsoft/stackfuture
Add a way to resize StackFutures
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 314
- Forks
- 17
- Avg merge
- 11h 50m
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the repository's StackFuture implementation and existing tests, then trace how its storage size and ownership are represented. Evaluate the proposed resize API, including the success and original-future error paths; done means a smaller or larger StackFuture can be attempted safely without boxing unless resizing fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100