Docs.rs
  • expr-lang-0.3.2
    • expr-lang 0.3.2
    • Permalink
    • Docs.rs crate page
    • MIT
    • Links
    • Homepage
    • Repository
    • crates.io
    • Source
    • Owners
    • jdx
    • Dependencies
      • indexmap ^2 normal
      • log ^0.4 normal
      • once_cell ^1 normal
      • pest ^2 normal
      • pest_derive ^2 normal
      • regex ^1 normal
      • serde ^1.0 normal optional
      • strum ^0.27 normal
      • thiserror ^2 normal
      • proptest ^1 dev
      • serde ^1 dev
      • serde_json ^1 dev
      • test-log ^0.2 dev
    • Versions
    • 14.47% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate expr

expr0.3.2

  • All Items

Crate Items

  • Macros
  • Structs
  • Enums
  • Functions
  • Type Aliases

Crates

  • expr

Crate expr

Source
Expand description

Example:

use expr::{Context, Parser};

let mut p = Parser::new();

let mut ctx = Context::default();
ctx.insert("two".to_string(), 2);

let three: i64 = p.eval("1 + two", &ctx).unwrap().as_number().unwrap();
assert_eq!(three, 3);

p.add_function("add", |c| {
  let mut sum = 0;
  for arg in c.args {
    sum += arg.as_number().unwrap();
  }
  Ok(sum.into())
});

let six: i64 = p.eval("add(1, two, 3)", &ctx).unwrap().as_number().unwrap();
assert_eq!(six, 6);

Macros§

bail
value
Construct an expr::Value from a json-like literal.

Structs§

Context
Environment
Struct containing custom environment setup for expr evaluation (e.g. custom function definitions)
ParserDeprecated
Main struct for parsing and evaluating expr programs
Program
A parsed expr program that can be run

Enums§

Error
An error that can occur when parsing or evaluating an expr program
Rule
Value
Represents a data value as input or output to an expr program

Functions§

compile
Parse an expr program to be run later
eval
Compile and run an expr program in one step, using the default environment.
run
Run a compiled expr program, using the default environment

Type Aliases§

Result

Results

Settings
Help
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.