style/rule_tree/
source.rs1#![forbid(unsafe_code)]
6
7use crate::properties::PropertyDeclarationBlock;
8use crate::shared_lock::{Locked, SharedRwLockReadGuard};
9use servo_arc::Arc;
10use std::io::Write;
11use std::ptr;
12
13#[derive(Clone, Debug)]
20pub struct StyleSource(Arc<Locked<PropertyDeclarationBlock>>);
21
22impl PartialEq for StyleSource {
23 fn eq(&self, other: &Self) -> bool {
24 Arc::ptr_eq(&self.0, &other.0)
25 }
26}
27
28impl StyleSource {
29 #[inline]
30 pub(super) fn key(&self) -> ptr::NonNull<()> {
31 self.0.raw_ptr()
32 }
33
34 #[inline]
36 pub fn from_declarations(decls: Arc<Locked<PropertyDeclarationBlock>>) -> Self {
37 Self(decls)
38 }
39
40 pub(super) fn dump<W: Write>(&self, guard: &SharedRwLockReadGuard, writer: &mut W) {
41 let _ = write!(writer, " -> {:?}", self.read(guard).declarations());
42 }
43
44 #[inline]
47 pub fn read<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a PropertyDeclarationBlock {
48 self.0.read_with(guard)
49 }
50
51 #[inline]
53 pub fn get(&self) -> &Arc<Locked<PropertyDeclarationBlock>> {
54 &self.0
55 }
56}