Skip to main content

sqlite3_match_version

Macro sqlite3_match_version 

Source
macro_rules! sqlite3_match_version {
    (@modern ($($body:tt)*) $ver:literal => { $($block:tt)* } $($tail:tt)* ) => { ... };
    (@old $ver:literal => { $($block:tt)* } $($tail:tt)* ) => { ... };
    (@modern ($($body:tt)*) $ver:literal => $expr:expr, $($tail:tt)* ) => { ... };
    (@old $ver:literal => $expr:expr, $($tail:tt)* ) => { ... };
    (@modern ($($body:tt)*) $ver:literal => $expr:expr ) => { ... };
    (@old $ver:literal => $expr:expr ) => { ... };
    (@modern ($($body:tt)*) _ => $expr:expr $(,)? ) => { ... };
    (@old _ => $expr:expr $(,)? ) => { ... };
    (@modern ($($body:tt)*) , $($tail:tt)* ) => { ... };
    (@old , $($tail:tt)* ) => { ... };
    (@verify $version:literal) => { ... };
    ( $x:literal => $($tail:tt)* ) => { ... };
}
Expand description

Selectively enable features which require a particular SQLite version.

This macro mimics a match expression, except each pattern is a minimum supported version rather than an exact match. It performs a check for the given SQLite version both at compile time and at runtime. If both checks pass, the expression is evaluated, otherwise the following match arms are checked.

The minimum supported version of SQLite is 3.6.8. It is a compile error to attempt to match against an older version of SQLite using this macro (this helps avoid typos where digits are accidentally omitted from a version number).

This macro is particularly useful when interacting with ffi methods, since these may be missing on older versions of SQLite, which would cause a compilation error.

A fallback arm is always required when using this macro. For cases where no fallback is possible, use sqlite3_require_version.

§Examples

use sqlite3_ext::{sqlite3_match_version, ffi};
use std::ffi::c_void;

fn alloc_memory_with_sqlite3(len: usize) -> *mut c_void {
    unsafe {
        sqlite3_match_version! {
            3_008_007 => ffi::sqlite3_malloc64(len as _),
            _ => ffi::sqlite3_malloc(len as _),
        }
    }
}