Skip to content
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

Support no_std environments that can't ship an allocator #162

Open
TheButlah opened this issue Jan 12, 2023 · 4 comments
Open

Support no_std environments that can't ship an allocator #162

TheButlah opened this issue Jan 12, 2023 · 4 comments

Comments

@TheButlah
Copy link

I'm working on some rust firmware and we are considering the use of flatbuffers. I know that the official flatc requires alloc. However, we are targetting devices that don't have enough flash space for that.

Is there any interest in having the ability to use something like heapless::Vec in planus? Its a bit of a stretch but I thought I would ask.

@TethysSvensson
Copy link
Collaborator

Yes, there is definitely interest! I'd even go as far as say that it was one of the original motivations for creating planus.

I think the deserialize code should already work fine without alloc. The serialize code so probably need some work, since the API doesn't support failing allocations.

Perhaps it would be good enough to put the error handling as a field on the builder instead of returning a Result?

@TheButlah
Copy link
Author

as a field on the builder

Not sure what you meant by that 👀

@TethysSvensson
Copy link
Collaborator

I am considering the problem of how to check for errors while serializing. Ideally a builder that could fail would have an API like this:

fn build_table(builder: &mut planus::Builder) -> Result<planus::Offset<MyTable>> {
    let offset = MyTable::builder().field_a(17).finish(&mut builder)?;
    Ok(offset)
}

However for builders that cannot fail, having to do error handling for non-existing errors is annoying. We could probably solve this with generic associated types, if we were willing to wait until we can bump our MSRV to rust 1.65.

Alternatively we could change the API slightly to look like this:

fn build_table(builder: &mut planus::Builder) -> Result<planus::Offset<MyTable>> {
    let offset = MyTable::builder().field_a(17).finish(&mut builder);
    builder.check_for_errors()?;
    Ok(offset)
}

@TheButlah
Copy link
Author

I would opt for the first one over the second, I don't find the second's flow of errors to be idiomatic.

I'm in no rush, I would suggest waiting until GATs if you have features from there you need

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

2 participants