diff --git a/examples/test.rs b/examples/test.rs index 9a72790..84f33e4 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -1,10 +1,11 @@ -use clingo::ast::{guard, symbolic_term, ComparisonOperator, Location}; +use clingo::ast::{symbolic_term, ComparisonOperator, Guard, Location, SymbolicTerm, Term, AST}; use clingo::Symbol; use clingo_sys::*; +use core::marker::PhantomData; +use core::ptr::NonNull; +use std::ffi::{CStr, CString}; fn raw() { - use std::ffi::{CStr, CString}; - let file = CString::new("").unwrap(); let location = clingo_location { begin_line: 0, @@ -68,12 +69,38 @@ fn raw() { assert_eq!(res, " > \"test\"".to_string()); } -fn wrapped() { - use clingo::ast::{Guard, Term, AST}; - use core::marker::PhantomData; - use core::ptr::NonNull; - use std::ffi::{CStr, CString}; +fn xguard<'a, T>(gt: ComparisonOperator, symbolic_term: T) -> Result, ()> +where + T: Into>, +{ + let term: Term = symbolic_term.into(); + let mut guard = std::ptr::null_mut(); + if !unsafe { + clingo_ast_build( + clingo_ast_type_e_clingo_ast_type_guard as i32, + &mut guard, + gt, + term.ast, + ) + } { + panic!("clingo_ast_build() guard failed."); + } + let _ = gt; + let _ = term; + let _ = symbolic_term; + + match NonNull::new(guard) { + Some(ast) => Ok(Guard { + ast: AST { + ptr: ast, + _lifetime: PhantomData, + }, + }), + None => Err(()), + } +} +fn wrapped() { let loc = Location::default(); let mut symbol = 0; let c_str = CString::new("test").unwrap(); @@ -108,30 +135,34 @@ fn wrapped() { let gt = ComparisonOperator::GreaterThan; - let term : Term = symbolic_term.into(); - let mut guard = std::ptr::null_mut(); - if !unsafe { - clingo_ast_build( - clingo_ast_type_e_clingo_ast_type_guard as i32, - &mut guard, - gt as isize, - term, - ) - } { - panic!("clingo_ast_build() guard failed."); - } + // let term: Term = symbolic_term.into(); + // let mut guard = std::ptr::null_mut(); + // if !unsafe { + // clingo_ast_build( + // clingo_ast_type_e_clingo_ast_type_guard as i32, + // &mut guard, + // gt as isize, + // term.ast, + // ) + // } { + // panic!("clingo_ast_build() guard failed."); + // } + // let _ = gt; + // let _ = term; + // let _ = symbolic_term; - let guard = match NonNull::new(guard) { - Some(ast) => Ok(Guard { - ast: AST { - ptr: ast, - _lifetime: PhantomData, - }, - }), - None => Err(()), - }; - let guard = guard.unwrap(); - // let guard = guard(gt, symbolic_term).unwrap(); + // let guard = match NonNull::new(guard) { + // Some(ast) => Ok(Guard { + // ast: AST { + // ptr: ast, + // _lifetime: PhantomData, + // }, + // }), + // None => Err(()), + // }; + // let guard = guard.unwrap(); + let guard = xguard(gt, symbolic_term).unwrap(); + // let guard = clingo::ast::guard(gt, symbolic_term).unwrap(); let mut size: usize = 0; if !unsafe { clingo_ast_to_string_size(guard.ast.ptr.as_ptr(), &mut size) } {