Skip to content

Commit

Permalink
Applied rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchmid committed Sep 13, 2023
1 parent ac182ad commit 7319327
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
17 changes: 4 additions & 13 deletions src/verbose/values/array_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ impl Iterator for ArrayBoolIterator<'_> {
};
self.rest = unsafe {
// SAFETY: Safe as len at least 1.
core::slice::from_raw_parts(
self.rest.as_ptr().add(1),
self.rest.len() - 1
)
core::slice::from_raw_parts(self.rest.as_ptr().add(1), self.rest.len() - 1)
};
Some(result)
}
Expand Down Expand Up @@ -162,19 +159,13 @@ impl Iterator for ArrayBoolIterator<'_> {
};
self.rest = unsafe {
// SAFETY: Safe as len at least n + 1.
core::slice::from_raw_parts(
self.rest.as_ptr().add(n + 1),
self.rest.len() - n - 1
)
core::slice::from_raw_parts(self.rest.as_ptr().add(n + 1), self.rest.len() - n - 1)
};
Some(result)
} else {
self.rest = unsafe {
// SAFETY: Safe as reduced to len 0.
core::slice::from_raw_parts(
self.rest.as_ptr().add(self.rest.len()),
0
)
core::slice::from_raw_parts(self.rest.as_ptr().add(self.rest.len()), 0)
};
None
}
Expand Down Expand Up @@ -582,7 +573,7 @@ mod test {

// test last
assert_eq!(arr.into_iter().last(), content.last().map(|v| *v != 0));

// test nth
for i in 0..content.len() {
let mut it = arr.into_iter();
Expand Down
20 changes: 6 additions & 14 deletions src/verbose/values/array_i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,19 @@ impl Iterator for ArrayI8Iterator<'_> {
#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
if n < self.rest.len() {
let result = i8::from_ne_bytes([
unsafe {
// SAFETY: Safe as the length is checked beforehand to be at least n + 1
*self.rest.get_unchecked(n)
}
]);
let result = i8::from_ne_bytes([unsafe {
// SAFETY: Safe as the length is checked beforehand to be at least n + 1
*self.rest.get_unchecked(n)
}]);
self.rest = unsafe {
// SAFETY: Safe as the length is checked beforehand to be at least n + 1
core::slice::from_raw_parts(
self.rest.as_ptr().add(n + 1),
self.rest.len() - n - 1
)
core::slice::from_raw_parts(self.rest.as_ptr().add(n + 1), self.rest.len() - n - 1)
};
Some(result)
} else {
self.rest = unsafe {
// SAFETY: Safe as the length is checked beforehand to be at least n + 1
core::slice::from_raw_parts(
self.rest.as_ptr().add(self.rest.len()),
0
)
core::slice::from_raw_parts(self.rest.as_ptr().add(self.rest.len()), 0)
};
None
}
Expand Down
14 changes: 4 additions & 10 deletions src/verbose/values/array_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Iterator for ArrayU8Iterator<'_> {
core::slice::from_raw_parts(
// SAFETY: Safe as has at least one element.
self.rest.as_ptr().add(1),
self.rest.len() - 1
self.rest.len() - 1,
)
};
Some(result)
Expand Down Expand Up @@ -203,19 +203,13 @@ impl Iterator for ArrayU8Iterator<'_> {
};
self.rest = unsafe {
// SAFETY: Safe as the length is checked beforehand to be at least n + 1
core::slice::from_raw_parts(
self.rest.as_ptr().add(n + 1),
self.rest.len() - n - 1
)
core::slice::from_raw_parts(self.rest.as_ptr().add(n + 1), self.rest.len() - n - 1)
};
Some(result)
} else {
self.rest = unsafe {
// SAFETY: Safe as the length is checked beforehand to be at least n + 1
core::slice::from_raw_parts(
self.rest.as_ptr().add(self.rest.len()),
0
)
core::slice::from_raw_parts(self.rest.as_ptr().add(self.rest.len()), 0)
};
None
}
Expand Down Expand Up @@ -990,7 +984,7 @@ mod test {

// test last
assert_eq!(arr.into_iter().last(), content.last().map(|v| *v));

// test nth
for i in 0..content.len() {
let mut it = arr.into_iter();
Expand Down

0 comments on commit 7319327

Please sign in to comment.