Macro swipl::term_getable

source ·
macro_rules! term_getable {
    (($t:ty, $term_: ident) => $b: block) => { ... };
    (($t:ty, $name: tt, $term_: ident) => $b: block) => { ... };
}
Expand description

Easily implement TermGetable.

Example:

struct Foo {num: u64}

term_getable!{
    (Foo, term) => {
        // Body needs to return an Option indicating success or failure.
        // Failure may also be an exception. The wrapper will check for this.
        let num: u64 = attempt_opt(term.get()).unwrap_or(None)?;
        Some(Foo { num })
    }
}

fn do_something(term: &Term) -> PrologResult<()> {
    let foo: Foo = term.get()?;
    println!("foo is {}", foo.num);
    Ok(())
}