Skip to content

Commit d71e367

Browse files
author
Deren Vural
committed
Refactored property() function
Updated MainWindow class - Updated property function to use match not expect Updated Processor class: - Updated property function to use match not expect Updated Property class: - Updated property function to use match not expect Updated Provider class: - Updated property function to use match not expect Signed-off-by: Deren Vural <[email protected]>
1 parent b627c77 commit d71e367

File tree

4 files changed

+90
-56
lines changed

4 files changed

+90
-56
lines changed

src/mainwindow/imp.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,12 @@ impl ObjectImpl for MainWindow {
700700

701701
match pspec.name() {
702702
"provider" => {
703-
let input_provider_property: Option<Provider> = value
704-
.get()
705-
.expect("The value needs to be of type `Provider`.");
706-
self.provider.replace(input_provider_property);
703+
match value.get() {
704+
Ok(input_provider_property) => {
705+
self.provider.replace(input_provider_property);
706+
},
707+
Err(_) => panic!("The value needs to be of type `Provider`."),
708+
}
707709
}
708710
_ => panic!("Property `{}` does not exist..", pspec.name())
709711
}

src/processor/imp.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,28 @@ impl ObjectImpl for Processor {
123123

124124
match pspec.name() {
125125
"base-call" => {
126-
let input_base_call = value
127-
.get()
128-
.expect("The value needs to be of type `String`.");
129-
self.base_call.replace(input_base_call);
126+
match value.get() {
127+
Ok(input_base_call) => {
128+
self.base_call.replace(input_base_call);
129+
},
130+
Err(_) => panic!("The value needs to be of type `String`."),
131+
}
130132
}
131133
"call" => {
132-
let input_call = value
133-
.get()
134-
.expect("The value needs to be of type `String`.");
135-
self.call.replace(input_call);
134+
match value.get() {
135+
Ok(input_call) => {
136+
self.call.replace(input_call);
137+
},
138+
Err(_) => panic!("The value needs to be of type `String`."),
139+
}
136140
}
137141
"tail-call" => {
138-
let input_tail_call = value
139-
.get()
140-
.expect("The value needs to be of type `String`.");
141-
self.tail_call.replace(input_tail_call);
142+
match value.get() {
143+
Ok(input_tail_call) => {
144+
self.tail_call.replace(input_tail_call);
145+
},
146+
Err(_) => panic!("The value needs to be of type `String`."),
147+
}
142148
}
143149
_ => panic!("Property `{}` does not exist..", pspec.name())
144150
}

src/property/imp.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,34 +119,44 @@ impl ObjectImpl for Property {
119119

120120
match pspec.name() {
121121
"icon" => {
122-
let input_icon = value
123-
.get()
124-
.expect("The value needs to be of type `String`.");
125-
self.icon.replace(input_icon);
122+
match value.get() {
123+
Ok(input_icon) => {
124+
self.icon.replace(input_icon);
125+
},
126+
Err(_) => panic!("The value needs to be of type `String`."),
127+
}
126128
}
127129
"gpu-count" => {
128-
let input_gpu_count = value
129-
.get()
130-
.expect("The value needs to be of type `i32`.");
131-
self.gpu_count.replace(input_gpu_count);
130+
match value.get() {
131+
Ok(input_gpu_count) => {
132+
self.gpu_count.replace(input_gpu_count);
133+
},
134+
Err(_) => panic!("The value needs to be of type `i32`."),
135+
}
132136
}
133137
"call-extension" => {
134-
let input_call_extension = value
135-
.get()
136-
.expect("The value needs to be of type `String`.");
137-
self.call_extension.replace(input_call_extension);
138+
match value.get() {
139+
Ok(input_call_extension) => {
140+
self.call_extension.replace(input_call_extension);
141+
},
142+
Err(_) => panic!("The value needs to be of type `String`."),
143+
}
138144
}
139145
"processor" => {
140-
let input_processor = value
141-
.get()
142-
.expect("The value needs to be of type `Processor`.");
143-
self.processor.replace(input_processor);
146+
match value.get() {
147+
Ok(input_processor) => {
148+
self.processor.replace(input_processor);
149+
},
150+
Err(_) => panic!("The value needs to be of type `Processor`."),
151+
}
144152
}
145153
"formatter" => {
146-
let input_formatter = value
147-
.get()
148-
.expect("The value needs to be of type `Formatter`.");
149-
self.formatter.replace(input_formatter);
154+
match value.get() {
155+
Ok(input_formatter) => {
156+
self.formatter.replace(input_formatter);
157+
},
158+
Err(_) => panic!("The value needs to be of type `Formatter`."),
159+
}
150160
}
151161
_ => panic!("Property `{}` does not exist..", pspec.name())
152162
}

src/provider/imp.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,40 +128,56 @@ impl ObjectImpl for Provider {
128128

129129
match pspec.name() {
130130
"utilization-property" => {
131-
let input_utilization_property = value
132-
.get()
133-
.expect("The value needs to be of type `Property`.");
134-
self.utilization.replace(input_utilization_property);
131+
match value.get() {
132+
Ok(input_utilization_property) => {
133+
self.utilization.replace(input_utilization_property);
134+
},
135+
Err(_) => panic!("The value needs to be of type `Property`."),
136+
}
135137
}
136138
"temperature-property" => {
139+
match value.get() {
140+
Ok(input_temperature_property) => {
141+
self.temperature.replace(input_temperature_property);
142+
},
143+
Err(_) => panic!("The value needs to be of type `Property`."),
144+
}
137145
let input_temperature_property = value
138146
.get()
139147
.expect("The value needs to be of type `Property`.");
140148
self.temperature.replace(input_temperature_property);
141149
}
142150
"memory-usage-property" => {
143-
let input_memory_usage_property = value
144-
.get()
145-
.expect("The value needs to be of type `Property`.");
146-
self.memory_usage.replace(input_memory_usage_property);
151+
match value.get() {
152+
Ok(input_memory_usage_property) => {
153+
self.memory_usage.replace(input_memory_usage_property);
154+
},
155+
Err(_) => panic!("The value needs to be of type `Property`."),
156+
}
147157
}
148158
"fan-speed-property" => {
149-
let input_fan_speed_property = value
150-
.get()
151-
.expect("The value needs to be of type `Property`.");
152-
self.fan_speed.replace(input_fan_speed_property);
159+
match value.get() {
160+
Ok(input_fan_speed_property) => {
161+
self.fan_speed.replace(input_fan_speed_property);
162+
},
163+
Err(_) => panic!("The value needs to be of type `Property`."),
164+
}
153165
}
154166
"power-usage-property" => {
155-
let input_power_usage_property = value
156-
.get()
157-
.expect("The value needs to be of type `Property`.");
158-
self.power_usage.replace(input_power_usage_property);
167+
match value.get() {
168+
Ok(input_power_usage_property) => {
169+
self.power_usage.replace(input_power_usage_property);
170+
},
171+
Err(_) => panic!("The value needs to be of type `Property`."),
172+
}
159173
}
160174
"provider-type" => {
161-
let input_provider_type_property = value
162-
.get()
163-
.expect("The value needs to be of type `i32`.");
164-
self.provider_type.replace(input_provider_type_property);
175+
match value.get() {
176+
Ok(input_provider_type_property) => {
177+
self.provider_type.replace(input_provider_type_property);
178+
},
179+
Err(_) => panic!("The value needs to be of type `i32`."),
180+
}
165181
}
166182
_ => panic!("Property `{}` does not exist..", pspec.name())
167183
}

0 commit comments

Comments
 (0)