-
Notifications
You must be signed in to change notification settings - Fork 12
Support externally provided storage for Channel #67
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
base: main
Are you sure you want to change the base?
Conversation
src/storage/abstractions.rs
Outdated
| use crate::Channel; | ||
|
|
||
| /// The mechanism used to manage the storage of the inner state of a channel of `T`. | ||
| #[expect(private_bounds, reason = "sealed trait with private API surface")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I observe this attribute is failing one of the automated builds that uses Rust 1.65 toolchain, as the lint and the way I suppressed it are all from a too-new Rust version. What is the correctly pattern to apply here to suppress this linter warning in context of this repo's practices? I am not very familiar with how to best build using both old and new toolchains at the same time (except in dependency scenarios where lints are suppressed anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, relaxing to an allow() got rid of some of the warnings but I see that 1.65 does not support this sealed trait pattern in the first place. Will leave the question of what to do with this open for now, pending design discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option to avoid the sealing being an issue on older Rust is to just open up the pattern to non-sealed, so anyone can make an impl Storage.
Enables user-provided storage for the internal
Channel<T>state, so it can be managed in an allocation-free manner (pooled, placed on stack, embedded in another object, etc).Initial draft to facilitate design discussion - it seems to work based on initial exploration but needs more polishing and especially better test coverage.
Closes #66
Example
Design
An important consideration was to not make the default
oneshot::channel()slower/bigger. This is facilitated by generics:Sender<T>becomesSender<T, S = Global<T>>(as well asReceiverandSendError- anything that usesChannel<T>). In this form, behavior is identical to the original.The type parameter has a default value of
Global<T>which means existing code usingoneshotremains unchanged and can continue to pretend there is only 1 generic type parameter.There is a new function that returns
Sender<T, S = External<T>>which enables the new functionality: