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: NodeImplementations§
Source§impl Document
impl Document
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self, String>
pub fn load(path: impl AsRef<Path>) -> Result<Self, String>
Load a document, flattening any failure to a sentence.
Sourcepub fn load_checked(path: impl AsRef<Path>) -> Result<Self, LoadError>
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.
Sourcepub fn from_source(src: &str) -> Result<Self, String>
pub fn from_source(src: &str) -> Result<Self, String>
Process .rux source with no import resolution (used for fallbacks/tests).
Sourcepub fn from_source_checked(src: &str) -> Result<Self, LoadError>
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.
Sourcepub fn engine_mut(&mut self) -> &mut Engine
pub fn engine_mut(&mut self) -> &mut Engine
The script engine, for running @tap handlers.
Sourcepub fn diagnostics(&self) -> &Diagnostics
pub fn diagnostics(&self) -> &Diagnostics
What is currently wrong with this document, for the dev overlay.
Sourcepub fn set_load_error(&mut self, error: impl Into<String>)
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.
Sourcepub fn clear_stale(&mut self)
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.
Sourcepub fn replace_with(&mut self, fresh: Document)
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.
Sourcepub fn set_focus(&mut self, focus: Option<Focus>)
pub fn set_focus(&mut self, focus: Option<Focus>)
Focus an input (by r-model), with its caret and selection. None clears.
Sourcepub fn interaction(&self) -> &InteractionState
pub fn interaction(&self) -> &InteractionState
The pointer/focus state pseudo-class selectors match against.
Sourcepub fn set_interaction(&mut self, next: InteractionState) -> bool
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.
Sourcepub fn set_viewport(&mut self, viewport: Viewport) -> bool
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.
Sourcepub fn patch(&mut self, changed: &HashSet<String>) -> bool
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.
Sourcepub fn apply_edit(&mut self, model: &str, value: &str)
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.
Sourcepub fn apply_handler(&mut self, src: &str) -> bool
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§
impl !Freeze for Document
impl !RefUnwindSafe for Document
impl !Send for Document
impl !Sync for Document
impl !UnwindSafe for Document
impl Unpin for Document
impl UnsafeUnpin for Document
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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