Skip to content

Commit

Permalink
refactor: Omit unnecessary type casts on same types
Browse files Browse the repository at this point in the history
  • Loading branch information
AiyionPrime committed Jun 26, 2024
1 parent b6648bb commit 59a1c06
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub mod debug {
let mut hex_line = format!("{:08x}: ", 0);

for (i, b) in buf.iter().enumerate() {
let value = *b as u8;
let value = { *b };
if i > 0 && i % line_len == 0 {
trace!(target: "hex", "{} {}", hex_line, char_line);
hex_line = format!("{:08}: ", i);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/server/address_space/address_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl AddressSpace {
);
self.set_variable_value(
Server_ServerCapabilities_MinSupportedSampleRate,
constants::MIN_SAMPLING_INTERVAL as f64,
constants::MIN_SAMPLING_INTERVAL,
&now,
&now,
);
Expand Down
7 changes: 1 addition & 6 deletions lib/src/server/address_space/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,7 @@ impl Variable {
if let Some(ref array_dimensions) = array.dimensions {
// Multidimensional arrays encode/decode dimensions with Int32 in Part 6, but arrayDimensions in Part 3
// wants them as u32. Go figure... So convert Int32 to u32
Some(
array_dimensions
.iter()
.map(|v| *v as u32)
.collect::<Vec<u32>>(),
)
Some(array_dimensions.iter().map(|v| *v).collect::<Vec<u32>>())
} else {
Some(vec![array.values.len() as u32])
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ impl Server {
"opc.tcp://{}:{}",
config.tcp_config.host, config.tcp_config.port
);
let max_subscriptions = config.limits.max_subscriptions as usize;
let max_monitored_items_per_sub = config.limits.max_monitored_items_per_sub as usize;
let max_monitored_item_queue_size = config.limits.max_monitored_item_queue_size as usize;
let max_subscriptions = config.limits.max_subscriptions;
let max_monitored_items_per_sub = config.limits.max_monitored_items_per_sub;
let max_monitored_item_queue_size = config.limits.max_monitored_item_queue_size;

let diagnostics = Arc::new(RwLock::new(ServerDiagnostics::default()));
let min_publishing_interval_ms = config.limits.min_publishing_interval * 1000.0;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/types/node_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl From<i32> for Identifier {

impl From<u32> for Identifier {
fn from(v: u32) -> Self {
Identifier::Numeric(v as u32)
Identifier::Numeric(v)
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/types/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ impl fmt::Display for Variant {
impl Variant {
/// Test the flag (convenience method)
pub fn test_encoding_flag(encoding_mask: u8, flag: u8) -> bool {
encoding_mask == flag as u8
encoding_mask == flag
}

/// Returns the length of just the value, not the encoding flag
Expand Down Expand Up @@ -1189,7 +1189,7 @@ impl Variant {
Variant::StatusCode(v) => match target_type {
VariantTypeId::Int32 => (v.bits() as i32).into(),
VariantTypeId::Int64 => (v.bits() as i64).into(),
VariantTypeId::UInt32 => (v.bits() as u32).into(),
VariantTypeId::UInt32 => v.bits().into(),
VariantTypeId::UInt64 => (v.bits() as u64).into(),
_ => Variant::Empty,
},
Expand Down Expand Up @@ -1637,7 +1637,7 @@ impl Variant {
} else {
max
};
let values = &values[min as usize..=max];
let values = &values[min..=max];
let values: Vec<Variant> = values.to_vec();
Ok(Variant::from((array.value_type, values)))
}
Expand Down
4 changes: 2 additions & 2 deletions samples/simple-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn add_example_variables(server: &mut Server, ns: u16) {
// Add some variables to our sample folder. Values will be overwritten by the timer
let _ = address_space.add_variables(
vec![
Variable::new(&v1_node, "v1", "v1", 0 as i32),
Variable::new(&v1_node, "v1", "v1", 0_i32),
Variable::new(&v2_node, "v2", "v2", false),
Variable::new(&v3_node, "v3", "v3", UAString::from("")),
Variable::new(&v4_node, "v4", "v4", 0f64),
Expand Down Expand Up @@ -118,7 +118,7 @@ fn add_example_variables(server: &mut Server, ns: u16) {
data.1 = !data.1;
let mut address_space = address_space.write();
let now = DateTime::now();
let _ = address_space.set_variable_value(v1_node.clone(), data.0 as i32, &now, &now);
let _ = address_space.set_variable_value(v1_node.clone(), data.0, &now, &now);
let _ = address_space.set_variable_value(v2_node.clone(), data.1, &now, &now);
});
}
Expand Down

0 comments on commit 59a1c06

Please sign in to comment.