pub fn initialize() -> Result<()>
Expand description

Initialize gexiv2.

This must be called in a thread-safe fashion before using rexiv2. The library may appear to work without calling this, but some features such as HEIC/BMFF will silently fail, and the underlying libraries make the assumption that this will be called so it is safer to do so.

Calling it first thing in the main function should ensure that it is executed on the main thread and is thread safe. Do not call it in a threaded or async context (such as in a tokio context).

See also

Associated Gexiv2 source code: https://gitlab.gnome.org/GNOME/gexiv2/-/blob/e4d65b31cd77f28ef248117e161de9d8cc31d712/gexiv2/gexiv2-startup.cpp#L14

Examples

It is normally sufficient to simply call the function in the usual obvious way:

fn main() {
    rexiv2::initialize().expect("Unable to initialize rexiv2");
}

However if you have a more complex multi-threaded environment, you might want to ensure the function only gets set up once:

use std::sync::Once;

fn main() {
    static START: Once = Once::new();

    START.call_once(|| unsafe {
        rexiv2::initialize().expect("Unable to initialize rexiv2");
    });
}