rust-embedded / rust-embedded/heapless
from_iter on heapless::String should be generic over any iterator that yields a type that implements AsRef<str>
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2k
- Forks
- 253
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 1
Description
You currently cannot use from_iter directly with a &[CompactString] for example. You have to do .into_iter().map(...) which is annoying. I ended up building my own helper function for this but it would be nicer if the heapless crate itself provided this generic impl.
This is my helper function:
pub fn build_hstring<const N: usize, I, S>(iter: I) -> heapless::String<N>
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
let mut new = heapless::String::<N>::new();
for c in iter {
new.push_str(c.as_ref()).expect("build_hstring: capacity exceeded");
}
new
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from heapless::String::from_iter and compare it with the helper shown in the issue, including its IntoIterator and AsRef bounds. Confirm the desired behavior with an iterator over string-like values such as &[CompactString]; it is done when callers no longer need an intermediate map to build a heapless::String.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100