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

String::from_utf8? #378

Closed
t-moe opened this issue Sep 21, 2023 · 0 comments · Fixed by #399
Closed

String::from_utf8? #378

t-moe opened this issue Sep 21, 2023 · 0 comments · Fixed by #399

Comments

@t-moe
Copy link

t-moe commented Sep 21, 2023

Im using nom to parse binary data, coming from a modem. The data is sometimes uft8 and sometimes other binary data. At some point I want to convert from u8 slices to a heapless String...

struct Request
{
    method: String<5>,
    url: String<120>,
    version: String<8>
}

fn request_line(i: &[u8]) -> IResult<&[u8], Request, VerboseError<&[u8]>> {
// ....
}

Currently I use core::str::from_utf8(method).unwrap().into() to convert from the u8 slice into the String<...>.
Is there another, simpler way? Should we add a from_uft8 method to heapless::String, similar to how std has one?

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 a pull request may close this issue.

1 participant