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

Buffered parse #11

Closed
wants to merge 12 commits into from
Closed

Buffered parse #11

wants to merge 12 commits into from

Conversation

Easyoakland
Copy link
Contributor

Add parsing of iterators with the str::parse function.
Allows re-use of a datatype's FromStr implementation and easily changing the temporary buffer type so allocations can be done on the stack (no_std compatible) using ex. heapless::String or crate::buffered::StackString instead of naively using a std::string::String on the heap.

@jsdw
Copy link
Owner

jsdw commented Oct 16, 2023

This is a very interesting approach; thank you! This has fallen off my radar for ages, but I'd very much like to play around with your approach here and see how I feel about it; being able to easily parse digits and such is something I've run into quite a lot, and so something like this would be a great addition!

@Easyoakland
Copy link
Contributor Author

Easyoakland commented Oct 16, 2023

It might not be worth having StackString in the crate and instead linking to heapless or ArrayVec and using that for the tests.

Intstead of choosing the buffer type when doing parsing
choose the buffer based upon `Tokens`'s type.
This allows zero-copy parsing by re-using the underlying token buffer if one exists.
If one doesn't exist it enables opaque handling of creating a buffer.
@Easyoakland
Copy link
Contributor Author

Changed. Now buffer has an associated type which is selected by the particular Tokens implementation. This allows re-using the buffer that StrTokens and SliceTokens have without having to copy anything. IterTokens has to copy because it doesn't already have an in-memory buffer, but it is parametrized over the user-decided buffer type when constructed.

@Easyoakland
Copy link
Contributor Author

Closed in favor of #13

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.

2 participants