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§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DatatypeBuilder
impl RefUnwindSafe for DatatypeBuilder
impl !Send for DatatypeBuilder
impl !Sync for DatatypeBuilder
impl Unpin for DatatypeBuilder
impl UnsafeUnpin for DatatypeBuilder
impl UnwindSafe for DatatypeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more