smtlib_lowlevel/backend/
z3_binary.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::ffi::OsStr;

use super::{Backend, BinaryBackend};

pub struct Z3Binary {
    bin: BinaryBackend,
}

impl Z3Binary {
    pub fn new(z3: impl AsRef<OsStr>) -> Result<Self, std::io::Error> {
        Ok(Z3Binary {
            bin: BinaryBackend::new(z3, |cmd| {
                cmd.arg("smtlib2_compliant=true").arg("-in");
            })?,
        })
    }
}

impl Backend for Z3Binary {
    fn exec(&mut self, cmd: &crate::Command) -> Result<String, crate::Error> {
        self.bin.exec(cmd).map(Into::into)
    }
}

#[cfg(feature = "tokio")]
pub mod tokio {
    use std::{ffi::OsStr, future::Future};

    use crate::backend::tokio::TokioBinaryBackend;

    pub struct Z3BinaryTokio {
        bin: TokioBinaryBackend,
    }

    impl Z3BinaryTokio {
        pub async fn new(z3: impl AsRef<OsStr>) -> Result<Self, std::io::Error> {
            Ok(Z3BinaryTokio {
                bin: TokioBinaryBackend::new(z3, |cmd| {
                    cmd.arg("smtlib2_compliant=true").arg("-in");
                })
                .await?,
            })
        }
    }

    impl crate::backend::tokio::TokioBackend for Z3BinaryTokio {
        fn exec(
            &mut self,
            cmd: &crate::Command,
        ) -> impl Future<Output = Result<String, crate::Error>> {
            async move { self.bin.exec(cmd).await.map(Into::into) }
        }
    }
}