Skip to content

[Rust] Implement AsRef<[u8]> on flatbuffers::Array<'a, u8, N> #8574

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

Open
dsxmachina opened this issue Apr 8, 2025 · 0 comments
Open

[Rust] Implement AsRef<[u8]> on flatbuffers::Array<'a, u8, N> #8574

dsxmachina opened this issue Apr 8, 2025 · 0 comments

Comments

@dsxmachina
Copy link

Hello, this is a suggestion for more ergonomic handling of flatbuffer types.

When I have a byte array in a flatbuffer type, e.g. like this:

struct SignatureWithKey {
  key_bytes: [ubyte: 32];
  sig_bytes: [ubyte: 64];
}

The resulting type is a flatbuffers::Array, that internally just wraps a &[u8].

It would be nice, if these arrays (if they are byte arrays) would automatically implement the AsRef<[u8]> trait from the standard library, to easily integrate in existing interfaces of other crates.

Right now, if you want to use the bytes in some function (e.g. a hash function from another crate), you always have to re-build your slice back from the pointer, which requires an unsafe operation and a copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant