-
Notifications
You must be signed in to change notification settings - Fork 29
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
Subspace as a const #175
Comments
|
Rust doesn't support The only way to make Subspace "const" right now would be to change it's internals to support a I'm open to suggestion, feel free to provide a PR, even WIP if you need guidance so we can discuss on a more concrete ground. An example of your use case might be great too. |
This is definitely an enhancement/ergonomic request. It would improve performance slightly, due to the serialization of any type to byte array would be done at compile time. fn myspace() -> Subspace {
Subspace::from(&"myspace");
} Would become const MYSPACE: &Subspace = &Subspace::from(&"myspace"); lazy_static |
Doing pack at compile is possible, but would requires some complex macro setup to work. I'm wondering about changing the Subspace definition so it can be copy free: pub struct Subspace<'a> {
prefix: Cow<'a, [u8]>,
} Either that or: pub struct Subspace<'a> {
prefix: Prefix<'a>,
}
enum Prefix<'a> {
Owned(Box<[u8]>),
Borrowed(&'a[u8]),
Value(&'a dyn TuplePack),
} |
Would it be possible to change Supsace such that you are able to initialize it as a const? ie.
I'm far from an expert, more like a beginner; but from what I'm aware only tuple structs are able to be consts and no allocation is allowed. Since it should be easy to convert any static value into a byte array at compile time.
The text was updated successfully, but these errors were encountered: