From 4968f9a970cca36c70a900f2e2049c4ce3993a21 Mon Sep 17 00:00:00 2001 From: Sidney Cammeresi Date: Sat, 6 Jul 2024 16:31:46 -0700 Subject: [PATCH] improvements recommended by clippy --- src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0d9887e..590b46f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,10 @@ pub struct LinkerSetIter { } impl LinkerSetIter { + /// 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 } @@ -65,6 +69,10 @@ impl LinkerSet 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(); @@ -79,6 +87,10 @@ where pub fn len(&self) -> usize { self.slice.len() } + + pub fn is_empty(&self) -> bool { + self.start == self.stop + } } impl IntoIterator for LinkerSet @@ -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,