-
Notifications
You must be signed in to change notification settings - Fork 22
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
Arbitrary borrow count #9
Conversation
TODO List
|
I'm not sure how to improve the ergonomics. Right now, you must pass it a reference to a The best that I could think of is adding an |
and docs directing people to use the macro
(for better cargo expand output)
Thanks for the PR. I know you haven't quite finished yet, but my first impression is that this makes things a lot more complicated. I've tried to keep things as simple as possible for an unsafe-code reviewer. I'm aware that companies will often want to review crate unsafety themselves, and if their reviewer understands what is going on, they will accept it -- otherwise not. So I have to keep things simple if I want the code to be used. Your code seems to have a lot more Also, I reckoned I could see uses for rw2 (e.g. swapping values between two items), maybe for rw3, but I couldn't think of cases for more, so I stopped at 3. After a certain number (probably around 3 or 4) the caller is likely to be dealing with a dynamic number, which requires a different approach. I think it would be good to have a motivating example use-case for needing 4 or more mutable borrows. I think if this was neat and an "easy win", then definitely I'd go for it. But it's looking like it's creating more problems for the crate than it is solving right now. Let me know what you think. |
That is a very valid concern. A lot of the new I used I'll see how I can simplify this code.
If you want a dynamic number of cells, they will all have to be the exact same type. However, this would greatly simplify the code. If you want to go in this direction, I can send a PR sometime this week for that. |
Could you add Edit: Also an |
What I meant by a dynamic number is that you'd probably want to not borrow them all at the same time, but borrow them in subsets, e.g. borrow pairs at a time. If you borrow them all at the same time, checks go up as O(N^2). If I had an example use-case of how larger numbers of simultaneous borrows would be needed, it would make more sense. Using multiple owners is also an option for TCell/TLCell, although less convenient for LCell (lifetimes) or QCell (memory overhead). Yes, I'm certainly up for adding more methods to allow you to create the functionality in another crate. Are you proposing to send me a PR for this? Or I could do it. |
Ok, that makes sense, I'll make a PR for the extra functionality and split this into it's own crate.
No, I thought that you are only allowed to use one owner per cell for it's entire lifetime. That's how it looks right now at least. |
Thanks. Yes, it's just one owner per cell. But if you have a situation where you need to borrow say 4 cells at the same time, if it can be arranged that they have different owners then that all works out fine. |
This allows you to borrow as many
rw
borrows as you want. (remove the limitation of 3)