From cfd887d2abbfa23458747f7bdd6ce1cbfcae458f Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Tue, 25 Apr 2017 22:35:29 +0300 Subject: [PATCH] Add capacity_with_nul to ImString --- src/input.rs | 4 +--- src/string.rs | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/input.rs b/src/input.rs index a0fa03e..e784398 100644 --- a/src/input.rs +++ b/src/input.rs @@ -152,10 +152,8 @@ impl<'ui, 'p> InputText<'ui, 'p> { pub fn build(self) -> bool { unsafe { imgui_sys::igInputText(self.label.as_ptr(), - // TODO: this is evil. - // Perhaps something else than &mut str is better self.buf.as_ptr() as *mut i8, - self.buf.capacity() + 1, + self.buf.capacity_with_nul(), self.flags, None, ptr::null_mut()) diff --git a/src/string.rs b/src/string.rs index 1af1c5b..8cc1dd0 100644 --- a/src/string.rs +++ b/src/string.rs @@ -35,6 +35,7 @@ impl ImString { self.0.push(b'\0'); } pub fn capacity(&self) -> usize { self.0.capacity() - 1 } + pub fn capacity_with_nul(&self) -> usize { self.0.capacity() } pub fn reserve(&mut self, additional: usize) { self.0.reserve(additional); }