pub struct Term<'a> { /* private fields */ }
Expand description
A term reference.
Implementations§
source§impl<'a> Term<'a>
impl<'a> Term<'a>
sourcepub fn get_dict_key<K: IntoKey, G: TermGetable>(
&self,
key: K
) -> PrologResult<G>
pub fn get_dict_key<K: IntoKey, G: TermGetable>( &self, key: K ) -> PrologResult<G>
Get the value of the given key in the dictionary contained in the dictionary contained in this term.
If the dictionary doesn’t contain the key, or if the expected type is different, this will fail. If the given term doesn’t contain a dictionary, this will always fail. Otherwise, the value corresponding to the given key is returned.
sourcepub fn get_dict_key_term<K: IntoKey>(
&self,
key: K,
term: &Term<'_>
) -> PrologResult<()>
pub fn get_dict_key_term<K: IntoKey>( &self, key: K, term: &Term<'_> ) -> PrologResult<()>
Get the value of the given key in the dictionary contained in the dictionary contained in this term.
If the dictionary doesn’t contain the key, this will fail. If the given term doesn’t contain a dictionary, this will always fail. Otherwise, the term argument will be overwritten with the value corresponding to the key.
sourcepub fn get_dict_tag(&self) -> PrologResult<Option<Atom>>
pub fn get_dict_tag(&self) -> PrologResult<Option<Atom>>
Get the tag of this dictionary.
Tag is assumed to be an atom. If it isn’t (because it is either a variable or some other kind of term), None will be returned. Otherwise Some(atom) will be returned.
If this is not a dictionary, this method will fail.
If tag could be a non-atom term, consider using get_dict_tag_term instead.
sourcepub fn get_dict_tag_term(&self, term: &Term<'_>) -> PrologResult<()>
pub fn get_dict_tag_term(&self, term: &Term<'_>) -> PrologResult<()>
Get the tag of this dictionary and put it in the given term.
Unlike get_dict_tag, this is able to extract complex dictionary tags. Though uncommon, a dictionary tag can actually be any valid prolog term. This method helps in extracting that.
If this is not a dictionary, this method will fail.
source§impl<'a> Term<'a>
impl<'a> Term<'a>
pub fn origin_engine_ptr(&self) -> PL_engine_t
sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if this term reference holds an integer.
sourcepub unsafe fn reset(&self)
pub unsafe fn reset(&self)
Reset terms created after this term, including this term itself.
Safety
Only safe to call when you’re sure these terms aren’t used afterwards.
sourcepub fn assert_term_handling_possible(&self)
pub fn assert_term_handling_possible(&self)
Assert that the engine where this term was originally created is the active engine on this thread.
sourcepub fn unify<U: Unifiable>(&self, unifiable: U) -> PrologResult<()>
pub fn unify<U: Unifiable>(&self, unifiable: U) -> PrologResult<()>
Unify this term with some unifiable data.
Unifiable is a trait that has been implemented for many data types.
This will return an Err(PrologError::Exception)
if during
unification, an error was raised somewhere in the SWI-Prolog
fli. If unification is not possible, an
Err(PrologError::Failure)
will be returned. Otherwise the
result is an Ok(())
.
sourcepub fn unify_arg<U: Unifiable>(
&self,
index: usize,
unifiable: U
) -> PrologResult<()>
pub fn unify_arg<U: Unifiable>( &self, index: usize, unifiable: U ) -> PrologResult<()>
Unify the nth arg of the term with some unifiable data. This assumes that the given term contains a functor.
The argument position is 1-indexed. Therefore, the first argument is argument 1.
This will return an Err(PrologError::Exception)
if during
unification, an error was raised somewhere in the SWI-Prolog
fli. If unification is not possible (which may be because this
term does not hold a functor), an Err(PrologError::Failure)
will be returned. Otherwise the result is an Ok(())
.
sourcepub fn get<G: TermGetable>(&self) -> PrologResult<G>
pub fn get<G: TermGetable>(&self) -> PrologResult<G>
Retrieve data from the term reference.
Any data type for which TermGetable has been implemented may be retrieved in this way.
This will return an Err(PrologError::Exception)
if during
getting, an error was raised somewhere in the SWI-Prolog
fli. If getting is not possible (because the term holds a
variable, or an incompatible data type), an
Err(PrologError::Failure)
will be returned. Otherwise the
result is an Ok(data)
, with the requested data in it.
sourcepub fn get_ex<G: TermGetable>(&self) -> PrologResult<G>
pub fn get_ex<G: TermGetable>(&self) -> PrologResult<G>
Retrieve data from the term reference, or raise exception if this is impossible.
Any data type for which TermGetable has been implemented may be retrieved in this way.
In addition to the situations where get()
would raise an
exception, this will raise an error(instantiation_error, _)
when called on an unbound term, and error(type_error(<type name>, <term>), _)
when retrieving the value from the term
was not possible, which is always assumed to be due to a type
incompatibility.
Therefore, the only way this function will error is with an exception. It will never return a failure.
sourcepub fn get_arg<G: TermGetable>(&self, index: usize) -> PrologResult<G>
pub fn get_arg<G: TermGetable>(&self, index: usize) -> PrologResult<G>
Retrieve data from the nth position of the given term. This assumes that the given term contains a functor.
The argument position is 1-indexed. Therefore, the first argument is argument 1.
This will return an Err(PrologError::Exception)
if during
getting, an error was raised somewhere in the SWI-Prolog
fli. If getting is not possible (because the term holds a
variable, or an incompatible data type), an
Err(PrologError::Failure)
will be returned. Otherwise the
result is an Ok(data)
, with the requested data in it.
sourcepub fn get_arg_ex<G: TermGetable>(&self, index: usize) -> PrologResult<G>
pub fn get_arg_ex<G: TermGetable>(&self, index: usize) -> PrologResult<G>
Retrieve data from the nth position of the given term. This assumes that the given term contains a functor.
The argument position is 1-indexed. Therefore, the first argument is argument 1.
This will return an Err(PrologError::Exception)
if during
getting, an error was raised somewhere in the SWI-Prolog fli,
or if the underlying type was not the expected type, or if the
term was not a compound or had the wrong arity. Otherwise the
result is an Ok(data)
, with the requested data in it.
sourcepub fn get_str<R, F>(&self, func: F) -> PrologResult<R>
pub fn get_str<R, F>(&self, func: F) -> PrologResult<R>
Retrieve a &str from this term, and call the given function with it.
This allows you to extract a string from a prolog string with as few copies as possible.
sourcepub fn get_atom<R, F>(&self, func: F) -> PrologResult<R>
pub fn get_atom<R, F>(&self, func: F) -> PrologResult<R>
Retrieve an atom from this term, and call the given function with a borrow to it.
We skip reference-counting for this atom which may be slightly faster in some scenarios.
sourcepub fn get_atom_name<R, F>(&self, func: F) -> PrologResult<R>
pub fn get_atom_name<R, F>(&self, func: F) -> PrologResult<R>
Retrieve an atom from this term, and call the given function with a borrow to it.
We skip reference-counting for this atom which may be slightly faster in some scenarios.
sourcepub fn put<T: TermPutable + ?Sized>(
&self,
val: &T
) -> NonFailingPrologResult<()>
pub fn put<T: TermPutable + ?Sized>( &self, val: &T ) -> NonFailingPrologResult<()>
Put data into the term reference using a borrow.
Any data type for which TermPutable has been implemented may be put into a term ref in this way.
This is a nonlogical operation. The term reference will replace its content in a way that does not play nicely with backtracking.
This will return an Err(PrologException)
if during putting,
an error was raised somewhere in the SWI-Prolog
fli. Otherwise, the result is Ok(())
.
sourcepub fn put_val<T: TermPutable>(&self, val: T) -> NonFailingPrologResult<()>
pub fn put_val<T: TermPutable>(&self, val: T) -> NonFailingPrologResult<()>
Put data into the term reference using a copyable value.
Any data type for which TermPutable has been implemented may be put into a term ref in this way.
This is a nonlogical operation. The term reference will replace its content in a way that does not play nicely with backtracking.
This will return an Err(PrologException)
if during putting,
an error was raised somewhere in the SWI-Prolog
fli. Otherwise, the result is Ok(())
.
Trait Implementations§
source§impl<'a> Ord for Term<'a>
impl<'a> Ord for Term<'a>
source§impl<'a> PartialEq for Term<'a>
impl<'a> PartialEq for Term<'a>
source§impl<'a> PartialOrd for Term<'a>
impl<'a> PartialOrd for Term<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more