Struct z3::DatatypeBuilder

source ·
pub struct DatatypeBuilder<'ctx> { /* private fields */ }
Expand description

Build a custom datatype sort.

Example:

// Like Rust's Option<int> type
let option_int = DatatypeBuilder::new(&ctx, "OptionInt")
.variant("None", vec![])
.variant(
    "Some",
    vec![("value", DatatypeAccessor::Sort(Sort::int(&ctx)))],
)
.finish();

// Assert x.is_none()
let x = Datatype::new_const(&ctx, "x", &option_int.sort);
solver.assert(&option_int.variants[0].tester.apply(&[&x]).as_bool().unwrap());

// Assert y == Some(3)
let y = Datatype::new_const(&ctx, "y", &option_int.sort);
let value = option_int.variants[1].constructor.apply(&[&Int::from_i64(&ctx, 3)]);
solver.assert(&y._eq(&value.as_datatype().unwrap()));

assert_eq!(solver.check(), SatResult::Sat);
let model = solver.get_model().unwrap();;

// Get the value out of Some(3)
let ast = option_int.variants[1].accessors[0].apply(&[&y]);
assert_eq!(3, model.eval(&ast.as_int().unwrap(), true).unwrap().as_i64().unwrap());

Implementations§

source§

impl<'ctx> DatatypeBuilder<'ctx>

source

pub fn new<S: Into<Symbol>>(ctx: &'ctx Context, name: S) -> Self

source

pub fn variant( self, name: &str, fields: Vec<(&str, DatatypeAccessor<'ctx>)> ) -> Self

source

pub fn finish(self) -> DatatypeSort<'ctx>

Trait Implementations§

source§

impl<'ctx> Debug for DatatypeBuilder<'ctx>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'ctx> RefUnwindSafe for DatatypeBuilder<'ctx>

§

impl<'ctx> !Send for DatatypeBuilder<'ctx>

§

impl<'ctx> !Sync for DatatypeBuilder<'ctx>

§

impl<'ctx> Unpin for DatatypeBuilder<'ctx>

§

impl<'ctx> UnwindSafe for DatatypeBuilder<'ctx>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.