diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-23 13:24:39 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-23 13:26:10 +0100 |
| commit | 2b8426b1b3a19d46a94abaece674525948c146af (patch) | |
| tree | 35eae5b09cda399224c58543f58a985cfcd00e79 /src/model/module.rs | |
| parent | 6ca240508eed7288fcc317b9e167f6470a2f952c (diff) | |
Interpret methods on modules as functions in modules
Diffstat (limited to 'src/model/module.rs')
| -rw-r--r-- | src/model/module.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/model/module.rs b/src/model/module.rs index c7cb7faf..ba6c76fb 100644 --- a/src/model/module.rs +++ b/src/model/module.rs @@ -2,8 +2,9 @@ use std::fmt::{self, Debug, Formatter}; use std::path::Path; use std::sync::Arc; -use super::{Content, Scope}; -use crate::util::EcoString; +use super::{Content, Scope, Value}; +use crate::diag::StrResult; +use crate::util::{format_eco, EcoString}; /// An evaluated module, ready for importing or typesetting. #[derive(Clone, Hash)] @@ -46,6 +47,13 @@ impl Module { &self.0.scope } + /// Try to access a definition in the module. + pub fn get(&self, name: &str) -> StrResult<&Value> { + self.scope().get(&name).ok_or_else(|| { + format_eco!("module `{}` does not contain `{name}`", self.name()) + }) + } + /// Extract the module's content. pub fn content(self) -> Content { match Arc::try_unwrap(self.0) { |
