Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support splitting into multiple objects? #117

Open
fzyzcjy opened this issue Jun 15, 2024 · 0 comments
Open

Support splitting into multiple objects? #117

fzyzcjy opened this issue Jun 15, 2024 · 0 comments

Comments

@fzyzcjy
Copy link

fzyzcjy commented Jun 15, 2024

Hi thanks for the helpful package!

When implementing https://github.com/fzyzcjy/flutter_rust_bridge, I am considering the following scenario. Firstly a simple one:

struct One { .. }
struct Two<'a> { .. }
fn compute(one: &'a One) -> Two<'a> { .. }

I have a Arc<One> as input, and want to provide something as if Arc<Two> as output, but it should have no lifetime specifier by putting Arc<One> inside it.

// pseudo code for both self_cell and ouroboros
struct TwoWithOwner {
  one: Arc<One>,
  two: Two<'this>,
}

let input: Arc<One> = ...;
let output: Arc<TwoWithOwner> = Arc::new(TwoWithOwnerBuilder {
  one: input,
  two_builder: |one| compute(one),
}.build());

Now comes the problem. Suppose the return type is a Vec:

fn compute(one: &'a One) -> Vec<Two<'a>> { .. }

And for the same input, I hope to provide Vec<Arc<Two>> as output (again without lifetimes).
If using the exact same code, I will only get something like:

struct VecTwoWithOwner {
  one: Arc<One>,
  two: Vec<Two<'this>>,
}

In other words, an Arc<VecTwoWithOwner> object, instead of Vec<Arc<TwoWithOwner>>.

It would be great if there are some API that can split an Arc<VecTwoWithOwner> object into multiple Vec<Arc<TwoWithOwner>> objects. From my naive thoughts, maybe there can be something like a transform function. Or, there may be better solutions for the scenario above.

Cross-posted in: Voultapher/self_cell#58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant