Skip to main content

synth_element_id

Function synth_element_id 

Source
pub fn synth_element_id(block_id: u64, byte_start: u32) -> u64
Expand description

Synthesize a stable per-fragment id from a block id and byte offset within that block. Populates the element_id field in FragmentContent::{Text, Image} (the public layout-engine type), giving callers a stable handle across renders even though the underlying InlineSegments are never stored. Two segments at the same (block_id, byte_start) always produce the same id; a segment that moves to a new byte_start (e.g. due to an insert upstream) gets a new id.

Bit layout (u64): bit 62 = synth tag (so synthesized ids never collide with real entity ids issued by the store’s counter, which start at 1 and grow upward). Bits 32..62 = block id (1 billion blocks per document, 30 bits). Bottom 32 bits = byte offset (4 GB per block). The top bit stays zero so the value fits in positive i64 range — public DTOs expose element_id as i64.