Struct swipl::term::Term

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

A term reference.

Implementations§

source§

impl<'a> Term<'a>

source

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.

source

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.

source

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.

source

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

pub fn is_dict(&self) -> bool

Returns true if this term reference holds a dictionary.

source§

impl<'a> Term<'a>

source

pub fn term_ptr(&self) -> term_t

Return the underying term_t from the SWI-Prolog fli.

source

pub fn origin_engine_ptr(&self) -> PL_engine_t

source

pub fn term_type(&self) -> TermType

Returns the type of the value in this term.

source

pub fn is_var(&self) -> bool

Returns true if this term reference holds a variable.

source

pub fn is_atom(&self) -> bool

Returns true if this term reference holds an atom.

source

pub fn is_string(&self) -> bool

Returns true if this term reference holds a string.

source

pub fn is_integer(&self) -> bool

Returns true if this term reference holds an integer.

source

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.

source

pub fn assert_term_handling_possible(&self)

Assert that the engine where this term was originally created is the active engine on this thread.

source

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(()).

source

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(()).

source

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.

source

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.

source

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.

source

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.

source

pub fn get_str<R, F>(&self, func: F) -> PrologResult<R>
where F: Fn(Option<&str>) -> 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.

source

pub fn get_atom<R, F>(&self, func: F) -> PrologResult<R>
where F: Fn(Option<&Atom>) -> 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.

source

pub fn get_atom_name<R, F>(&self, func: F) -> PrologResult<R>
where F: Fn(Option<&str>) -> 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.

source

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(()).

source

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(()).

source

pub fn record(&self) -> Record

Return a record of the term.

Trait Implementations§

source§

impl<'a> Clone for Term<'a>

source§

fn clone(&self) -> Term<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Term<'a>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a> Ord for Term<'a>

source§

fn cmp(&self, other: &Term<'_>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'a> PartialEq for Term<'a>

source§

fn eq(&self, other: &Term<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialOrd for Term<'a>

source§

fn partial_cmp(&self, other: &Term<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> TermPutable for Term<'a>

source§

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

Put data into the term reference. Read more
source§

impl<'a> Unifiable for Term<'a>

source§

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

Unify this data with the given term reference. Read more
source§

impl<'a> Eq for Term<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Term<'a>

§

impl<'a> Send for Term<'a>

§

impl<'a> Sync for Term<'a>

§

impl<'a> Unpin for Term<'a>

§

impl<'a> UnwindSafe for Term<'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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.