Skip to main content

CSSRuleList

Struct CSSRuleList 

Source
pub struct CSSRuleList { /* private fields */ }
Expand description

CSSRuleList 对象

表示一个 CSSRule 对象的集合,通常通过 CSSStyleSheet.cssRules 访问。 这是一个实时更新的列表(live list),当样式表变化时自动更新。

§示例

use iris_cssom::cssrulelist::CSSRuleList;
use iris_cssom::cssrule::CSSStyleRule;
use std::sync::{Arc, Mutex};

let mut list = CSSRuleList::new();
let rule = Arc::new(Mutex::new(CSSStyleRule::new(".class")));
list.append_rule(rule);

assert_eq!(list.length(), 1);

Implementations§

Source§

impl CSSRuleList

Source

pub fn new() -> Self

创建空的规则列表

Source

pub fn from_rules(rules: Vec<Arc<Mutex<dyn CSSRuleTrait>>>) -> Self

从规则向量创建

Source

pub fn length(&self) -> u32

获取规则数量

§示例
use iris_cssom::cssrulelist::CSSRuleList;

let list = CSSRuleList::new();
assert_eq!(list.length(), 0);
Source

pub fn item(&self, index: u32) -> Option<Arc<Mutex<dyn CSSRuleTrait>>>

根据索引获取规则

§参数
  • index - 规则索引(从 0 开始)
§返回值

返回指定索引的规则,如果索引超出范围则返回 None

§示例
use iris_cssom::cssrulelist::CSSRuleList;
use iris_cssom::cssrule::CSSStyleRule;
use std::sync::{Arc, Mutex};

let mut list = CSSRuleList::new();
let rule = Arc::new(Mutex::new(CSSStyleRule::new(".class")));
list.append_rule(rule.clone());

let retrieved = list.item(0);
assert!(retrieved.is_some());
Source

pub fn append_rule(&mut self, rule: Arc<Mutex<dyn CSSRuleTrait>>)

添加规则到列表末尾

§参数
  • rule - 要添加的规则
Source

pub fn insert_rule( &mut self, rule: Arc<Mutex<dyn CSSRuleTrait>>, index: usize, ) -> bool

插入规则到指定位置

§参数
  • rule - 要插入的规则
  • index - 插入位置
§返回值

插入成功返回 true,索引超出范围返回 false

Source

pub fn remove_rule(&mut self, index: usize) -> bool

删除指定索引的规则

§参数
  • index - 要删除的规则索引
§返回值

删除成功返回 true,索引超出范围返回 false

Source

pub fn clear(&mut self)

清空所有规则

Source

pub fn iter(&self) -> impl Iterator<Item = &Arc<Mutex<dyn CSSRuleTrait>>>

获取所有规则的迭代器

Source

pub fn get_all_css_texts(&self) -> Vec<String>

获取所有规则的 CSS 文本

§示例
use iris_cssom::cssrulelist::CSSRuleList;
use iris_cssom::cssrule::CSSStyleRule;
use std::sync::{Arc, Mutex};

let mut list = CSSRuleList::new();
let rule1 = Arc::new(Mutex::new(CSSStyleRule::new(".class1")));
let rule2 = Arc::new(Mutex::new(CSSStyleRule::new(".class2")));
list.append_rule(rule1);
list.append_rule(rule2);

let css_texts = list.get_all_css_texts();
assert_eq!(css_texts.len(), 2);

Trait Implementations§

Source§

impl Clone for CSSRuleList

Source§

fn clone(&self) -> CSSRuleList

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CSSRuleList

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CSSRuleList

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.