pepl_stdlib/modules/
location.rs1use crate::capability::{CAP_LOCATION, LOCATION_CURRENT};
16use crate::error::StdlibError;
17use crate::module::StdlibModule;
18use crate::value::Value;
19
20pub struct LocationModule;
22
23impl LocationModule {
24 pub fn new() -> Self {
25 Self
26 }
27}
28
29impl Default for LocationModule {
30 fn default() -> Self {
31 Self::new()
32 }
33}
34
35impl StdlibModule for LocationModule {
36 fn name(&self) -> &'static str {
37 "location"
38 }
39
40 fn has_function(&self, function: &str) -> bool {
41 matches!(function, "current")
42 }
43
44 fn call(&self, function: &str, args: Vec<Value>) -> Result<Value, StdlibError> {
45 match function {
46 "current" => self.current(args),
47 _ => Err(StdlibError::unknown_function("location", function)),
48 }
49 }
50}
51
52impl LocationModule {
53 fn current(&self, args: Vec<Value>) -> Result<Value, StdlibError> {
58 if !args.is_empty() {
59 return Err(StdlibError::wrong_args("location.current", 0, args.len()));
60 }
61 Err(StdlibError::capability_call(
62 "location",
63 "current",
64 CAP_LOCATION,
65 LOCATION_CURRENT,
66 args,
67 ))
68 }
69}