Attribute Macro show_image::main[][src]

#[main]
Expand description

Wrap your program entry point for correct initialization of the show-image global context.

The show-image global context will run in the main thread, and your own entry point will be executed in a new thread. When your entry point returns, the whole process will exit.

Any background tasks spawned by show-image will be joined before the process terminates, but any threads spawned by user code will be killed. You should manually join those if needed.

Note that we are very sorry about stealing your main thread. We would rather let you keep the main thread and run the global context in a background thread. However, some platforms require all GUI code to run in the “main” thread (looking at you, OS X). To ensure portability, the same restriction is enforced on other platforms.

Examples

use show_image::{ContextProxy, WindowOptions};

#[show_image::main]
fn main() -> Result<(), Box<dyn Error>> {
  let window = show_image::create_window("My Awesome Window", WindowOptions::default())?;
  let image = image::open("/path/to/image.png")?;

  window.set_image("image", image)?;
  window.wait_until_destroyed()?;
  Ok(())
}