pub struct Symbol(/* private fields */);
Expand description
Represents a symbol.
This includes numbers, strings, functions (including constants when arguments are empty and tuples when the name is empty), #inf and #sup.
Implementations§
Source§impl Symbol
impl Symbol
Sourcepub fn create_number(number: i32) -> Symbol
pub fn create_number(number: i32) -> Symbol
Construct a symbol representing a number.
Sourcepub fn create_supremum() -> Symbol
pub fn create_supremum() -> Symbol
Construct a symbol representing #sup.
Sourcepub fn create_infimum() -> Symbol
pub fn create_infimum() -> Symbol
Construct a symbol representing #inf
Sourcepub fn create_string(string: &str) -> Result<Symbol, ClingoError>
pub fn create_string(string: &str) -> Result<Symbol, ClingoError>
Construct a symbol representing a string.
§Arguments
string
- the string
§Errors:
ClingoError::NulError
- ifstring
contains a nul byteClingoError::InternalError
withErrorCode::BadAlloc
Sourcepub fn create_id(name: &str, positive: bool) -> Result<Symbol, ClingoError>
pub fn create_id(name: &str, positive: bool) -> Result<Symbol, ClingoError>
Construct a symbol representing an id.
Note: This is just a shortcut for Symbol::create_function()
with
empty arguments.
§Arguments
name
- the name of the symbolpositive
- whether the symbol has a classical negation sign
§Errors
ClingoError::NulError
- ifname
contains a nul byteClingoError::InternalError
withErrorCode::BadAlloc
Sourcepub fn create_function(
name: &str,
arguments: &[Symbol],
positive: bool,
) -> Result<Symbol, ClingoError>
pub fn create_function( name: &str, arguments: &[Symbol], positive: bool, ) -> Result<Symbol, ClingoError>
Construct a symbol representing a function or tuple.
Note: To create tuples, the empty string has to be used as name.
§Arguments
name
- the name of the functionarguments
- the arguments of the functionpositive
- whether the symbol has a classical negation sign
§Errors
ClingoError::NulError
- ifname
contains a nul byteClingoError::InternalError
withErrorCode::BadAlloc
Sourcepub fn number(self) -> Result<i32, ClingoError>
pub fn number(self) -> Result<i32, ClingoError>
Get the number of a symbol.
§Errors
ClingoError::InternalError
withErrorCode::Runtime
if symbol is not of typeSymbolType::Number
Sourcepub fn name(&self) -> Result<&'static str, ClingoError>
pub fn name(&self) -> Result<&'static str, ClingoError>
Get the name of a symbol.
Note: The string is internalized and valid for the duration of the process.
§Errors
Sourcepub fn string(&self) -> Result<&'static str, ClingoError>
pub fn string(&self) -> Result<&'static str, ClingoError>
Get the string of a symbol.
Note: The string is internalized and valid for the duration of the process.
§Errors
ClingoError::InternalError
withErrorCode::Runtime
if symbol is not of typeSymbolType::String
ClingoError::Utf8Error
Sourcepub fn is_positive(self) -> Result<bool, ClingoError>
pub fn is_positive(self) -> Result<bool, ClingoError>
Check if a function is positive (does not have a sign).
§Errors
Sourcepub fn is_negative(self) -> Result<bool, ClingoError>
pub fn is_negative(self) -> Result<bool, ClingoError>
Check if a function is negative (has a sign).
§Errors
Sourcepub fn symbol_type(self) -> Result<SymbolType, ClingoError>
pub fn symbol_type(self) -> Result<SymbolType, ClingoError>
Get the type of a symbol.
§Errors
ClingoError::InternalError
- may failed to match clingo symbol type
Trait Implementations§
Source§impl From<Symbol> for clingo_symbol_t
impl From<Symbol> for clingo_symbol_t
Source§impl From<u64> for Symbol
impl From<u64> for Symbol
Source§fn from(symbol: clingo_symbol_t) -> Self
fn from(symbol: clingo_symbol_t) -> Self
Source§impl FromSymbol for Symbol
impl FromSymbol for Symbol
type Error = Infallible
fn from_symbol(symbol: Symbol) -> Result<Self, Self::Error>
Source§impl PartialOrd for Symbol
impl PartialOrd for Symbol
Source§fn partial_cmp(&self, other: &Symbol) -> Option<Ordering>
fn partial_cmp(&self, other: &Symbol) -> Option<Ordering>
Compare two symbols.
Symbols are first compared by type. If the types are equal, the values are compared (where strings are compared using strcmp). Functions are first compared by signature and then lexicographically by arguments.