css_parse/syntax/
function_block.rs1use crate::{
2 ComponentValues, CursorSink, Function, Parse, Parser, Result as ParserResult, Span, ToCursors, ToSpan, token_macros,
3};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
7pub struct FunctionBlock<'a>(Function<token_macros::Function, ComponentValues<'a>>);
8
9impl<'a> Parse<'a> for FunctionBlock<'a> {
11 fn parse(p: &mut Parser<'a>) -> ParserResult<Self> {
12 p.parse::<Function<token_macros::Function, ComponentValues<'a>>>().map(Self)
13 }
14}
15
16impl<'a> ToCursors for FunctionBlock<'a> {
17 fn to_cursors(&self, s: &mut impl CursorSink) {
18 ToCursors::to_cursors(&self.0, s);
19 }
20}
21
22impl<'a> ToSpan for FunctionBlock<'a> {
23 fn to_span(&self) -> Span {
24 self.0.to_span()
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31 use crate::test_helpers::*;
32
33 #[test]
34 fn size_test() {
35 assert_eq!(std::mem::size_of::<FunctionBlock>(), 64);
36 }
37
38 #[test]
39 fn test_writes() {
40 assert_parse!(FunctionBlock, "foo(bar)");
41 assert_parse!(FunctionBlock, "foo(bar{})");
42 }
43}