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>
impl<'a> DictBuilder<'a>
sourcepub fn set_tag_term(&mut self, term: Term<'a>)
pub fn set_tag_term(&mut self, term: Term<'a>)
Set the dictionary tag to the given term.
sourcepub fn add_entry_key<K: Into<Key>>(&mut self, key: K)
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.
sourcepub fn entry_key<K: Into<Key>>(self, key: K) -> Self
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.
sourcepub fn add_entry<K: Into<Key>, P: TermPutable + 'a>(&mut self, key: K, val: P)
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.
sourcepub fn entry<K: Into<Key>, P: TermPutable + 'a>(self, key: K, val: P) -> Self
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.