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

Add support for no-alloc using static lifetime ref Box and Vec types #44

Merged
merged 9 commits into from
May 13, 2022

Conversation

leighmcculloch
Copy link
Member

What

Add some super limited support for type construction in no-alloc envs using static lifetime ref Box and Vec types, used whenever the alloc feature is disabled. The alloc feature is dependent on the alloc crate's Box and Vec, and is enabled whenever std is enabled.

This results in three tiers of capabilities:

  • std, type construction using the default allocator for recursive types (that use Box) and Vecs, and encoding/decoding.
  • alloc, type construction using the default allocator for recursive types (that use Box) and Vecs.
  • Otherwise, type construction using static lifetime refs for recursive types and Vecs.

Why

This crate has good support for no_std environments, but not for environments that require no allocator. That's because the XDR types for the Stellar protocol are recursive, and so we can't easily drop-in stack based Vec types like heapless. There are some uses of this lib in no alloc environments that involve using the types for structured programming without us actually needing encoding/decoding. This PR makes that possible without changing the interface of passing an allocator around. Ideally in #39 this is revisited and an allocator is passed down instead.

Known limitations

These changes are temporary, and will be replaced when #39 is addressed.

@leighmcculloch leighmcculloch marked this pull request as draft May 13, 2022 00:38
Comment on lines +13 to +20
complete:
if: always()
needs: [fmt, build, test]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure')
run: exit 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leighmcculloch leighmcculloch marked this pull request as draft May 13, 2022 03:49
@leighmcculloch leighmcculloch marked this pull request as ready for review May 13, 2022 03:59
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

Successfully merging this pull request may close these issues.

1 participant