Function sibyl::env

source ·
pub fn env() -> Result<Environment>
Expand description

Returns a new environment handle, which is then used by the OCI functions.

While there can be multiple environments, most applications most likely will need only one.

As nothing can outlive its environment, when only one environment is used, it might be created either in the main function:

use sibyl as oracle; // pun intended :)
fn main() {
    let oracle = oracle::env().expect("Oracle OCI environment");
    // ...
}

and passed around, or it might be created statically:

use sibyl::{Environment, Result};
use once_cell::sync::OnceCell;

fn oracle() -> Result<&'static Environment> {
    static OCI_ENV: OnceCell<Environment> = OnceCell::new();
    OCI_ENV.get_or_try_init(||
        sibyl::env()
    )
}

fn main() -> Result<()> {
    let oracle = oracle()?;
    // ...
    Ok(())
}