Skip to content

Commit aa08382

Browse files
committed
fix nullability of return types
1 parent df76770 commit aa08382

24 files changed

+72
-87
lines changed

examples/src/date_time_picker_view.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ mod imp {
7171
let time_format = granite::date_time_get_default_time_format(
7272
settings.enum_("clock-format") == 1,
7373
false,
74-
)
75-
.expect("Unable to get default time format");
74+
);
7675

7776
let current_time = gtk::Label::builder()
7877
.label(
@@ -88,9 +87,7 @@ mod imp {
8887
.halign(gtk::Align::End)
8988
.build();
9089

91-
let date_format = granite::date_time_get_default_date_format(true, true, true)
92-
.expect("Unable to get default date format");
93-
90+
let date_format = granite::date_time_get_default_date_format(true, true, true);
9491
let current_date = gtk::Label::builder()
9592
.label(
9693
now.format(date_format.as_str())
@@ -164,8 +161,7 @@ impl DateTimePickerView {
164161
.date_picker
165162
.upgrade()
166163
.expect("Unable to get date picker")
167-
.date()
168-
.expect("Unable to get date from date picker");
164+
.date();
169165

170166
selected_datetime = selected_datetime
171167
.add_hours(
@@ -174,7 +170,6 @@ impl DateTimePickerView {
174170
.upgrade()
175171
.expect("Unable to get time picker")
176172
.time()
177-
.expect("Unable to get time from time picker")
178173
.hour(),
179174
)
180175
.expect("Unable to add hours to time");
@@ -186,7 +181,6 @@ impl DateTimePickerView {
186181
.upgrade()
187182
.expect("Unable to get time picker")
188183
.time()
189-
.expect("Unable to get time from time picker")
190184
.minute(),
191185
)
192186
.expect("Unable to add minutes to time");
@@ -195,11 +189,7 @@ impl DateTimePickerView {
195189
.relative_datetime
196190
.upgrade()
197191
.expect("Unable to get relative datetime label")
198-
.set_label(
199-
granite::date_time_get_relative_datetime(&selected_datetime)
200-
.expect("Unable to format relative datetime")
201-
.as_str(),
202-
);
192+
.set_label(granite::date_time_get_relative_datetime(&selected_datetime).as_str());
203193
}
204194
}
205195

examples/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn build_ui(app: &Application) {
6969
.bidirectional()
7070
.build();
7171

72-
let granite_settings = granite::Settings::default().unwrap();
72+
let granite_settings = granite::Settings::default();
7373
gtk_settings.set_gtk_application_prefer_dark_theme(
7474
granite_settings.prefers_color_scheme() == granite::SettingsColorScheme::Dark,
7575
);

examples/src/settings_view/simple_settings_page.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ mod imp {
5050
.placeholder_text("This page's description")
5151
.build();
5252

53-
let content_area = obj.content_area().expect("Couldn't get content area");
53+
let content_area = obj.content_area();
5454
content_area.attach(&icon_label, 0, 0, 1, 1);
5555
content_area.attach(&icon_entry, 1, 0, 1, 1);
5656
content_area.attach(&title_label, 0, 1, 1, 1);
@@ -59,7 +59,7 @@ mod imp {
5959
content_area.attach(&description_entry, 1, 2, 1, 1);
6060

6161
let button = gtk::Button::with_label("Test Button");
62-
let action_area = obj.action_area().expect("Couldn't get action area");
62+
let action_area = obj.action_area();
6363
action_area.append(&button);
6464

6565
obj.update_status();

examples/src/welcome_view.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,17 @@ mod imp {
2626
.description("This is a demo of the Granite library")
2727
.build();
2828

29-
let vala_button = welcome
30-
.append_button(
31-
&gio::ThemedIcon::new("text-x-vala"),
32-
"Visit Valadoc",
33-
"The canonical source for Vala API references",
34-
)
35-
.unwrap();
36-
37-
let source_button = welcome
38-
.append_button(
39-
&gio::ThemedIcon::new("text-x-source"),
40-
"Get Granite Source",
41-
"Granite's source code is hosted on GitHub",
42-
)
43-
.unwrap();
29+
let vala_button = welcome.append_button(
30+
&gio::ThemedIcon::new("text-x-vala"),
31+
"Visit Valadoc",
32+
"The canonical source for Vala API references",
33+
);
34+
35+
let source_button = welcome.append_button(
36+
&gio::ThemedIcon::new("text-x-source"),
37+
"Get Granite Source",
38+
"Granite's source code is hosted on GitHub",
39+
);
4440

4541
let alert = granite::Placeholder::builder()
4642
.title("Panic! At the button")
@@ -49,13 +45,11 @@ mod imp {
4945
.build();
5046
alert.add_css_class(granite::STYLE_CLASS_WARNING);
5147

52-
let alert_action = alert
53-
.append_button(
54-
&gio::ThemedIcon::new("edit-delete"),
55-
"Hide This Button",
56-
"Click here to hide this",
57-
)
58-
.unwrap();
48+
let alert_action = alert.append_button(
49+
&gio::ThemedIcon::new("edit-delete"),
50+
"Hide This Button",
51+
"Click here to hide this",
52+
);
5953
alert_action.set_widget_name("alert_button");
6054

6155
let search_placeholder = granite::Placeholder::builder()

granite/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "granite-rs"
3-
version = "1.4.0"
3+
version = "2.0.0"
44
edition = "2021"
55
authors = ["David Hewitt <davidmhewitt@gmail.com>"]
66
readme = "../README.md"

granite/Gir.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ single_version_file = true
99
generate_safety_asserts = true
1010
deprecate_by_min_version = true
1111
generate_builder = true
12+
trust_return_value_nullability = true
1213

1314
generate = [
1415
"Granite.*",

granite/src/auto/accel_label.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl AccelLabelBuilder {
312312
pub trait AccelLabelExt: IsA<AccelLabel> + 'static {
313313
#[doc(alias = "granite_accel_label_get_action_name")]
314314
#[doc(alias = "get_action_name")]
315-
fn action_name(&self) -> Option<glib::GString> {
315+
fn action_name(&self) -> glib::GString {
316316
unsafe {
317317
from_glib_none(ffi::granite_accel_label_get_action_name(
318318
self.as_ref().to_glib_none().0,
@@ -352,7 +352,7 @@ pub trait AccelLabelExt: IsA<AccelLabel> + 'static {
352352

353353
#[doc(alias = "granite_accel_label_get_label")]
354354
#[doc(alias = "get_label")]
355-
fn label(&self) -> Option<glib::GString> {
355+
fn label(&self) -> glib::GString {
356356
unsafe {
357357
from_glib_none(ffi::granite_accel_label_get_label(
358358
self.as_ref().to_glib_none().0,

granite/src/auto/date_picker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl DatePickerBuilder {
557557
pub trait DatePickerExt: IsA<DatePicker> + 'static {
558558
#[doc(alias = "granite_date_picker_get_format")]
559559
#[doc(alias = "get_format")]
560-
fn format(&self) -> Option<glib::GString> {
560+
fn format(&self) -> glib::GString {
561561
unsafe {
562562
from_glib_none(ffi::granite_date_picker_get_format(
563563
self.as_ref().to_glib_none().0,
@@ -567,7 +567,7 @@ pub trait DatePickerExt: IsA<DatePicker> + 'static {
567567

568568
#[doc(alias = "granite_date_picker_get_date")]
569569
#[doc(alias = "get_date")]
570-
fn date(&self) -> Option<glib::DateTime> {
570+
fn date(&self) -> glib::DateTime {
571571
unsafe {
572572
from_glib_none(ffi::granite_date_picker_get_date(
573573
self.as_ref().to_glib_none().0,

granite/src/auto/dialog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pub trait DialogExt: IsA<Dialog> + 'static {
396396
#[cfg(feature = "v7_5")]
397397
#[cfg_attr(docsrs, doc(cfg(feature = "v7_5")))]
398398
#[doc(alias = "granite_dialog_add_button")]
399-
fn add_button(&self, button_text: &str, response_id: i32) -> Option<gtk::Widget> {
399+
fn add_button(&self, button_text: &str, response_id: i32) -> gtk::Widget {
400400
unsafe {
401401
from_glib_none(ffi::granite_dialog_add_button(
402402
self.as_ref().to_glib_none().0,

granite/src/auto/functions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ffi;
77
use glib::{prelude::*, translate::*};
88

99
#[doc(alias = "granite_date_time_get_default_time_format")]
10-
pub fn date_time_get_default_time_format(is_12h: bool, with_second: bool) -> Option<glib::GString> {
10+
pub fn date_time_get_default_time_format(is_12h: bool, with_second: bool) -> glib::GString {
1111
assert_initialized_main_thread!();
1212
unsafe {
1313
from_glib_full(ffi::granite_date_time_get_default_time_format(
@@ -18,7 +18,7 @@ pub fn date_time_get_default_time_format(is_12h: bool, with_second: bool) -> Opt
1818
}
1919

2020
#[doc(alias = "granite_date_time_get_relative_datetime")]
21-
pub fn date_time_get_relative_datetime(date_time: &glib::DateTime) -> Option<glib::GString> {
21+
pub fn date_time_get_relative_datetime(date_time: &glib::DateTime) -> glib::GString {
2222
assert_initialized_main_thread!();
2323
unsafe {
2424
from_glib_full(ffi::granite_date_time_get_relative_datetime(
@@ -43,7 +43,7 @@ pub fn date_time_get_default_date_format(
4343
with_weekday: bool,
4444
with_day: bool,
4545
with_year: bool,
46-
) -> Option<glib::GString> {
46+
) -> glib::GString {
4747
assert_initialized_main_thread!();
4848
unsafe {
4949
from_glib_full(ffi::granite_date_time_get_default_date_format(
@@ -55,7 +55,7 @@ pub fn date_time_get_default_date_format(
5555
}
5656

5757
#[doc(alias = "granite_date_time_seconds_to_time")]
58-
pub fn date_time_seconds_to_time(seconds: i32) -> Option<glib::GString> {
58+
pub fn date_time_seconds_to_time(seconds: i32) -> glib::GString {
5959
assert_initialized_main_thread!();
6060
unsafe { from_glib_full(ffi::granite_date_time_seconds_to_time(seconds)) }
6161
}
@@ -107,13 +107,13 @@ pub fn init() {
107107
}
108108

109109
#[doc(alias = "granite_accel_to_string")]
110-
pub fn accel_to_string(accel: Option<&str>) -> Option<glib::GString> {
110+
pub fn accel_to_string(accel: Option<&str>) -> glib::GString {
111111
assert_initialized_main_thread!();
112112
unsafe { from_glib_full(ffi::granite_accel_to_string(accel.to_glib_none().0)) }
113113
}
114114

115115
#[doc(alias = "granite_markup_accel_tooltip")]
116-
pub fn markup_accel_tooltip(accels: &[&str], description: Option<&str>) -> Option<glib::GString> {
116+
pub fn markup_accel_tooltip(accels: &[&str], description: Option<&str>) -> glib::GString {
117117
assert_initialized_main_thread!();
118118
let accels_length1 = accels.len() as _;
119119
unsafe {

0 commit comments

Comments
 (0)