pub fn split_with_parser(query: &str) -> Result<Vec<&str>> {
    let input = CString::new(query)?;
    let result = unsafe { pg_query_split_with_parser(input.as_ptr()) };
    let split_result = if !result.error.is_null() {
        let message = unsafe { CStr::from_ptr((*result.error).message) }.to_string_lossy().to_string();
        Err(Error::Split(message))
    } else {
        let n_stmts = result.n_stmts as usize;
        let mut statements = Vec::with_capacity(n_stmts);
        for offset in 0..n_stmts {
            let split_stmt = unsafe { *result.stmts.add(offset).read() };
            let start = split_stmt.stmt_location as usize;
            let end = start + split_stmt.stmt_len as usize;
            statements.push(&query[start..end]);
            // not sure the start..end slice'll hold up for non-utf8 charsets
        }
        Ok(statements)
    };
    unsafe { pg_query_free_split_result(result) };
    split_result
}
/// Split a well-formed query into separate statements.
///
/// # Example
///
/// ```rust
/// let query = r#"select /*;*/ 1; select "2;", (select 3);"#;
/// let statements = pg_query::split_with_parser(query).unwrap();
/// assert_eq!(statements, vec!["select /*;*/ 1", r#" select "2;", (select 3)"#]);
/// ```
///
/// However, `split_with_parser` will fail on malformed statements
///
/// ```rust
/// let query = "select 1; this statement is not sql; select 2;";
/// let result = pg_query::split_with_parser(query);
/// let err = r#"syntax error at or near "this""#;
/// assert_eq!(result, Err(pg_query::Error::Split(err.to_string())));
/// ```
Split a well-formed query into separate statements.
Split a well - formed query into separate statements .
pub fn split_with_parser(query: &str) -> Result<Vec<&str>> {
    let input = CString::new(query)?;
    let result = unsafe { pg_query_split_with_parser(input.as_ptr()) };
    let split_result = if !result.error.is_null() {
        let message = unsafe { CStr::from_ptr((*result.error).message) }.to_string_lossy().to_string();
        Err(Error::Split(message))
    } else {
        let n_stmts = result.n_stmts as usize;
        let mut statements = Vec::with_capacity(n_stmts);
        for offset in 0..n_stmts {
            let split_stmt = unsafe { *result.stmts.add(offset).read() };
            let start = split_stmt.stmt_location as usize;
            let end = start + split_stmt.stmt_len as usize;
            statements.push(&query[start..end]);
            // not sure the start..end slice'll hold up for non-utf8 charsets
        }
        Ok(statements)
    };
    unsafe { pg_query_free_split_result(result) };
    split_result
}
pub fn split_with_parser ( query : & str ) -> Result < Vec < & str > > { let input = CString :: new ( query ) ? ; let result = unsafe { pg_query_split_with_parser ( input . as_ptr ( ) ) } ; let split_result = if ! result . error . is_null ( ) { let message = unsafe { CStr :: from_ptr ( ( * result . error ) . message ) } . to_string_lossy ( ) . to_string ( ) ; Err ( Error :: Split ( message ) ) } else { let n_stmts = result . n_stmts as usize ; let mut statements = Vec :: with_capacity ( n_stmts ) ; for offset in 0 .. n_stmts { let split_stmt = unsafe { * result . stmts . add ( offset ) . read ( ) } ; let start = split_stmt . stmt_location as usize ; let end = start + split_stmt . stmt_len as usize ; statements . push ( & query [ start .. end ] ) ; // not sure the start..end slice'll hold up for non-utf8 charsets } Ok ( statements ) } ; unsafe { pg_query_free_split_result ( result ) } ; split_result }
Split a well-formed query into separate statements.
Split a well - formed query into separate statements .
query
&str
query
&str
example


However, `split_with_parser` will fail on malformed statements

```rust
let query = "select 1; this statement is not sql; select 2;";
let result = pg_query::split_with_parser(query);
let err = r#"syntax error at or near "this""#;
assert_eq!(result, Err(pg_query::Error::Split(err.to_string())));
```
However ` split_with_parser ` will fail on malformed statements ` ` ` rust let query = " select 1 ; this statement is not sql ; select 2 ; " ; let result = pg_query :: split_with_parser ( query ) ; let err = r# " syntax error at or near " this " " # ; assert_eq! ( result Err ( pg_query :: Error :: Split ( err . to_string () ))) ; ` ` `