Skip to content

Commit 1c7f47a

Browse files
Cleanup
1 parent 00918a3 commit 1c7f47a

File tree

2 files changed

+23
-50
lines changed

2 files changed

+23
-50
lines changed

application/apps/rustcore/rs-bindings/src/js/converting/observe.rs

+17-44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
convert::{TryFrom, TryInto},
3+
ops::Not,
34
path::PathBuf,
45
};
56

@@ -88,11 +89,7 @@ fn get_stream_transport(opt: &observe::observe_origin::Stream) -> Result<factory
8889
.into_iter()
8990
.map(|mc| factory::MulticastInfo {
9091
multiaddr: mc.multiaddr,
91-
interface: if mc.interface.is_empty() {
92-
None
93-
} else {
94-
Some(mc.interface)
95-
},
92+
interface: mc.interface.is_empty().not().then_some(mc.interface),
9693
})
9794
.collect(),
9895
})
@@ -125,54 +122,30 @@ impl TryInto<factory::ObserveOptions> for JsIncomeBuffer {
125122
observe::parser_type::Type::Dlt(opt) => {
126123
factory::ParserType::Dlt(factory::DltParserSettings {
127124
filter_config: opt.filter_config.map(|opt| factory::DltFilterConfig {
128-
min_log_level: Some(
129-
if opt.min_log_level <= u8::MAX as u32
130-
&& opt.min_log_level >= u8::MIN as u32
131-
{
132-
opt.min_log_level as u8
133-
} else {
134-
0
135-
},
136-
),
125+
min_log_level: Some(u8::try_from(opt.min_log_level).unwrap_or(0)),
137126
app_id_count: opt.app_id_count,
138-
app_ids: if opt.app_ids.is_empty() {
139-
None
140-
} else {
141-
Some(opt.app_ids)
142-
},
127+
app_ids: opt.app_ids.is_empty().not().then_some(opt.app_ids),
143128
context_id_count: opt.context_id_count,
144-
context_ids: if opt.context_ids.is_empty() {
145-
None
146-
} else {
147-
Some(opt.context_ids)
148-
},
149-
ecu_ids: if opt.ecu_ids.is_empty() {
150-
None
151-
} else {
152-
Some(opt.ecu_ids)
153-
},
129+
context_ids: opt.context_ids.is_empty().not().then_some(opt.context_ids),
130+
ecu_ids: opt.ecu_ids.is_empty().not().then_some(opt.ecu_ids),
154131
}),
155-
fibex_file_paths: if opt.fibex_file_paths.is_empty() {
156-
None
157-
} else {
158-
Some(opt.fibex_file_paths)
159-
},
132+
fibex_file_paths: opt
133+
.fibex_file_paths
134+
.is_empty()
135+
.not()
136+
.then_some(opt.fibex_file_paths),
160137
with_storage_header: opt.with_storage_header,
161-
tz: if opt.tz.is_empty() {
162-
None
163-
} else {
164-
Some(opt.tz)
165-
},
138+
tz: opt.tz.is_empty().not().then_some(opt.tz),
166139
fibex_metadata: None,
167140
})
168141
}
169142
observe::parser_type::Type::SomeIp(opt) => {
170143
factory::ParserType::SomeIp(factory::SomeIpParserSettings {
171-
fibex_file_paths: if opt.fibex_file_paths.is_empty() {
172-
None
173-
} else {
174-
Some(opt.fibex_file_paths)
175-
},
144+
fibex_file_paths: opt
145+
.fibex_file_paths
146+
.is_empty()
147+
.not()
148+
.then_some(opt.fibex_file_paths),
176149
})
177150
}
178151
observe::parser_type::Type::Text(_) => factory::ParserType::Text,

application/apps/rustcore/rs-bindings/src/js/jobs/converting.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl From<CommandOutcomeWrapper<String>> for Vec<u8> {
3434
},
3535
)),
3636
})
37-
.unwrap_or(proto::CommandOutcome {
37+
.unwrap_or_else(|| proto::CommandOutcome {
3838
outcome: Some(command_outcome::Outcome::Cancelled(Cancelled {})),
3939
});
4040
prost::Message::encode_to_vec(&msg)
@@ -53,7 +53,7 @@ impl From<CommandOutcomeWrapper<Option<String>>> for Vec<u8> {
5353
},
5454
)),
5555
})
56-
.unwrap_or(proto::CommandOutcome {
56+
.unwrap_or_else(|| proto::CommandOutcome {
5757
outcome: Some(command_outcome::Outcome::Cancelled(Cancelled {})),
5858
});
5959
prost::Message::encode_to_vec(&msg)
@@ -72,7 +72,7 @@ impl From<CommandOutcomeWrapper<Vec<String>>> for Vec<u8> {
7272
},
7373
)),
7474
})
75-
.unwrap_or(proto::CommandOutcome {
75+
.unwrap_or_else(|| proto::CommandOutcome {
7676
outcome: Some(command_outcome::Outcome::Cancelled(Cancelled {})),
7777
});
7878
prost::Message::encode_to_vec(&msg)
@@ -91,7 +91,7 @@ impl From<CommandOutcomeWrapper<bool>> for Vec<u8> {
9191
},
9292
)),
9393
})
94-
.unwrap_or(proto::CommandOutcome {
94+
.unwrap_or_else(|| proto::CommandOutcome {
9595
outcome: Some(command_outcome::Outcome::Cancelled(Cancelled {})),
9696
});
9797
prost::Message::encode_to_vec(&msg)
@@ -110,7 +110,7 @@ impl From<CommandOutcomeWrapper<()>> for Vec<u8> {
110110
},
111111
)),
112112
})
113-
.unwrap_or(proto::CommandOutcome {
113+
.unwrap_or_else(|| proto::CommandOutcome {
114114
outcome: Some(command_outcome::Outcome::Cancelled(Cancelled {})),
115115
});
116116
prost::Message::encode_to_vec(&msg)
@@ -129,7 +129,7 @@ impl From<CommandOutcomeWrapper<i64>> for Vec<u8> {
129129
},
130130
)),
131131
})
132-
.unwrap_or(proto::CommandOutcome {
132+
.unwrap_or_else(|| proto::CommandOutcome {
133133
outcome: Some(command_outcome::Outcome::Cancelled(Cancelled {})),
134134
});
135135
prost::Message::encode_to_vec(&msg)

0 commit comments

Comments
 (0)