Skip to content

Commit

Permalink
gtk: add a check on StringFilter::[new|set_expression]
Browse files Browse the repository at this point in the history
StringFilter's expression must be either NULL or evaluate to a string
  • Loading branch information
bilelmoussaoui committed Mar 22, 2021
1 parent f3749c2 commit 5b01b58
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gtk4/src/string_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ impl StringFilter {
#[doc(alias = "gtk_string_filter_new")]
pub fn new<E: AsRef<Expression>>(expression: Option<&E>) -> StringFilter {
assert_initialized_main_thread!();
if let Some(e) = expression {
if !e.as_ref().get_value_type().is_a(glib::Type::STRING) {
panic!("StringFilter::new must take either None or an expression that evaluates to a string.");
}
}
unsafe {
from_glib_full(ffi::gtk_string_filter_new(
expression.map(|e| e.as_ref()).to_glib_full(),
Expand All @@ -16,6 +21,11 @@ impl StringFilter {

#[doc(alias = "gtk_string_filter_set_expression")]
pub fn set_expression<E: AsRef<Expression>>(&self, expression: Option<&E>) {
if let Some(e) = expression {
if !e.as_ref().get_value_type().is_a(glib::Type::STRING) {
panic!("StringFilter::set_expression must take either None or an expression that evaluates to a string.");
}
}
unsafe {
ffi::gtk_string_filter_set_expression(
self.to_glib_none().0,
Expand Down

0 comments on commit 5b01b58

Please sign in to comment.