pub struct TextSourceMap { /* private fields */ }Expand description
Where each byte of a text node’s text comes from, for a text node whose span alone does not say it.
Most text nodes are a byte-for-byte copy of one source range, and their span
accounts for every byte; such nodes carry no map. The block-structure
rewrite pass (crate::lang::rewrites::blocks) merges adjacent text nodes,
collapses whitespace and applies typographic substitutions; a node whose
text is then no longer a copy of one source range carries this map, in
FlmNodeExt::source_map.
The text source pieces cover the node’s text in order.
Each maximal stretch of text that is a byte-for-byte copy of one source
range is one piece, and a new piece starts wherever that stops being true:
at a collapsed whitespace run, where two text nodes were merged, and at a
substitution, even one that keeps the length (--- becomes —, also three
bytes).
Each piece carries its own span, and a span records its source, so one map may refer to several sources: text merged across the boundary of an expanded user definition does.
Serialized form: {pieces: [...]}.
Implementations§
Source§impl TextSourceMap
impl TextSourceMap
Sourcepub fn new(pieces: Vec<TextSourcePiece>) -> TextSourceMap
pub fn new(pieces: Vec<TextSourcePiece>) -> TextSourceMap
Returns a map over pieces, which must already be in text order.
Sourcepub fn pieces(&self) -> &[TextSourcePiece]
pub fn pieces(&self) -> &[TextSourcePiece]
Returns the text source pieces, in the order in which they cover the node’s text.
Sourcepub fn total_len(&self) -> u32
pub fn total_len(&self) -> u32
Returns how many bytes of the node’s text the text source pieces cover, in total.
§Panics
In debug builds, if the piece lengths sum to more than a u32 holds. A
map is built from one node’s text, so reaching that would take a text
node of more than four gigabytes.
Sourcepub fn piece_at(&self, offset: u32) -> Option<(&TextSourcePiece, u32)>
pub fn piece_at(&self, offset: u32) -> Option<(&TextSourcePiece, u32)>
Returns the text source piece covering the byte at offset in the
node’s text, together with the byte’s offset within that piece; None
for an offset at or past total_len.
The piece’s span says which source range that stretch of text comes
from. The byte at offset is not necessarily the byte at the same
distance into the span: a piece whose text was substituted or collapsed
covers a source range of a different length.
§Panics
In debug builds, under the same overflow condition as
total_len.
Trait Implementations§
Source§impl Clone for TextSourceMap
impl Clone for TextSourceMap
Source§impl Debug for TextSourceMap
impl Debug for TextSourceMap
Source§impl Default for TextSourceMap
impl Default for TextSourceMap
Source§impl DeserializableValue<Flm> for TextSourceMap
impl DeserializableValue<Flm> for TextSourceMap
Source§fn deserialize_value(
__value: &SerialValue,
__cx: &mut DeserializeContext<'_, Flm>,
) -> Result<Self, DeserializeError>
fn deserialize_value( __value: &SerialValue, __cx: &mut DeserializeContext<'_, Flm>, ) -> Result<Self, DeserializeError>
cx gives the call access to the
state of the deserialization in progress. Read moreSource§fn deserialize_field(
name: &'static str,
value: Option<&SerialValue>,
cx: &mut DeserializeContext<'_, L>,
) -> Result<Self, DeserializeError>where
L: SerializableLang,
fn deserialize_field(
name: &'static str,
value: Option<&SerialValue>,
cx: &mut DeserializeContext<'_, L>,
) -> Result<Self, DeserializeError>where
L: SerializableLang,
name of a structure whose fields are read by
name (a type with #[derive(DeserializableValue)]): value is the field’s
value, or None when the key is missing from the map. The default requires
the key and reads its value with deserialize_value;
Option<T> reads a missing key as None. The counterpart of
SerializableValue::is_absent_field: a type overriding one overrides both. Read moreimpl Eq for TextSourceMap
Source§impl PartialEq for TextSourceMap
impl PartialEq for TextSourceMap
Source§impl SerializableValue<Flm> for TextSourceMap
impl SerializableValue<Flm> for TextSourceMap
Source§fn serialize_value(
&self,
__cx: &mut SerializeContext<'_, Flm>,
) -> Result<SerialValue, SerializeError>
fn serialize_value( &self, __cx: &mut SerializeContext<'_, Flm>, ) -> Result<SerialValue, SerializeError>
cx gives the call access to the state
of the serialization in progress — a value that refers to a table object
(a span’s source, say) interns it through cx and embeds the position. Read moreSource§fn is_absent_field(&self) -> boolwhere
L: SerializableLang,
fn is_absent_field(&self) -> boolwhere
L: SerializableLang,
#[derive(SerializableValue)]), is left out of the structure’s map
entirely — no key at all, rather than a key with a null value. The default is
false; Option<T> is absent when it is None. Read moreimpl StructuralPartialEq for TextSourceMap
Auto Trait Implementations§
impl Forget for TextSourceMap
impl Freeze for TextSourceMap
impl Move for TextSourceMap
impl RefUnwindSafe for TextSourceMap
impl Send for TextSourceMap
impl Sync for TextSourceMap
impl Unpin for TextSourceMap
impl UnsafeUnpin for TextSourceMap
impl UnwindSafe for TextSourceMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more