avl/arcshift

Add a version of rcu with projection

Closed this issue · 4 comments

Currently the version of rcu doesn't allow projection, is it possible to instead add a version of the function that allows such?

    pub fn rcu_project<F, A>(&mut self, f: F) -> (bool, A) where F: FnOnce(&T) -> (T, A) {

This is useful when dealing with a Option type where you always want to set it to some when updating it.

avl commented

Thank you for your request!

I'm all for adding new useful methods!

Using the method signature suggested, A could not have references into T. I think?

Would it be better to have two closure parameters, one FnOnce(&T) -> T and one FnOnce(&'a T)->A where A:'a ?

I won't have time to work on arcshift the next couple of days, but I'm happy to add the suggested function next week!

Would it be better to have two closure parameters, one FnOnce(&T) -> T and one FnOnce(&'a T)->A where A:'a ?

Hmm yeah this is more sensical 😄

avl commented

I'm thinking we could have a signature like this:

fn rcu_project<'s, A>(&'s mut self, f: impl FnOnce(&T) -> Option<T>, projector: impl FnOnce(&'s T) -> A ) -> (bool, A)

This allows the second closure, 'projector', to safely return references that point into the 'T' created by 'f'.

avl commented

An 'rcu_project'-method has been added.

Let me know if it doesn't solve your problem!