summaryrefslogtreecommitdiff
path: root/src/library/utility/mod.rs
blob: 4244ccbf11817470a0973cc36f2e57be1b762d97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! Computational utility functions.

mod blind;
mod color;
mod math;
mod string;

pub use blind::*;
pub use color::*;
pub use math::*;
pub use string::*;

use crate::library::prelude::*;

/// The name of a value's type.
pub fn type_(_: &mut Context, args: &mut Args) -> TypResult<Value> {
    Ok(args.expect::<Value>("value")?.type_name().into())
}

/// Ensure that a condition is fulfilled.
pub fn assert(_: &mut Context, args: &mut Args) -> TypResult<Value> {
    let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
    if !v {
        bail!(span, "assertion failed");
    }
    Ok(Value::None)
}