Skip to main content

DatatypeBuilder

Struct DatatypeBuilder 

Source
pub struct DatatypeBuilder { /* private fields */ }
Expand description

Build a custom datatype sort.

Example:

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

// Assert x.is_none()
let x = Datatype::new_const("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("y", &option_int.sort);
let value = option_int.variants[1].constructor.apply(&[&Int::from_i64(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 DatatypeBuilder

Source

pub fn new<S: Into<Symbol>>(name: S) -> Self

Source

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

Source

pub fn finish(self) -> DatatypeSort

Trait Implementations§

Source§

impl Debug for DatatypeBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.