pub struct Document {
source: Box<str>,
arena: Arena,
diagnostic_policy: DiagnosticPolicy,
}Expand description
Single owning handle to a parsed Aozora source.
Owns both the source buffer and a bumpalo-backed Arena.
The &self lifetime parameterises every borrowed-AST view
returned from Document::parse; consumers hold the tree only
as long as they hold a &Document reference.
Fields§
§source: Box<str>§arena: Arena§diagnostic_policy: DiagnosticPolicyImplementations§
Source§impl Document
impl Document
Sourcepub fn new(source: impl Into<Box<str>>) -> Self
pub fn new(source: impl Into<Box<str>>) -> Self
Wrap a source string in a Document with default options.
Equivalent to ParseOptions::new().build(source).
The arena is pre-sized to source.len() * ARENA_CAPACITY_FACTOR
bytes (a corpus-profile-driven estimate of the AST footprint:
p50 arena/source ratio is 3.4×, p99 is 8.25×). Pre-sizing
eliminates the early chunk-grow churn that hits large docs
hardest. Callers that want to override the arena hint or
diagnostic policy reach for Document::options /
ParseOptions::build instead.
Sourcepub fn options() -> ParseOptions
pub fn options() -> ParseOptions
Construct a fresh ParseOptions for the builder chain.
Document::options().arena_capacity(N).diagnostic_policy(P).build(s)
is the canonical configuration entry point.
Sourcepub fn with_arena_capacity(
source: impl Into<Box<str>>,
capacity_hint: usize,
) -> Self
👎Deprecated since 0.3.0: use Document::options().arena_capacity(n).build(source)
pub fn with_arena_capacity( source: impl Into<Box<str>>, capacity_hint: usize, ) -> Self
Wrap a source string with a pre-sized arena.
Document::options().arena_capacity(n).build(source) is the
preferred path since the builder composes naturally with the
diagnostic policy; this constructor remains for source-level
compatibility with pre-Phase-I callers.
Sourcepub fn arena_bytes(&self) -> usize
pub fn arena_bytes(&self) -> usize
Arena bytes currently committed. Diagnostic / benchmarking only.
Sourcepub fn edit(&self, span: Span, replacement: &str) -> Self
pub fn edit(&self, span: Span, replacement: &str) -> Self
Apply an in-place text edit and return a fresh Document.
span is a byte range in the current source (self.source);
replacement is the new text to splice in. The result is a
new Document whose source equals
self.source[..span.start] + replacement + self.source[span.end..].
The arena is rebuilt — incremental re-parse over the unchanged
region is a future improvement (see the architecture handbook
chapter on incremental parse).
The signature is the supported entry point for editor surfaces
implementing textDocument/didChange. Even with a full reparse
inside, callers get a stable API today and a transparent
upgrade path to subtree-aware reuse later.
§Panics
Panics if span.start > span.end, if span.end > source.len(),
or if span.start / span.end does not lie on a UTF-8
codepoint boundary in self.source. These are programmer
errors — editor integrations should clamp the span via the
existing aozora::Span constructor’s bounds checking.
Sourcepub fn parse(&self) -> AozoraTree<'_>
pub fn parse(&self) -> AozoraTree<'_>
Parse the document, returning a borrowed-AST view bound to
&self’s lifetime.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Document
impl !RefUnwindSafe for Document
impl Send for Document
impl !Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl !UnwindSafe for Document
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<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more