Skip to content

esp-radio: make Ssid::as_bytes public - #6322

Open
fbartho wants to merge 3 commits into
esp-rs:mainfrom
fbartho:feat/ssid-raw-bytes
Open

fbartho wants to merge 3 commits into
esp-rs:mainfrom
fbartho:feat/ssid-raw-bytes

Conversation

@fbartho

@fbartho fbartho commented Sep 12, 2026

Copy link
Copy Markdown

Ssid::as_str truncates at the first invalid UTF-8 byte, and the Wi-Fi standard allows an SSID to be any 32 bytes, not necessarily valid UTF-8. A scanned network name that isn't UTF-8 has no public way to be read back out as bytes for storage.

Ssid already implements TryFrom<&[u8]> publicly (esp-radio/src/wifi/mod.rs:843-854), which covers rebuilding an Ssid from stored bytes. The only missing half is the accessor to get the bytes back out, so this PR makes as_bytes public (esp-radio/src/wifi/mod.rs:785-793), matching the visibility of as_str, len, and is_empty on the same type, with a doc comment.

This is a visibility widening on a pre-1.0 crate, so it's additive only; nothing existing changes behavior.

I used AI assistance (Claude) to prepare this branch; I reviewed, tested, and understand the change before opening this PR, per the project's AI tool use policy.

Testing

cargo xtask fmt, cargo xtask lint esp-radio esp32s3, and cargo xtask documentation --packages esp-radio pass clean. No test added: esp-radio has no host-test path and this file's doctests are no_run, and the change only widens the visibility of an existing method.

Changelog

# Changelog

## esp-radio

- Changed: `Ssid::as_bytes` is now public, so a scanned SSID that is not valid UTF-8 can be read as raw bytes for storage and later rebuilt with `Ssid::try_from(&[u8])`.

Validated with echo "<body>" | cargo xtask check-pr-changelog against this exact body (including the prose around it): "PR description changelog format is valid."

Ssid::as_str truncates at the first invalid UTF-8 byte and the Wi-Fi
standard allows any 32 bytes, so a scanned non-UTF-8 network name has
no public way to be read back out as bytes for storage. `Ssid` already
implements `TryFrom<&[u8]>` publicly, which covers rebuilding an SSID
from stored bytes; only the accessor to get the bytes out was missing.

@bjoernQ bjoernQ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd say the hint about as_str would belong to that method and we don't really need a justification for a method to be present.

However we will need another round of API docs review before esp-radio 1.0 proper anyways

@MabezDev MabezDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please mark this API as unstable before we merge this, using the instability attribute.

@bjoernQ

bjoernQ commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

If you touch this, it makes sense to move the as_str API-doc hint, too

Review feedback on esp-rs#6322: the new accessor is gated behind the
`unstable` feature, and the note about lossy UTF-8 handling moves to
`as_str`, the method whose behavior it describes.
@fbartho

fbartho commented Sep 17, 2026

Copy link
Copy Markdown
Author

Addressed in d965e59. Thanks!

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.

3 participants