pub struct Context { /* private fields */ }Expand description
Manager of all other Z3 objects, global configuration options, etc.
An application may use multiple Z3 contexts. Objects created in one context cannot be used in another one. However, several objects may be “translated” from one context to another.
While it is not safe to access Z3 objects from multiple threads, this library includes
a safe structured abstraction for usage of Z3 objects across threads.
See Synchronized.
z3.rs uses an implicit thread-local context by default, which is used in all operations. Most users will not need to create their own contexts or interact with contexts directly.
To use a context with a customized configuration (e.g. setting timeouts),
use with_z3_config.
Advanced users (e.g. those performing FFI with other Z3 bindings) can unsafely create their
own contexts using Context::from_raw, and then use them with with_z3_context.
§See also:
Implementations§
Source§impl Context
impl Context
Sourcepub fn thread_local() -> Context
pub fn thread_local() -> Context
Sourcepub unsafe fn from_raw(z3_ctx: Z3_context) -> Context
pub unsafe fn from_raw(z3_ctx: Z3_context) -> Context
Construct a Context from a raw Z3_context pointer. This is mostly useful for
consumers who want to interoperate with Z3 contexts created through other means,
such as the C API or other bindings such as Python.
§Safety
The caller must ensure the pointer is valid and not already managed elsewhere.
§Examples
use z3::ast::Bool;
use z3_sys::{Z3_mk_config, Z3_del_config, Z3_mk_context_rc};
use z3::Context;
// Create a raw Z3_config using the low-level API
let cfg = unsafe { Z3_mk_config() }.unwrap();
let raw_ctx = unsafe { Z3_mk_context_rc(cfg) }.unwrap();
let ctx = unsafe { Context::from_raw(raw_ctx) };
// Use `ctx` as usual...
unsafe { Z3_del_config(cfg) };
let b = Bool::from_bool(true);
assert_eq!(b.as_bool(), Some(true));pub fn get_z3_context(&self) -> Z3_context
Sourcepub fn interrupt(&self)
pub fn interrupt(&self)
Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
Sourcepub fn handle(&self) -> ContextHandle<'_>
pub fn handle(&self) -> ContextHandle<'_>
Obtain a handle that can be used to interrupt computation from another thread.