Replace u32::from with .into() for idiomatic Rust
This commit is contained in:
+17
-17
@@ -87,7 +87,7 @@ impl BmsReadable for ProtocolVersion {
|
|||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
let transit = Transit_U26::from_be_bytes(version)?;
|
let transit = Transit_U26::from_be_bytes(version)?;
|
||||||
Ok(ProtocolVersion(u32::from(transit)))
|
Ok(ProtocolVersion(transit.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ impl BmsReadable for FirmwareVersion {
|
|||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
let transit = Transit_U26::from_be_bytes(version)?;
|
let transit = Transit_U26::from_be_bytes(version)?;
|
||||||
Ok(FirmwareVersion(u32::from(transit)))
|
Ok(FirmwareVersion(transit.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,9 +142,9 @@ impl BmsReadable for Config {
|
|||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
capacity_mah: u32::from(Transit_U26::from_be_bytes(capacity_mah)?),
|
capacity_mah: Transit_U26::from_be_bytes(capacity_mah)?.into(),
|
||||||
v_full_mv: u32::from(Transit_U26::from_be_bytes(v_full_mv)?),
|
v_full_mv: Transit_U26::from_be_bytes(v_full_mv)?.into(),
|
||||||
v_empty_mv: u32::from(Transit_U26::from_be_bytes(v_empty_mv)?),
|
v_empty_mv: Transit_U26::from_be_bytes(v_empty_mv)?.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,11 +182,11 @@ impl BmsReadable for BatteryState {
|
|||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
Ok(BatteryState {
|
Ok(BatteryState {
|
||||||
lifetime_capacity_mah: u32::from(Transit_U26::from_be_bytes(lifetime_capacity_mah)?),
|
lifetime_capacity_mah: Transit_U26::from_be_bytes(lifetime_capacity_mah)?.into(),
|
||||||
remaining_capacity_mah: u32::from(Transit_U26::from_be_bytes(remaining_capacity_mah)?),
|
remaining_capacity_mah: Transit_U26::from_be_bytes(remaining_capacity_mah)?.into(),
|
||||||
current_mv: u32::from(Transit_U26::from_be_bytes(current_mv)?),
|
current_mv: Transit_U26::from_be_bytes(current_mv)?.into(),
|
||||||
temperature_celcius: i32::from_be_bytes(temperature_celcius),
|
temperature_celcius: i32::from_be_bytes(temperature_celcius),
|
||||||
health_percent: u32::from(Transit_U26::from_be_bytes(health_percent)?),
|
health_percent: Transit_U26::from_be_bytes(health_percent)?.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,9 +209,9 @@ impl BmsReadable for ChargeInfoWindowSec {
|
|||||||
Operation::Read(&mut charge_info_window_sec),
|
Operation::Read(&mut charge_info_window_sec),
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
Ok(ChargeInfoWindowSec(u32::from(Transit_U26::from_be_bytes(
|
Ok(ChargeInfoWindowSec(
|
||||||
charge_info_window_sec,
|
Transit_U26::from_be_bytes(charge_info_window_sec)?.into(),
|
||||||
)?)))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,11 +266,11 @@ impl BmsReadable for ChargeInfo {
|
|||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
Ok(ChargeInfo {
|
Ok(ChargeInfo {
|
||||||
total_charge_ma: u32::from(Transit_U26::from_be_bytes(total_charge_ma)?),
|
total_charge_ma: Transit_U26::from_be_bytes(total_charge_ma)?.into(),
|
||||||
total_discharge_ma: u32::from(Transit_U26::from_be_bytes(total_discharge_ma)?),
|
total_discharge_ma: Transit_U26::from_be_bytes(total_discharge_ma)?.into(),
|
||||||
max_charge_mw: u32::from(Transit_U26::from_be_bytes(max_charge_mw)?),
|
max_charge_mw: Transit_U26::from_be_bytes(max_charge_mw)?.into(),
|
||||||
max_discharge_mw: u32::from(Transit_U26::from_be_bytes(max_discharge_mw)?),
|
max_discharge_mw: Transit_U26::from_be_bytes(max_discharge_mw)?.into(),
|
||||||
avg_voltage_mv: u32::from(Transit_U26::from_be_bytes(avg_voltage_mv)?),
|
avg_voltage_mv: Transit_U26::from_be_bytes(avg_voltage_mv)?.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user