Return previous values from replace and remove

This commit is contained in:
Tad Hardesty 2018-09-19 22:27:27 -07:00
parent d202872280
commit bdbdfe58e3

View File

@ -31,7 +31,6 @@ impl From<*mut c_void> for ImTexture {
/// Create your image using the builder pattern then [`Image::build`] it. /// Create your image using the builder pattern then [`Image::build`] it.
#[must_use] #[must_use]
pub struct Image<'ui> { pub struct Image<'ui> {
/// we use Result to allow postponing any construction errors to the build call
texture_id: ImTexture, texture_id: ImTexture,
size: ImVec2, size: ImVec2,
uv0: ImVec2, uv0: ImVec2,
@ -131,13 +130,12 @@ impl<T> Textures<T> {
ImTexture(id) ImTexture(id)
} }
pub fn replace(&mut self, id: ImTexture, texture: T) { pub fn replace(&mut self, id: ImTexture, texture: T) -> Option<T> {
assert!(self.textures.contains_key(&id.0)); self.textures.insert(id.0, texture)
self.textures.insert(id.0, texture);
} }
pub fn remove(&mut self, id: ImTexture) { pub fn remove(&mut self, id: ImTexture) -> Option<T> {
self.textures.remove(&id.0); self.textures.remove(&id.0)
} }
pub fn get(&self, id: ImTexture) -> Option<&T> { pub fn get(&self, id: ImTexture) -> Option<&T> {