Text

Struct Text 

Source
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

SyntaxLanguageSyntaxHint
"hello"PlaintextQuoted
`hello`ImplicitInline1
``hello``ImplicitInline2
sql`SELECT`Other("sql")Inline1
``` (no lang)ImplicitBlock3
```rustOther("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: String

The text content.

§language: Language

The language tag for this text.

§syntax_hint: Option<SyntaxHint>

Hint for serialization about the original syntax.

Implementations§

Source§

impl Text

Source

pub fn new(content: impl Into<String>, language: Language) -> Self

Create a new text value.

Source

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.

Source

pub fn plaintext(content: impl Into<String>) -> Self

Create a plaintext value (from "..." syntax).

Source

pub fn inline_implicit(content: impl Into<String>) -> Self

Create an inline code value with implicit language (from `...` syntax).

Source

pub fn inline(content: impl Into<String>, language: impl Into<String>) -> Self

Create an inline code value with explicit language (from lang`...` syntax).

Source

pub fn block_implicit(content: impl Into<String>) -> Self

Create a block code value with implicit language (from ``` syntax without lang).

Source

pub fn block(content: impl Into<String>, language: impl Into<String>) -> Self

Create a block code value with explicit language.

Source

pub fn block_without_trailing_newline( content: impl Into<String>, language: impl Into<String>, ) -> Self

Create a block code value without adding a trailing newline. This must be used only when performing convertion to eure from another data format.

Source

pub fn as_str(&self) -> &str

Returns the content as a string slice.

Source§

impl Text

Source

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{...}.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Text

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Text> for PrimitiveValue

Source§

fn from(t: Text) -> Self

Converts to this type from the input type.
Source§

impl IntoDocument for Text

Source§

fn write_to(self, c: &mut DocumentConstructor) -> Result<(), WriteError>

Write this value to the current node in the document constructor.
Source§

impl ParseDocument<'_> for Text

Source§

type Error = ParseError

The error type returned by parsing.
Source§

fn parse(ctx: &ParseContext<'_>) -> Result<Self, Self::Error>

Parse a value of this type from the given parse context.
Source§

impl PartialEq for Text

Source§

fn eq(&self, other: &Text) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Text

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnwindSafe for Text

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.