MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus / extract_single_text_node

Function extract_single_text_node

packages/document/src/elements/mod.rs:70–103  ·  view source on GitHub ↗
(children: &Element)

Source from the content-addressed store, hash-verified

68}
69
70fn extract_single_text_node(children: &Element) -> Result<String, ExtractSingleTextNodeError<'_>> {
71 let vnode = match children {
72 Element::Ok(vnode) => vnode,
73 Element::Err(err) => {
74 return Err(ExtractSingleTextNodeError::RenderError(err));
75 }
76 };
77 // The title's children must be in one of two forms:
78 // 1. rsx! { "static text" }
79 // 2. rsx! { "title: {dynamic_text}" }
80 match vnode.template {
81 // rsx! { "static text" }
82 Template {
83 roots: &[TemplateNode::Text { text }],
84 node_paths: &[],
85 attr_paths: &[],
86 ..
87 } => Ok(text.to_string()),
88 // rsx! { "title: {dynamic_text}" }
89 Template {
90 roots: &[TemplateNode::Dynamic { id }],
91 node_paths: &[&[0]],
92 attr_paths: &[],
93 ..
94 } => {
95 let node = &vnode.dynamic_nodes[id];
96 match node {
97 DynamicNode::Text(text) => Ok(text.value.clone()),
98 _ => Err(ExtractSingleTextNodeError::NonTextNode),
99 }
100 }
101 _ => Err(ExtractSingleTextNodeError::NonTemplate),
102 }
103}
104
105fn get_or_insert_root_context<T: Default + Clone + 'static>() -> T {
106 let rt = Runtime::current();

Callers 3

style_contentsMethod · 0.85
TitleFunction · 0.85
script_contentsMethod · 0.85

Calls 4

ErrFunction · 0.85
RenderErrorEnum · 0.85
OkFunction · 0.85
cloneMethod · 0.45

Tested by

no test coverage detected