pub struct Text {
pub content: String,
pub language: Language,
pub syntax_hint: Option<SyntaxHint>,
}Expand description
A text value in Eure, unifying strings and code.
§Overview
Text represents all text values in Eure, regardless of whether they were
written using string syntax ("...") or code syntax (`...`). This
unification simplifies the data model while preserving the semantic distinction
through the language field.
§Syntax Mapping
| Syntax | Language | SyntaxHint |
|---|---|---|
"hello" | Plaintext | Quoted |
`hello` | Implicit | Inline1 |
``hello`` | Implicit | Inline2 |
sql`SELECT` | Other("sql") | Inline1 |
``` (no lang) | Implicit | Block3 |
```rust | Other("rust") | Block3 |
§Key Distinction
"..."→Plaintext(explicit: “this is text, not code”)`...`without lang →Implicit(code, language inferred from schema)lang`...`→Other(lang)(code with explicit language)
Fields§
§content: StringThe text content.
language: LanguageThe language tag for this text.
syntax_hint: Option<SyntaxHint>Hint for serialization about the original syntax.
Implementations§
Source§impl Text
impl Text
Sourcepub fn with_syntax_hint(
content: impl Into<String>,
language: Language,
syntax_hint: SyntaxHint,
) -> Self
pub fn with_syntax_hint( content: impl Into<String>, language: Language, syntax_hint: SyntaxHint, ) -> Self
Create a new text value with a syntax hint.
For block syntax hints, automatically ensures trailing newline.
Sourcepub fn plaintext(content: impl Into<String>) -> Self
pub fn plaintext(content: impl Into<String>) -> Self
Create a plaintext value (from "..." syntax).
Sourcepub fn inline_implicit(content: impl Into<String>) -> Self
pub fn inline_implicit(content: impl Into<String>) -> Self
Create an inline code value with implicit language (from `...` syntax).
Sourcepub fn inline(content: impl Into<String>, language: impl Into<String>) -> Self
pub fn inline(content: impl Into<String>, language: impl Into<String>) -> Self
Create an inline code value with explicit language (from lang`...` syntax).
Sourcepub fn block_implicit(content: impl Into<String>) -> Self
pub fn block_implicit(content: impl Into<String>) -> Self
Create a block code value with implicit language (from ``` syntax without lang).
Sourcepub fn block(content: impl Into<String>, language: impl Into<String>) -> Self
pub fn block(content: impl Into<String>, language: impl Into<String>) -> Self
Create a block code value with explicit language.
Source§impl Text
impl Text
Sourcepub fn parse_quoted_string(s: &str) -> Result<Self, TextParseError>
pub fn parse_quoted_string(s: &str) -> Result<Self, TextParseError>
Parse a quoted string like "hello world" into a Text value.
Handles escape sequences: \\, \", \', \n, \r, \t, \0, \u{...}.
Sourcepub fn parse_text_binding(s: &str) -> Result<Self, TextParseError>
pub fn parse_text_binding(s: &str) -> Result<Self, TextParseError>
Parse a text binding content (after the colon) like : hello world\n.
Strips trailing newline and trims whitespace.
Sourcepub fn parse_indented_block(
language: Language,
content: String,
syntax_hint: SyntaxHint,
) -> Result<Self, TextParseError>
pub fn parse_indented_block( language: Language, content: String, syntax_hint: SyntaxHint, ) -> Result<Self, TextParseError>
Parse an indented code block, removing base indentation.
The base indentation is auto-detected from trailing whitespace in the content.
If the content ends with \n followed by spaces, those spaces represent
the closing delimiter’s indentation and determine how much to strip.