1
0

49 lines
1.1 KiB
Rust
Raw Normal View History

/// Built-in functions that are available to all Dust programs.
2023-12-05 17:08:22 -05:00
use crate::{Map, Result, Type, Value};
2023-11-28 17:54:17 -05:00
2023-11-30 10:00:40 -05:00
mod assert;
mod collections;
mod commands;
2023-11-30 10:10:03 -05:00
mod data_formats;
2023-11-28 17:54:17 -05:00
mod fs;
2023-12-02 02:34:23 -05:00
mod network;
2023-12-26 20:05:19 -05:00
mod option;
2023-11-28 17:54:17 -05:00
mod output;
mod packages;
2023-11-30 11:05:09 -05:00
mod random;
2023-11-30 02:09:55 -05:00
mod r#type;
2023-11-28 17:54:17 -05:00
/// All built-in functions recognized by the interpreter.
///
/// This is the public interface to access built-in functions by iterating over
/// the references it holds.
2023-12-26 20:05:19 -05:00
pub const BUILT_IN_FUNCTIONS: [&dyn BuiltInFunction; 21] = [
2023-11-30 10:00:40 -05:00
&assert::Assert,
&assert::AssertEqual,
&collections::Length,
&commands::Raw,
&commands::Sh,
2023-11-30 10:10:03 -05:00
&data_formats::FromJson,
&data_formats::ToJson,
2023-11-30 02:09:55 -05:00
&fs::Read,
&fs::Write,
&fs::Append,
&network::Download,
2023-12-26 20:05:19 -05:00
&option::EitherOr,
&option::IsNone,
&option::IsSome,
2023-11-30 02:09:55 -05:00
&output::Output,
&packages::InstallPackages,
2023-11-30 11:05:09 -05:00
&random::Random,
&random::RandomBoolean,
&random::RandomFloat,
2023-11-30 11:05:09 -05:00
&random::RandomInteger,
2023-12-02 02:34:23 -05:00
&r#type::TypeFunction,
2023-11-30 02:09:55 -05:00
];
2023-11-28 17:54:17 -05:00
pub trait BuiltInFunction {
fn name(&self) -> &'static str;
2023-11-30 02:09:55 -05:00
fn run(&self, arguments: &[Value], context: &Map) -> Result<Value>;
2023-12-05 17:08:22 -05:00
fn r#type(&self) -> Type;
2023-11-28 17:54:17 -05:00
}