Heading 2 Core API class mt-12 Markdown **Note:** The Core API provides low-level parsing functionality optimized for performance and memory efficiency. It uses direct mutation patterns similar to C for optimal performance. For most projects you'll want to use the [Document API](#document-api) instead. It provides an ergonomic wrapper around the Core API and lets you focus on parsing your documents without worrying about low-level details. Heading 3 LineData class mb-4 mt-12 CodeBlock rust // Struct Definition /// Holds the parsed information from each line. #[derive(Debug, Clone, PartialEq)] pub struct LineData { /// Which character is being used for indentation. pub indent: char, /// How many indent characters are present in the current line before the first non-indent character. pub level: usize, /// The number of characters before the start of the line's "head" section. pub offset_head: usize, /// The number of characters before the start of the line's "tail" section. pub offset_tail: usize, } Heading 3 create_line_data() class mb-4 mt-12 Markdown | Parameter | Type | Description | -------------- | --------------------- | ----------------------------------------------------------------------- | indent | char | The character used for indentation in the document. Only a single character is permitted. | **@returns** | [LineData](#line-data) | A LineData instance with the specified indent character and all other values initialized to 0. Initialize a LineData instance with default values to pass to [parse_line()](#parse-line). CodeBlock rust // Function Signature pub fn create_line_data(indent: char) -> LineData // Import Path use terrace::parser::{create_line_data, LineData}; // Usage let line_data = create_line_data(' '); println!("{:?}", line_data); // LineData { indent: ' ', level: 0, offset_head: 0, offset_tail: 0 } // Use the same line_data object for all calls to parse_line in the same document. Heading 3 parse_line() class mb-4 mt-12 Markdown | Parameter | Type | Description | -------------- | --------------------- | ----------------------------------------------------------------------- | line | &str | A string slice containing a line to parse. Shouldn't end with a newline. | line_data | &mut [LineData](#line-data) | A mutable reference to a LineData object to store information about the current line, from [create_line_data()](#create-line-data).
**Mutated in-place!** Core Terrace parser function, sets `level`, `offset_head`, and `offset_tail` in a [LineData](#line-data) object based on the passed line. Note that this is a C-style function, `line_data` is treated as a mutable reference and mutated in-place for performance. CodeBlock rust // Function Signature pub fn parse_line(line: &str, line_data: &mut LineData) // Import Path use terrace::parser::{create_line_data, parse_line}; // Usage let mut line_data = create_line_data(' '); parse_line("title Example Title", &mut line_data); println!("{:?}", line_data); // LineData { indent: ' ', level: 0, offset_head: 0, offset_tail: 5 } // Parse indented line parse_line(" subtitle Example Subtitle", &mut line_data); println!("{:?}", line_data); // LineData { indent: ' ', level: 2, offset_head: 2, offset_tail: 10 }