Skip to content

Instantly share code, notes, and snippets.

@sireliah
Last active February 23, 2019 17:04
Show Gist options
  • Select an option

  • Save sireliah/48abcf7427c07b14226a45647af7f48a to your computer and use it in GitHub Desktop.

Select an option

Save sireliah/48abcf7427c07b14226a45647af7f48a to your computer and use it in GitHub Desktop.
type ImageRef = Rc<RefCell<Option<gtk::Image>>>;
#[derive(Clone)]
struct ImageWrapper {
internal_value: ImageRef
}
impl ImageWrapper {
fn new() -> ImageWrapper {
ImageWrapper { internal_value: Rc::new(RefCell::new(None)) }
}
fn get_image(&self) -> Result<gtk::Image, &str> {
let image_wrapper = self.internal_value.borrow();
match image_wrapper.as_ref() {
Some(image) => Ok(image.clone()),
None => Err("Expected an image!")
}
}
fn set_image(&self, image_gtk: gtk::Image) {
let mut image = self.internal_value.borrow_mut();
*image = Some(image_gtk);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment