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
use std::ffi::CString;
use z3_sys::*;
use Context;
use Symbol;
use Z3_MUTEX;

impl<'ctx> Symbol<'ctx> {
    /// Create a Z3 symbol using an integer.
    ///
    /// NB. Not all integers can be passed to this function.
    /// The legal range of unsigned integers is 0 to 2^30-1.
    ///
    /// # See also:
    ///
    /// - [`Symbol::from_string()`](#method.from_string)
    pub fn from_int(ctx: &Context, i: u32) -> Symbol {
        Symbol {
            ctx,
            cst: None,
            z3_sym: {
                let guard = Z3_MUTEX.lock().unwrap();
                unsafe { Z3_mk_int_symbol(ctx.z3_ctx, i as ::std::os::raw::c_int) }
            },
        }
    }

    /// Create a Z3 symbol using a string.
    ///
    /// # See also:
    ///
    /// - [`Symbol::from_int()`](#method.from_int)
    pub fn from_string(ctx: &'ctx Context, s: &str) -> Symbol<'ctx> {
        let ss = CString::new(s).unwrap();
        let p = ss.as_ptr();
        Symbol {
            ctx,
            cst: Some(ss),
            z3_sym: unsafe {
                let guard = Z3_MUTEX.lock().unwrap();
                Z3_mk_string_symbol(ctx.z3_ctx, p)
            },
        }
    }
}