Ref<(A, Option<B>)> -> Ref<Option<(A, B)>>?

    pub fn foo<A, B>(x: Ref<(A, Option<B>)>) -> Ref<Option<(A, B)>> {
        Ref::map(x, |(a, ob)| match ob {
            None => None,
            Some(b) => Some((a, b)),
        })
    }

I understand that the above code does not work. My question is: is there a way to make it work? The problem I seem to run into is that any & we generate is unlikely to live long enough.

This, once again, is using Ref in std::cell - Rust

no, it should be impossible

A potentially useful alternative that is possible is e.g.
Ref<(A, Option<B>) -> Option<(Ref<A>, Ref<B>)> (using Ref::map_split).

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.