pub enum Patch {
Create {
id: String,
element_type: String,
props: ResolvedProps,
},
SetProp {
id: String,
name: String,
value: Value,
},
RemoveProp {
id: String,
name: String,
},
SetText {
id: String,
text: String,
},
Insert {
parent_id: String,
id: String,
before_id: Option<String>,
},
Move {
parent_id: String,
id: String,
before_id: Option<String>,
},
Remove {
id: String,
},
Detach {
id: String,
},
Attach {
parent_id: String,
id: String,
before_id: Option<String>,
},
}Expand description
Platform-agnostic patch operations for updating the UI.
Patches are the wire protocol between the Hypen engine and platform
renderers (DOM, Canvas, iOS UIKit, Android Views). Every mutation to the
UI tree is expressed as an ordered sequence of Patch values.
§Serialization
Patches serialize to JSON with a "type" discriminator and camelCase
field names for direct JavaScript consumption:
{"type": "create", "id": "1", "elementType": "Text", "props": {"0": "Hello"}}
{"type": "insert", "parentId": "root", "id": "1", "beforeId": null}§Node IDs
Node IDs are opaque string identifiers (currently compact integers like
"1", "42"). Renderers must treat them as opaque — the format may
change between versions. The special parent ID "root" refers to the
renderer’s root container.
§Ordering
Within a single render cycle, patches are ordered such that:
Createalways precedesInsertfor the same nodeSetProp/SetTextfollowCreatefor new nodesRemoveis always the last operation for a given nodeInsert/Movespecify position viabefore_id(None= append)
Variants§
Create
Create a new element node with initial properties.
The renderer should allocate a platform-native element and store it by
id. The node is not yet visible — a subsequent Insert attaches it.
props is Arc<IndexMap<...>> so emitting a Create for an existing
InstanceNode is an Arc clone rather than a deep copy of the map.
Wire format is unchanged — the custom serde shim serializes the
inner map directly without exposing the Arc.
Fields
props: ResolvedPropsInitial properties. Key "0" is the positional text content.
SetProp
Update a single property on an existing node.
RemoveProp
Remove a property from an existing node (revert to default).
SetText
Set the text content of a node.
Reserved for future use — not currently emitted by the engine.
The reconciler represents text changes as SetProp { name: "0", ... }
(the positional content slot), so no production code path constructs
a SetText patch today. Renderers must still handle this variant for
forward compatibility; removing it would break the wire format.
Insert
Insert a node as a child of parent_id.
If before_id is Some, insert before that sibling. If None, append.
Fields
Move
Move an already-inserted node to a new position within its parent.
Remove
Remove a node from the tree and deallocate it.
Detach
Detach a subtree from its parent without tearing it down.
The renderer must unlink id from its parent’s children list
but keep the native element and its descendants alive (same
identifier, same props, same children). A subsequent Attach
can reinsert the subtree with zero rebuild work. If Remove
arrives instead, the subtree is torn down normally.
Used by the Router reconciler to cache off-screen route subtrees, so navigating back to a previously-visited route skips both the engine’s keyed-diff work and the renderer’s element-creation work.
Attach
Reattach a previously-Detached subtree to a parent.
The id must reference a still-alive native element that was
detached earlier in the session. If before_id is Some, the
subtree is inserted before that sibling; None appends.
Implementations§
Source§impl Patch
impl Patch
Sourcepub fn create(id: NodeId, element_type: String, props: ResolvedProps) -> Self
pub fn create(id: NodeId, element_type: String, props: ResolvedProps) -> Self
Construct a Create patch. props must already be an
Arc-wrapped resolved-prop map; callers holding a bare
IndexMap wrap it explicitly via Arc::new(...).
pub fn set_prop(id: NodeId, name: String, value: Value) -> Self
pub fn remove_prop(id: NodeId, name: String) -> Self
pub fn set_text(id: NodeId, text: String) -> Self
pub fn insert(parent_id: NodeId, id: NodeId, before_id: Option<NodeId>) -> Self
Sourcepub fn insert_root(id: NodeId) -> Self
pub fn insert_root(id: NodeId) -> Self
Insert a root node into the “root” container
pub fn move_node( parent_id: NodeId, id: NodeId, before_id: Option<NodeId>, ) -> Self
pub fn remove(id: NodeId) -> Self
Sourcepub fn detach(id: NodeId) -> Self
pub fn detach(id: NodeId) -> Self
Emit a Detach patch for the given node.
Instructs the renderer to unlink the subtree rooted at id
from its parent without destroying the native element. A
subsequent Attach can reinsert it.
Sourcepub fn attach(parent_id: NodeId, id: NodeId, before_id: Option<NodeId>) -> Self
pub fn attach(parent_id: NodeId, id: NodeId, before_id: Option<NodeId>) -> Self
Emit an Attach patch to reinsert a previously-detached node
as a child of parent_id (with optional before_id position).
Sourcepub fn attach_root(id: NodeId, before_id: Option<NodeId>) -> Self
pub fn attach_root(id: NodeId, before_id: Option<NodeId>) -> Self
Emit an Attach patch targeting the "root" container. Used when
a control-flow container (Router/Conditional) sitting at the IR
root caches and re-attaches its matched route’s subtree — the
attach has to bypass the container’s own (never-created) NodeId.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Patch
impl<'de> Deserialize<'de> for Patch
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Patch
impl RefUnwindSafe for Patch
impl Send for Patch
impl Sync for Patch
impl Unpin for Patch
impl UnsafeUnpin for Patch
impl UnwindSafe for Patch
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);