duckscriptsdk/sdk/std/collections/map/
mod.rs1use crate::utils::pckg;
2use crate::utils::state::put_handle;
3use duckscript::types::command::{Command, CommandInvocationContext, CommandResult};
4use duckscript::types::runtime::StateValue;
5use std::collections::HashMap;
6
7#[cfg(test)]
8#[path = "./mod_test.rs"]
9mod mod_test;
10
11#[derive(Clone)]
12pub(crate) struct CommandImpl {
13 package: String,
14}
15
16impl Command for CommandImpl {
17 fn name(&self) -> String {
18 pckg::concat(&self.package, "Map")
19 }
20
21 fn aliases(&self) -> Vec<String> {
22 vec!["map".to_string()]
23 }
24
25 fn help(&self) -> String {
26 include_str!("help.md").to_string()
27 }
28
29 fn clone_and_box(&self) -> Box<dyn Command> {
30 Box::new((*self).clone())
31 }
32
33 fn run(&self, context: CommandInvocationContext) -> CommandResult {
34 let map = HashMap::new();
35
36 let key = put_handle(context.state, StateValue::SubState(map));
37
38 CommandResult::Continue(Some(key))
39 }
40}
41
42pub(crate) fn create(package: &str) -> Box<dyn Command> {
43 Box::new(CommandImpl {
44 package: package.to_string(),
45 })
46}