mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
26 lines
589 B
Rust
26 lines
589 B
Rust
//! Computational utility functions.
|
|
|
|
mod color;
|
|
mod math;
|
|
mod string;
|
|
|
|
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)
|
|
}
|