Add From<Vec<u8>> and FromFFIArg<Vec<u8>> for FFIValue ByteVector#666
Open
koalazub wants to merge 1 commit into
Open
Add From<Vec<u8>> and FromFFIArg<Vec<u8>> for FFIValue ByteVector#666koalazub wants to merge 1 commit into
koalazub wants to merge 1 commit into
Conversation
Enables Rust FFI functions to return Vec<u8> as Steel bytevectors via register_fn, and accept Vec<u8> arguments. Previously only RVec<u8> was supported for arguments, and ByteVector returns were not possible. This unblocks zero-copy binary data transport across the Rust-Steel FFI boundary without base64 encoding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dylib FFI functions can currently accept byte vectors as
RVec<u8>, but there is noway to return one as a Steel bytevector: a returned
Vec<u8>goes throughIntoFFIVal for Vec<T>and arrives in Scheme as a list of integers, sobytes-length,bytes-refetc. fail on it.This adds the two missing ergonomic impls:
From<Vec<u8>> for FFIValue(andFrom<RVec<u8>>) — returned byte buffers becomeproper
FFIValue::ByteVectorsFromFFIArg<'a> for Vec<u8>— owned-Vecarguments work symmetrically with theexisting
RVec<u8>supportUse case: a Helix plugin's companion dylib streams animation frames (kitty graphics
payloads) to the Steel side as bytevectors. Without this, binary transport needs
base64 strings or per-byte list conversion.
One possible concern:
From<Vec<u8>> for FFIValuemakesVec<u8>returns bytevectorswhile other
Vec<T>returns stay lists — an asymmetry, but the same one Rust itselfhas (
Vec<u8>is the de-facto byte-buffer type), and it can't break existing codebecause
Vec<u8>previously satisfied only the list path viaIntoFFIVal, which theblanket
impl<T: Into<FFIValue>> IntoFFIVal for Tnow shadows for this one type.Reviewer should confirm Matt is comfortable with that override — a returned
Vec<u8>that some existing plugin expected as a list would change type. If that's aworry, the alternative is a
ByteVecnewtype instead; happy to rework.Testing: builds + existing steel-core tests pass on the branch; consumer
(libnothelix) exercises both directions in its animation test suite (316 tests).
🤖 Generated with Claude Code