pub enum Patch {
Create {
id: String,
element_type: String,
props: IndexMap<String, Value>,
},
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,
},
}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.
Fields
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.
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.
Implementations§
Source§impl Patch
impl Patch
pub fn create( id: NodeId, element_type: String, props: IndexMap<String, Value>, ) -> Self
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
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,
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>
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>
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);