HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
tomtomwombat
cold-string
Rust2026–2026
tomtomwombat / cold-string

cold-string

A 1-word (8-byte) sized representation of immutable UTF-8 strings. In-lines up to 8 bytes.

2Distinct people
2Mentions
0Explicit recommenders
65GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

A 1-word (8-byte) sized representation of immutable UTF-8 strings. In-lines up to 8 bytes.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 12:54:37 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by week2 dated mentions

Observed mentions: 2026-03-01 22:31:42 UTC to 2026-04-09 14:56:34 UTC. Weeks start Monday, UTC.

012026-02-23 00:00:00 UTC to 2026-03-02 00:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 commentsFeb 232026-03-02 00:00:00 UTC to 2026-03-09 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-03-09 00:00:00 UTC to 2026-03-16 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-03-16 00:00:00 UTC to 2026-03-23 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsMar 162026-03-23 00:00:00 UTC to 2026-03-30 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-03-30 00:00:00 UTC to 2026-04-06 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-04-06 00:00:00 UTC to 2026-04-13 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 commentsApr 6

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Feb 232026-02-23 00:00:00 UTC2026-03-02 00:00:00 UTC110
Mar 22026-03-02 00:00:00 UTC2026-03-09 00:00:00 UTC000
Mar 92026-03-09 00:00:00 UTC2026-03-16 00:00:00 UTC000
Mar 162026-03-16 00:00:00 UTC2026-03-23 00:00:00 UTC000
Mar 232026-03-23 00:00:00 UTC2026-03-30 00:00:00 UTC000
Mar 302026-03-30 00:00:00 UTC2026-04-06 00:00:00 UTC000
Apr 62026-04-06 00:00:00 UTC2026-04-13 00:00:00 UTC101

What Hacker News says

2 sources
I realise that I don't do the best job of explaining ColdString here. After all most 8 byte strings of UTF-8 text could equally be a pointer so, why can this work? All ColdStrings which look like 8 bytes of UTF-8 text really are 8 bytes of UTF-8 text, just the type label on those 8 bytes isn't "[u8; 8]" an array of 8 bytes but instead "mut *u8" a raw pointer. "Validate" for example is 8 bytes of ASCII, thus UTF-8, and Rust is OK with us just saying we want a pointer on a 64-bit machine with those bytes. It's not a valid pointer, but it is a pointer and Rust is OK with that, we just need to be careful never to [unsafely] dereference the pointer because it's invalid OK, so there are two cases left: First, what if there are fewer bytes of text? Zero even? Since there are fewer than 8 bytes of text we can use the whole first byte to signal ho
Read the rest
w many of the remainder are text, we use the UTF-8 over-long prefix indicator in which the top five bits of the byte are all set, bytes 0xF8 through 0xFF for this, there are eight of these bytes corresponding to our 8 lengths 0 through 7 inclusive. Because it's over-long this indicator isn't itself a valid UTF-8 prefix. Again we can pretend this is a pointer while knowing it's invalid. Lastly, the seemingly trickiest problem, what if the string didn't fit inline? We use a heap allocation to store the text prefixed by a variable size integer length and we insist this allocation is aligned to 4 bytes. This means a valid pointer to our allocation has zeroes for the bottom two bits, then we rotate that pointer so those bottom two bits are at the top of the first byte position (depending on machine word layout) and we set the top bit. This is now always invalid UTF-8 because it has the continuation marker - the top bit is set but the next is not, which cannot happen in the first byte of any UTF-8 text, and so our code can detect this and reverse the transformation to get back a valid pointer using the strict provenance APIs if this marker is present. This type is tomtomwombat's idea, credit to them: https://github.com/tomtomwombat/cold-string*
In Union types in C# 15

Show HN: ColdString – An 8-byte (1-word) SSO string for Rust

I’ve been working on ColdString, a specialized Rust string type designed for maximum memory efficiency in both small and large immutable strings. In benchmarks, it uses 35% – 64% less memory than Rust's std String and other Rust short-string libraries. ColdString is an 8-byte tagged pointer (4 bytes on 32-bit machines) that can inline up to 8 bytes for character storage. Otherwise, the pointer points to the heap where both the length and characters are stored. The length is encoded as a variable length integer, so it only uses 1 byte for lengths 0 - 127, 2 bytes for 128 - 16383, etc. It's property and MIRI tested. Read more about the implementation: https://github.com/tomtomwombat/cold-string?tab=readme-ov-fi... Any feedback welcome!
1 points · Open discussion

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.