SmartString is the same size as String and relies on pointer alignment to be able to store a discriminant bit in its inline form that will never be present in its String form
If your pointer must always be aligned to a 32-bit or 64-bit boundary, say, the lowest bits of your aligned pointers (memory addresses) will always end in some number of zeroes.
There's no endianness involved once you are dealing with abstract numeric values. Number-based bitwise operations don't transmute everything to a native-endian blob of bytes, they treat the number as… well, a number. Thus x & 0x01 always gives you the least significant bit of an integer.
If this weren't true, you couldn't rely on basically anything staying consistent across platforms. A literal "1" would suddenly become 263, which is certainly not a useful abstraction.
It assumes that the first 8 bytes are the raw pointer of the String.
Then it validates that the least significant bit of the first byte(the lowest byte) is 0 on a little-endian machine and the most significant bit of the first byte(the highest byte) is 0 on a big-endian machine.
I just can't understand the validation...
Is this to say that the address pointing to heap is always 0b...xxx00 or 0b...xxx000?
Then why the big endian use the highest bit of the highest byte? @quinedot
Well, that was me relying on their English description, and it's accurate for little endian. After skimming the code, looks like they're assuming you never get memory in the upper-half of the address space for big-endian instead. (Typically that's kernel memory, though maybe you could get ahold of such a pointer via a syscall or the like.) There's also this:
// This hack isn't going to work out very well on 32-bit big endian archs,
// so let's not compile on those.
assert_cfg!(not(all(target_endian = "big", target_pointer_width = "32")));
Edit: To be more explicit, they're putting their marker bit into the first byte of the data structure, which corresponds to the first byte of the pointer, given a String. That's the low byte in little endian (so relying on alignment by using the lowest bit) and the high byte in big endian (so relying on lower-half of address space by using the highest bit).