Skip to content

Commit

Permalink
improvements recommended by clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cammeresi committed Jul 6, 2024
1 parent 887a99a commit 4968f9a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub struct LinkerSetIter<T> {
}

impl<T> LinkerSetIter<T> {
/// Create a new iterator for a linker set.
///
/// # Safety
/// The pointers must be start and end pointers generated by the linker.
pub unsafe fn new(start: *const T, stop: *const T) -> Self {
assert!(start < stop);
Self { next: start, stop }
Expand Down Expand Up @@ -65,6 +69,10 @@ impl<T> LinkerSet<T>
where
T: 'static,
{
/// Create a new object to represent a linker set.
///
/// # Safety
/// The pointers must be start and end pointers generated by the linker.
pub unsafe fn new(start: *const T, stop: *const T) -> Self {
assert!(start < stop);
let len = stop.offset_from(start).try_into().unwrap();
Expand All @@ -79,6 +87,10 @@ where
pub fn len(&self) -> usize {
self.slice.len()
}

pub fn is_empty(&self) -> bool {
self.start == self.stop
}
}

impl<T> IntoIterator for LinkerSet<T>
Expand Down Expand Up @@ -194,6 +206,11 @@ mod test {
assert_eq!(actual, expect);
}

#[test]
fn test_is_empty() {
assert!(!set!(stuff).is_empty());
}

#[derive(Debug, Eq, PartialEq, Hash)]
pub(crate) struct Foo {
a: u32,
Expand Down

0 comments on commit 4968f9a

Please sign in to comment.