-
Notifications
You must be signed in to change notification settings - Fork 37
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
IOWrite using TryIntoCtx #36
Comments
Hi @roblabla thanks for opening the issue! So:
But yea, I'll merge a PR with tests and examples for this, seems good to me; but will probably require some bikeshedding on a good name? |
Yeah, the name is pretty bad, I didn't think long and hard on it :P. For the stack array, there are crates like smallvec which provide stack arrays under a certain size, and heap arrays otherwise. We could move to something like (untested): let mut buf = SmallVec::<[u8; 256]>::new();
let size = N::size_with(&ctx);
let buf = buf.resize(size, 0);
n.try_into_ctx(buf, ctx)?;
self.write_all(buf)?;
Ok(()) I'll try to write a PR soon:tm: |
Ok, but just fyi, I don't really want external deps in scroll; I know that's super annoying, but I'd like to keep it dependency free in general. That being said I think your general design is good, and I'd even be ok wtih merging a 256 byte temporary struct if it gets this issue closed (as switching to heap allocation for objects larger than 256 bytes is somewhat orthogonal to your requirements). Anyway, thanks for your interest, and no rush :) |
Lots of types implement TryIntoCtx but not IntoCtx in goblin (like elf::ProgramHeader). It'd be nice if those types would be usable with IOWrite. Furthermore, this would grant the user more control over error handling.
Maybe something like:
The text was updated successfully, but these errors were encountered: