Skip to main content

Document

Struct Document 

Source
pub struct Document {
    pub root: Node,
    /* private fields */
}
Expand description

A loaded .rux document: parsed source, imported components (by tag), the script engine, and the current tree.

Fields§

§root: Node

Implementations§

Source§

impl Document

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self, String>

Load a document, flattening any failure to a sentence.

Source

pub fn load_checked(path: impl AsRef<Path>) -> Result<Self, LoadError>

Load a document, keeping the failure’s position so a checker can point at it. Document::load is this with the structure discarded.

Source

pub fn from_source(src: &str) -> Result<Self, String>

Process .rux source with no import resolution (used for fallbacks/tests).

Source

pub fn from_source_checked(src: &str) -> Result<Self, LoadError>

Document::from_source, keeping the failure’s position.

The playground needs this: it has no file to point at, so a parse error with no line was all it could ever show, and “something is wrong somewhere” is not much of an editor.

Source

pub fn engine_mut(&mut self) -> &mut Engine

The script engine, for running @tap handlers.

Source

pub fn diagnostics(&self) -> &Diagnostics

What is currently wrong with this document, for the dev overlay.

Source

pub fn set_load_error(&mut self, error: impl Into<String>)

Record that a re-load failed. The tree on screen stays as it was, so the app keeps working while the file is broken; the overlay says so, and marks what you’re looking at as stale.

Source

pub fn clear_stale(&mut self)

Mark the visible tree as not a leftover from before the error, used when the very first load failed, so there is no earlier version being shown.

Source

pub fn replace_with(&mut self, fresh: Document)

Adopt a freshly loaded document’s tree and state, keeping this one’s identity. Used by hot-reload so a successful load clears the error.

Source

pub fn set_focus(&mut self, focus: Option<Focus>)

Focus an input (by r-model), with its caret and selection. None clears.

Source

pub fn interaction(&self) -> &InteractionState

The pointer/focus state pseudo-class selectors match against.

Source

pub fn set_interaction(&mut self, next: InteractionState) -> bool

Update the interaction state (:hover / :active / :focus) and restyle what it affects. Returns whether anything was restyled, so the shell knows whether to repaint, false for the overwhelmingly common case of the pointer moving within the same element.

Only the affected subtree is spliced, not the whole tree: hover moving between two siblings re-cascades their common parent’s subtree, so a caret or selection anywhere else survives by node identity, the same reconcile discipline signal changes use.

Source

pub fn set_viewport(&mut self, viewport: Viewport) -> bool

Tell the document the window size, for @media. Returns whether any query changed answer, i.e. whether the rule set moved and the tree had to be re-cascaded.

A resize fires continuously, and almost every one crosses no breakpoint, so the common case must be free: the media conditions are evaluated at the old and new size and compared, and the tree is only rebuilt when that vector actually differs. A document with no @media at all compares two empty vectors and never rebuilds.

Source

pub fn rebuild(&mut self)

Rebuild the layout tree from the engine’s current state.

Source

pub fn patch(&mut self, changed: &HashSet<String>) -> bool

Apply a set of changed signals in place where possible: re-evaluate the text bindings that read them and write the new strings into their nodes, without rebuilding the tree (so ephemeral state, caret, scroll, survives untouched). Returns false when the change can’t be patched, it touched a signal that drives structure, an attribute, an input value, or a component prop, in which case the caller must rebuild. Nothing is mutated on the false path.

Source

pub fn apply_edit(&mut self, model: &str, value: &str)

Apply an input edit (a keystroke’s new value for model) and reflect it the cheapest correct way: patch the input’s shown value in place, falling back to a rebuild only when model is also read structurally. The caller sets the caret afterward via set_focus.

Source

pub fn apply_handler(&mut self, src: &str) -> bool

Run an @tap handler and reflect its effect the cheapest correct way: patch the changed bindings in place, falling back to a full rebuild only when the change is structural. Returns whether anything changed, so the shell knows whether to repaint.

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.