change some std types to core equivalent #337
Merged
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.
Part 2 of the #294 series, this PR just simply replace some
stdtypes that can usecoreas its substitution. This will greatly helpno_stdcompatibility, although there are still some issue unresolved, for example, thevec!macro is subtlety used and this is undefined inno_stdcontext -- although addinguse alloc::vec;statement back in would compile well, but this would imply the use ofalloc, and I think it is okay for most situations.My own anecdotal use case is for a core part of a language parser that I want it to be
no_stdso it can be embedded easily into a ESP32 target to parse some Lispy command from serial console for configurating sensor states and setup WiFi information in flash memory -- and I don't want to use LALR parser there because memory access time is slow on that MCU. Although I can have a memory allocator there because each ESP32 device have their memory map well-defined and a global allocator is usually provided for free using their SDK. This solved my problem well and I guess 99% of the people can relax nicely here....But I have another use case: I'm writing a kernel command-line parser and the existence of a global allocator is not guaranteed at all time, so I can't use
allocat all most of the time especially when this parser ran before the virtual memory heap is initialized yet.To be honest the implicit
vecproblem comes from here:These operators are merely tail-recursive optimization for the equivalent recursion expansion, and it can be worked-around by going back to doing recursive expansions instead.
For now, any user that does not use
allocbutno_stdmust be aware of this issue, since we cannot disable these operators as a feature.Maybe we should document it instead and tell any user who wants to preserve these operators, they must define their own
Vectype and implement their ownvecmacro that does static size allocation -- you can wrap the peg grammar inside a mod, and do whatever customization you want, so the freedom is up to what you defined in the super crate.However, if you are not using those repeating operators at all, you don't have to worry: your code is already
no_stdready now.