diff options
| author | MALO <57839069+MDLC01@users.noreply.github.com> | 2023-05-30 10:13:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-30 10:13:27 +0200 |
| commit | 644bbf99145042266ea8cf2890cef5771bd04be4 (patch) | |
| tree | b19aaeb5d9ad95dee18bf182804ca93d6719f1fd /src/model/content.rs | |
| parent | b6b6666efdde33a3727955fb2254ba16a886e1d3 (diff) | |
Add `fields` method to content (#1340)
Diffstat (limited to 'src/model/content.rs')
| -rw-r--r-- | src/model/content.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/model/content.rs b/src/model/content.rs index 8b60ab44..f262d027 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -12,7 +12,7 @@ use super::{ }; use crate::diag::{SourceResult, StrResult}; use crate::doc::Meta; -use crate::eval::{Cast, Str, Value, Vm}; +use crate::eval::{Cast, Dict, Str, Value, Vm}; use crate::syntax::Span; use crate::util::pretty_array_like; @@ -251,6 +251,13 @@ impl Content { .ok_or_else(|| missing_field_no_default(field)) } + /// Return the fields of the content as a dict. + pub fn dict(&self) -> Dict { + self.fields() + .map(|(key, value)| (key.to_owned().into(), value)) + .collect() + } + /// The content's label. pub fn label(&self) -> Option<&Label> { match self.field_ref("label")? { |
