notcurses/rust/examples/direct-image-rust.rs
joseLuís b12abeddc9 rust: finish NcDirect error system refactor
- change Option return type for NcResult when appropriate.
- make NcDirect constructors return NcResult.
- rename NcError::new() to with_msg() and simplify new().
- refactor examples:
  - rename direct-image.rs to direct-image-c.rs
  - recreate using rust methods, as direct-image-rust.rs
  - differentiate more throughly between both styles.
  - remove the sys namespace on both examples.
2020-12-25 17:41:02 +01:00

33 lines
798 B
Rust

//! Example 'direct-image'
//!
//! Explore image rendering in direct mode
//!
//! NOTE: This example uses the Rust style with methods.
use libnotcurses_sys::*;
fn main() -> NcResult<()> {
let ncd = NcDirect::new()?;
render_image(ncd, NCBLIT_1x1)?;
render_image(ncd, NCBLIT_2x1)?;
render_image(ncd, NCBLIT_BRAILLE)?;
ncd.stop()?;
Ok(())
}
fn render_image(ncd: &mut NcDirect, blit: NcBlitter) -> NcResult<()>{
if let Err(nc_error) = ncd.render_image(
"image-16x16.png",
NCALIGN_CENTER,
blit,
NCSCALE_NONE,
) {
return Err(NcError::with_msg(nc_error.int,
"ERROR: ncdirect_render_image(). Make sure you \
are running this example from the examples folder"));
}
Ok(())
}