forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraits.rs
More file actions
54 lines (47 loc) · 1.62 KB
/
traits.rs
File metadata and controls
54 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use cssparser::*;
use crate::properties::Property;
use crate::declaration::DeclarationList;
use crate::printer::Printer;
use crate::error::{ParserError, PrinterError};
use crate::logical::LogicalProperties;
pub trait Parse: Sized {
/// Parse a value of this type.
///
/// Returns an error on failure.
fn parse<'i, 't>(
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i, ParserError<'i>>>;
}
/// Trait for things the can serialize themselves in CSS syntax.
pub(crate) trait ToCss {
/// Serialize `self` in CSS syntax, writing to `dest`.
fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError> where W: std::fmt::Write;
/// Serialize `self` in CSS syntax and return a string.
///
/// (This is a convenience wrapper for `to_css` and probably should not be overridden.)
#[inline]
fn to_css_string(&self) -> String {
let mut s = String::new();
let mut printer = Printer::new("", &mut s, None, false, None);
self.to_css(&mut printer).unwrap();
s
}
}
impl<'a, T> ToCss for &'a T
where
T: ToCss + ?Sized,
{
fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError> where W: std::fmt::Write {
(*self).to_css(dest)
}
}
pub(crate) trait PropertyHandler: Sized {
fn handle_property(&mut self, property: &Property, dest: &mut DeclarationList, logical_properties: &mut LogicalProperties) -> bool;
fn finalize(&mut self, dest: &mut DeclarationList, logical_properties: &mut LogicalProperties);
}
pub trait TryAdd<T> {
fn try_add(&self, other: &T) -> Option<T>;
}
pub trait FromStandard<T>: Sized {
fn from_standard(val: &T) -> Option<Self>;
}