static_resources.rs.in 676 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Source: https://gitlab.gnome.org/World/podcasts/blob/master/podcasts-gtk/src/static_resource.rs

use gio::{resources_register, Resource};
use glib::{Bytes, Error};

pub(crate) fn init() -> Result<(), Error> {
    // load the gresource binary at build time and include/link it into the final
    // binary.
    let res_bytes = include_bytes!(@RESOURCEFILE@);

    // Create Resource it will live as long the value lives.
    let gbytes = Bytes::from_static(res_bytes.as_ref());
Bilal Elmoussaoui's avatar
Bilal Elmoussaoui committed
13
    let resource = Resource::from_data(&gbytes)?;
14 15 16 17 18 19 20

    // Register the resource so it won't be dropped and will continue to live in
    // memory.
    resources_register(&resource);

    Ok(())
}