Skip to content

Add support for smol_str::SmolStr#107

Open
AndreyErmilov wants to merge 2 commits into
SoftbearStudios:mainfrom
hit-box:smol_str
Open

Add support for smol_str::SmolStr#107
AndreyErmilov wants to merge 2 commits into
SoftbearStudios:mainfrom
hit-box:smol_str

Conversation

@AndreyErmilov

Copy link
Copy Markdown

Hi, thank you for the crate!
This PR adds Encode/Decode support for smol_str::SmolStr behind an optional smol_str feature flag, following the same pattern as the existing uuid, time, and rust_decimal integrations.

@finnbear

finnbear commented Apr 4, 2026

Copy link
Copy Markdown
Member

Hello, thanks for the PR!

For efficiency, bitcode checks UTF-8 of multiple strings at once during decoding and vectorizes during encoding. However, this requires using a more specialized pattern than DerefEncoder and FromDecoder. The following snippets can be adapted for SmolStr. Please make an impl_string macro that can be used to support anything with the API of String, and use it for String and SmolStr. You will have to use <T>::from(&str) instead of <str>::to_owned(&self).

  • Encode:

    bitcode/src/str.rs

    Lines 60 to 73 in d0049d9

    impl Encoder<String> for StrEncoder {
    #[inline(always)]
    fn encode(&mut self, t: &String) {
    self.encode(t.as_str());
    }
    #[inline(always)]
    fn encode_vectored<'a>(&mut self, i: impl Iterator<Item = &'a String> + Clone)
    where
    String: 'a,
    {
    self.encode_vectored(i.map(String::as_str));
    }
    }
  • Decode:

    bitcode/src/str.rs

    Lines 134 to 140 in d0049d9

    impl<'a> Decoder<'a, String> for StrDecoder<'a> {
    #[inline(always)]
    fn decode(&mut self) -> String {
    let v: &str = self.decode();
    v.to_owned()
    }
    }

Secondly, please enable SmolStr's serde support so the fuzzer passes.

@AndreyErmilov

Copy link
Copy Markdown
Author

Hi, @finnbear! Thank you for the comments.
Could you please check out the update? I hope I understood everything correctly.
I've encountered a problem with MSRV - smol_str 0.3.4+ uses edition 2024 and requires Rust 1.89, while bitcode's MSRV is 1.70. The only non-yanked version compatible with 1.70 is 0.3.2. Pinning to a single old version isn't a great solution. Do you have any plans to bump the MSRV to 1.89 or higher? Asking just in case :)

@finnbear

finnbear commented Apr 5, 2026

Copy link
Copy Markdown
Member

Thanks, looks good. Next time I work on bitcode (could be weeks/months from now), I'll fully review and likely merge this, making any remaining edits myself.

Regarding MSRV, this seems like a non-issue because:

  • it's an optional dependency
  • we can say version="0.3.2" which is not the same as pinning (version="=0.3.2"), and is fully compatible with "0.3.4+"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants