From 671ce3dedd40067bb5cea84fe0739de013827053 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 31 Oct 2022 13:49:10 +0100 Subject: Replace `encode` with `field` --- src/library/structure/heading.rs | 11 +++++------ src/library/structure/list.rs | 18 ++++++++---------- src/library/structure/reference.rs | 7 ++++--- src/library/structure/table.rs | 14 ++++++-------- 4 files changed, 23 insertions(+), 27 deletions(-) (limited to 'src/library/structure') diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs index c967c6d7..fa96248f 100644 --- a/src/library/structure/heading.rs +++ b/src/library/structure/heading.rs @@ -73,12 +73,11 @@ impl Show for HeadingNode { Self { body: self.body.unguard(sel), ..*self }.pack() } - fn encode(&self, styles: StyleChain) -> Dict { - dict! { - "level" => Value::Int(self.level.get() as i64), - "body" => Value::Content(self.body.clone()), - "outlined" => Value::Bool(styles.get(Self::OUTLINED)), - "numbered" => Value::Bool(styles.get(Self::NUMBERED)), + fn field(&self, name: &str) -> Option { + match name { + "level" => Some(Value::Int(self.level.get() as i64)), + "body" => Some(Value::Content(self.body.clone())), + _ => None, } } diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs index 082c98c3..8a57069e 100644 --- a/src/library/structure/list.rs +++ b/src/library/structure/list.rs @@ -90,16 +90,14 @@ impl Show for ListNode { .pack() } - fn encode(&self, _: StyleChain) -> Dict { - dict! { - "tight" => Value::Bool(self.tight), - "attached" => Value::Bool(self.attached), - "items" => Value::Array( - self.items - .items() - .map(|item| item.encode()) - .collect() - ), + fn field(&self, name: &str) -> Option { + match name { + "tight" => Some(Value::Bool(self.tight)), + "attached" => Some(Value::Bool(self.attached)), + "items" => Some(Value::Array( + self.items.items().map(|item| item.encode()).collect(), + )), + _ => None, } } diff --git a/src/library/structure/reference.rs b/src/library/structure/reference.rs index 0a9f4f9c..425ee518 100644 --- a/src/library/structure/reference.rs +++ b/src/library/structure/reference.rs @@ -16,9 +16,10 @@ impl Show for RefNode { Self(self.0.clone()).pack() } - fn encode(&self, _: StyleChain) -> Dict { - dict! { - "label" => Value::Str(self.0.clone().into()), + fn field(&self, name: &str) -> Option { + match name { + "label" => Some(Value::Str(self.0.clone().into())), + _ => None, } } diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs index a2f583f7..41dcd104 100644 --- a/src/library/structure/table.rs +++ b/src/library/structure/table.rs @@ -57,14 +57,12 @@ impl Show for TableNode { .pack() } - fn encode(&self, _: StyleChain) -> Dict { - dict! { - "cells" => Value::Array( - self.cells - .iter() - .map(|cell| Value::Content(cell.clone())) - .collect() - ), + fn field(&self, name: &str) -> Option { + match name { + "cells" => Some(Value::Array( + self.cells.iter().cloned().map(Value::Content).collect(), + )), + _ => None, } } -- cgit v1.2.3