reflexo_typst2vec/debug_loc.rs
1pub use reflexo::debug_loc::*;
2
3pub use typst::layout::Position as TypstPosition;
4
5/// Unevaluated source span.
6/// The raw source span is unsafe to serialize and deserialize.
7/// Because the real source location is only known during liveness of
8/// the compiled document.
9pub type SourceSpan = typst::syntax::Span;
10
11/// Unevaluated source span with offset.
12///
13/// It adds an additional offset relative to the start of the span.
14///
15/// The offset is usually generated when the location is inside of some
16/// text or string content.
17#[derive(Debug, Clone, Copy)]
18pub struct SourceSpanOffset {
19 pub span: SourceSpan,
20 pub offset: usize,
21}
22
23/// Lifts a [`SourceSpan`] to [`SourceSpanOffset`].
24impl From<SourceSpan> for SourceSpanOffset {
25 fn from(span: SourceSpan) -> Self {
26 Self { span, offset: 0 }
27 }
28}
29
30/// Converts a [`SourceSpan`] and an in-text offset to [`SourceSpanOffset`].
31impl From<(SourceSpan, u16)> for SourceSpanOffset {
32 fn from((span, offset): (SourceSpan, u16)) -> Self {
33 Self {
34 span,
35 offset: offset as usize,
36 }
37 }
38}