Skip to main content

SourceText

Struct SourceText 

Source
pub struct SourceText { /* private fields */ }
Expand description

Exact source bytes plus an equal-width UTF-8 carrier for the scalar lexer.

Genuine U+E000..=U+E7FF source characters are stored without side-table entries, and genuine ASCII DEL bytes have no invalid-byte entry, so both remain distinguishable from carrier scalars.

Implementations§

Source§

impl SourceText

Source

pub fn from_utf8(source: &str) -> Self

Wrap ordinary, well-formed UTF-8 source.

This mirrors the engine’s existing infallible &str source boundary; dynamic ECMAScript Strings use Self::try_from_js_string instead.

Source

pub fn try_from_raw_bytes(source: &[u8]) -> Result<Self, JsStringError>

Encode one explicitly sized QuickJS source buffer as equal-width scalar carrier text while retaining the exact original bytes.

Structurally valid Unicode scalars remain byte-identical. Three-byte surrogate encodings become marked PUA scalars, and every byte belonging to malformed, overlong, or out-of-range input becomes one marked DEL. The latter byte-by-byte representation keeps every raw byte offset addressable without allowing the marker to acquire source semantics.

§Errors

Returns JsStringError::TooLong when offsets cannot be represented, or JsStringError::OutOfMemory when storage cannot be reserved.

Source

pub fn try_from_js_string(source: &JsString) -> Result<Self, JsStringError>

Encode an ECMAScript String as reversible scalar-oriented source.

Valid surrogate pairs become their Unicode scalar. Each unpaired surrogate becomes U+E000..=U+E7FF and receives a side-table entry.

§Errors

Returns JsStringError::OutOfMemory if carrier or marker storage cannot be reserved.

Source

pub fn try_from_utf16( units: impl IntoIterator<Item = u16>, ) -> Result<Self, JsStringError>

Build source directly from ECMAScript UTF-16 code units.

§Errors

Propagates the QuickJS String length limit and allocation errors.

Source

pub fn carrier(&self) -> &str

Source

pub fn raw_bytes(&self) -> &[u8] ⓘ

Source

pub fn has_surrogate_markers(&self) -> bool

Source

pub fn surrogate_markers(&self) -> &[SurrogateMarker]

Source

pub fn surrogate_at(&self, byte_offset: usize) -> Option<u16>

Return the source surrogate represented at one carrier/raw byte offset.

Source

pub fn invalid_byte_at(&self, byte_offset: usize) -> bool

Whether one carrier DEL represents a malformed raw source byte.

Source

pub fn slice(&self, range: Range<usize>) -> Option<SourceTextSlice<'_>>

Select a half-open carrier byte range aligned to UTF-8 boundaries.

Source

pub fn semantic_utf16_units(&self) -> Option<SourceTextUtf16Units<'_>>

Source

pub fn try_to_raw_bytes(&self) -> Result<Vec<u8>, TryReserveError>

Clone the exact explicitly sized source payload.

Source

pub fn try_to_js_string(&self) -> Result<JsString, JsStringError>

Reconstruct the original ECMAScript String.

Source

pub fn try_range_to_js_string( &self, range: Range<usize>, ) -> Result<Option<JsString>, JsStringError>

Reconstruct one valid carrier byte range as an ECMAScript String.

Ok(None) means the range is out of bounds or splits a UTF-8 scalar.

Source

pub fn try_range_to_raw_bytes( &self, range: Range<usize>, ) -> Result<Option<Vec<u8>>, TryReserveError>

Clone one valid carrier byte range as exact original source bytes.

Ok(None) means the range is out of bounds or splits a UTF-8 scalar.

Trait Implementations§

Source§

impl AsRef<str> for SourceText

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for SourceText

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceText

Source§

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

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

impl Eq for SourceText

Source§

impl From<&str> for SourceText

Source§

fn from(source: &str) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SourceText

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SourceText

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.