Skip to content

Commit 8454d66

Browse files
committed
chromium_mod: First convert then slice
More efficient. Highlighted by new clippy lint: ``` error: calling `as_bytes` after slicing a string --> framework_lib/src/chromium_ec/mod.rs:919:45 | 919 | request.name[..end].copy_from_slice(name[..end].as_bytes()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&name.as_bytes()[..end]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#sliced_string_as_bytes = note: `-D clippy::sliced-string-as-bytes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::sliced_string_as_bytes)]` ``` Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 4aa392a commit 8454d66

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • framework_lib/src/chromium_ec

framework_lib/src/chromium_ec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ impl CrosEc {
916916
let mut request = EcRequestGpioGetV0 { name: [0; MAX_LEN] };
917917

918918
let end = MAX_LEN.min(name.len());
919-
request.name[..end].copy_from_slice(name[..end].as_bytes());
919+
request.name[..end].copy_from_slice(&name.as_bytes()[..end]);
920920

921921
let res = request.send_command(self)?;
922922
Ok(res.val == 1)

0 commit comments

Comments
 (0)