Struct swipl::dict::DictBuilder

source ·
pub struct DictBuilder<'a> { /* private fields */ }
Expand description

A builder for prolog dictionaries.

A dictionary can be constructed by first using the various builder functions on this type, and then either putting or unifying the builder with a term.

Example:

fn build_example_dict(term: &Term) -> PrologResult<()> {
    let dict = DictBuilder::new()
        .tag("some_tag")
        .entry("foo", 42_u64)
        .entry("bar", "hello".to_owned());

    term.put(&dict)?;
    Ok(())
}

This will create a prolog dictionary which looks like this:

some_tag{
    foo: 42,
    bar: "hello"
}

Implementations§

source§

impl<'a> DictBuilder<'a>

source

pub fn new() -> Self

Create a new dictionary builder.

source

pub fn set_tag<A: IntoAtom>(&mut self, tag: A)

Set the dictionary tag to the given atom.

source

pub fn tag<A: IntoAtom>(self, tag: A) -> Self

Set the dictionary tag to the given atom.

source

pub fn set_tag_term(&mut self, term: Term<'a>)

Set the dictionary tag to the given term.

source

pub fn tag_term(self, term: Term<'a>) -> Self

Set the dictionary tag to the given term.

source

pub fn add_entry_key<K: Into<Key>>(&mut self, key: K)

add an entry with the given key to the dictionary. The value is implied to be a variable.

If the entry already exists, this will overwrite it.

The key can either be an atom (or something that can be turned into an atom), or an integer.

source

pub fn entry_key<K: Into<Key>>(self, key: K) -> Self

add an entry with the given key to the dictionary. The value is implied to be a variable.

If the entry already exists, this will overwrite it.

The key can either be an atom (or something that can be turned into an atom), or an integer.

source

pub fn add_entry<K: Into<Key>, P: TermPutable + 'a>(&mut self, key: K, val: P)

Add an entry with the given key and value to the dictionary.

If the entry already exists, this will overwrite it.

The key can either be an atom (or something that can be turned into an atom), or an integer.

source

pub fn entry<K: Into<Key>, P: TermPutable + 'a>(self, key: K, val: P) -> Self

Add an entry with the given key and value to the dictionary.

If the entry already exists, this will overwrite it.

The key can either be an atom (or something that can be turned into an atom), or an integer.

Trait Implementations§

source§

impl<'a> Default for DictBuilder<'a>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> TermPutable for DictBuilder<'a>

source§

fn put(&self, term: &Term<'_>)

Put data into the term reference. Read more
source§

impl<'a> Unifiable for DictBuilder<'a>

source§

fn unify(&self, term: &Term<'_>) -> bool

Unify this data with the given term reference. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DictBuilder<'a>

§

impl<'a> !Send for DictBuilder<'a>

§

impl<'a> !Sync for DictBuilder<'a>

§

impl<'a> Unpin for DictBuilder<'a>

§

impl<'a> !UnwindSafe for DictBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.