Skip to main content

Node

Struct Node 

Source
pub struct Node {
    pub node_type: NodeType,
    pub children: Vec<Node>,
    pub node_idx: Option<usize>,
    pub features_hash: (u64, u64),
    pub children_shape_hash: (u64, u64),
    pub subtree_hash: (u64, u64),
}

Fields§

§node_type: NodeType§children: Vec<Node>§node_idx: Option<usize>§features_hash: (u64, u64)

スタイル計算メモ化(css::style_memo)用の要素単体の特徴ハッシュ(タグ・id・class・属性)。 生成時および属性書き換え時に計算しておき、style_memo::node_features が 1 回の再レイアウトで要素あたり 3〜4 回 BTreeMap を再走査するのを防ぐ(TODO P5a)。

§children_shape_hash: (u64, u64)

直接の子ノード列の形状(タグ・テキスト空判定・要素数)の 128 ビットハッシュ(TODO P5a)。

§subtree_hash: (u64, u64)

自身の features_hash と子孫全体の subtree_hash を畳み込んだ 128 ビットハッシュ(TODO P5a)。 :has() や部分木スタイルメモ(SubtreeStyleMemo)の O(1) ルックアップに使用する。

Implementations§

Source§

impl Node

Source

const MAX_SEARCH_DEPTH: usize = 256

Source

pub fn new_text(text: String) -> Self

Source

pub fn new_comment(text: String) -> Self

コメントを表すノード(#comment 要素。文字は属性 data)。parse_html_document の木だけに現れる。

Source

pub fn new_doctype( name: Option<String>, public_id: Option<String>, system_id: Option<String>, ) -> Self

DOCTYPE を表すノード(#doctype 要素。属性 name・publicid・systemid。無いものは属性なし)。

Source

pub fn new_element(name: String, attrs: BTreeMap<String, String>) -> Self

Source

pub fn new_element_direct( name: String, attrs: BTreeMap<String, String>, id: Option<String>, classes: Vec<String>, ) -> Self

Source

pub fn update_dependent_hashes(&mut self)

直接の子ノードが最新ハッシュを持つ前提で自身の children_shape_hash と subtree_hash を O(children.len()) で更新する。

Source

pub fn refresh_dependent_hashes(&mut self)

子孫からボトムアップで children_shape_hash と subtree_hash を再計算する。

Source

pub fn refresh_features_hash(&mut self)

node_type の属性等を直接書き換えた後に自身と全子孫の features_hash / children_shape_hash / subtree_hash を再計算する。

Source

pub fn empty_root() -> Self

子を持たない html ルート要素を返す。parse_html が返すルートと同じ形状で、 DOM ブリッジを真実源とするインクリメンタル再レイアウト時、HTML パースを 省略するためのプレースホルダとして使う(描画ツリーはブリッジから再構築される)。

Source

pub fn get_attribute(&self, name: &str) -> Option<&str>

要素の属性値を取得する。

Source

pub fn dataset(&self) -> BTreeMap<String, String>

W3C HTML5 §3.2.6.2 / DOMStringMap: data-* 属性から camelCase の dataset マップを抽出する。

Source

pub fn set_dataset_property( &mut self, prop: &str, value: &str, ) -> Result<String, DatasetError>

W3C HTML5 §3.2.6.2: dataset プロパティを設定し、対応する data-* 属性を更新する。

Source

pub fn remove_dataset_property( &mut self, prop: &str, ) -> Result<Option<String>, DatasetError>

W3C HTML5 §3.2.6.2: dataset プロパティを削除し、対応する data-* 属性を削除する。

Source

pub fn get_element_by_id(&self, target_id: &str) -> Option<&Node>

ID による要素探索(深さ優先・最初に一致した参照を返す)。

Source

fn get_element_by_id_depth( &self, target_id: &str, depth: usize, ) -> Option<&Node>

Source

pub fn get_elements_by_class_name<'a>( &'a self, target_class: &str, out: &mut Vec<&'a Node>, )

クラス名による要素収集(深さ優先・ゼロアロケーション走査)。

Source

fn get_elements_by_class_name_depth<'a>( &'a self, target_class: &str, out: &mut Vec<&'a Node>, depth: usize, )

Source

pub fn get_elements_by_tag_name<'a>( &'a self, target_tag: &str, out: &mut Vec<&'a Node>, )

タグ名による要素収集(大文字小文字無視)。

Source

fn get_elements_by_tag_name_depth<'a>( &'a self, target_tag: &str, out: &mut Vec<&'a Node>, depth: usize, )

Source

pub fn text_content(&self) -> String

ツリー内の全テキストを連結して取得する(単一バッファ追記方式)。

Source

fn collect_text(&self, out: &mut String, depth: usize)

Source§

impl Node

大文字小文字を維持した Element ノードを生成する。

Source

pub fn new_element_preserve_case( name: String, attrs: BTreeMap<String, String>, ) -> Self

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.