unsafe fn insert_raw(
        &mut self,
        address: *mut u8,
        len: NonZeroUsize,
    ) -> Result<(), OverlapError> {
        // The new buffer spans the address range [address, address + len - 1],
        // so the highest-address buffer it overlaps with starts at
        // address + len - 1. It can overlap with a buffer that starts with any
        // address less than that (if that buffer's length is large enough), so
        // we don't give a lower bound for the range.
        //
        // If the last buffer in this range does NOT overlap the new buffer,
        // then that buffer's memory range is strictly less than the new buffer.
        // Because buffers in self.buffers cannot overlap, all of the buffers in
        // the range would need to be strictly less than the new buffer.
        // Therefore we only need to check for overlap with the last buffer in
        // this range.
        //
        // range_end is one past the end of the range to check.
        let range_end = unsafe {
            // Safety: The function's preconditions require that address and len
            // represent a valid slice, which guarantees that this sum does not
            // oveflow.
            address.add(len.get())
        };
        if let Some(existing_buffer) = self.buffers.range(..range_end).next_back() {
            let (&existing_address, &existing_len) = existing_buffer;
            // Check if existing_buffer overlaps with the new buffer. Note that
            // existing_address.add(existing_len) generates a pointer one past
            // the end of the existing buffer, which is why the inequality is
            // strict.
            // Safety: self.buffers has an invariant that its values represent
            // slices, so this sum cannot overflow.
            if unsafe { existing_address.add(existing_len.get()) } > address {
                return Err(OverlapError);
            }
        }
        self.buffers.insert(address, len);
        Ok(())
    }
// Adds a new buffer, or returns an error if it overlaps with any existing
// buffers. Requires that address and len represent a valid slice.
Adds a new buffer, or returns an error if it overlaps with any existing
buffers. Requires that address and len represent a valid slice.
Adds a new buffer or returns an error if it overlaps with any existing buffers . Requires that address and len represent a valid slice .
unsafe fn insert_raw(
        &mut self,
        address: *mut u8,
        len: NonZeroUsize,
    ) -> Result<(), OverlapError> {
        // The new buffer spans the address range [address, address + len - 1],
        // so the highest-address buffer it overlaps with starts at
        // address + len - 1. It can overlap with a buffer that starts with any
        // address less than that (if that buffer's length is large enough), so
        // we don't give a lower bound for the range.
        //
        // If the last buffer in this range does NOT overlap the new buffer,
        // then that buffer's memory range is strictly less than the new buffer.
        // Because buffers in self.buffers cannot overlap, all of the buffers in
        // the range would need to be strictly less than the new buffer.
        // Therefore we only need to check for overlap with the last buffer in
        // this range.
        //
        // range_end is one past the end of the range to check.
        let range_end = unsafe {
            // Safety: The function's preconditions require that address and len
            // represent a valid slice, which guarantees that this sum does not
            // oveflow.
            address.add(len.get())
        };
        if let Some(existing_buffer) = self.buffers.range(..range_end).next_back() {
            let (&existing_address, &existing_len) = existing_buffer;
            // Check if existing_buffer overlaps with the new buffer. Note that
            // existing_address.add(existing_len) generates a pointer one past
            // the end of the existing buffer, which is why the inequality is
            // strict.
            // Safety: self.buffers has an invariant that its values represent
            // slices, so this sum cannot overflow.
            if unsafe { existing_address.add(existing_len.get()) } > address {
                return Err(OverlapError);
            }
        }
        self.buffers.insert(address, len);
        Ok(())
    }
unsafe fn insert_raw ( & mut self , address : * mut u8 , len : NonZeroUsize , ) -> Result < ( ) , OverlapError > { // The new buffer spans the address range [address, address + len - 1], // so the highest-address buffer it overlaps with starts at // address + len - 1. It can overlap with a buffer that starts with any // address less than that (if that buffer's length is large enough), so // we don't give a lower bound for the range. // // If the last buffer in this range does NOT overlap the new buffer, // then that buffer's memory range is strictly less than the new buffer. // Because buffers in self.buffers cannot overlap, all of the buffers in // the range would need to be strictly less than the new buffer. // Therefore we only need to check for overlap with the last buffer in // this range. // // range_end is one past the end of the range to check. let range_end = unsafe { // Safety: The function's preconditions require that address and len // represent a valid slice, which guarantees that this sum does not // oveflow. address . add ( len . get ( ) ) } ; if let Some ( existing_buffer ) = self . buffers . range ( .. range_end ) . next_back ( ) { let ( & existing_address , & existing_len ) = existing_buffer ; // Check if existing_buffer overlaps with the new buffer. Note that // existing_address.add(existing_len) generates a pointer one past // the end of the existing buffer, which is why the inequality is // strict. // Safety: self.buffers has an invariant that its values represent // slices, so this sum cannot overflow. if unsafe { existing_address . add ( existing_len . get ( ) ) } > address { return Err ( OverlapError ) ; } } self . buffers . insert ( address , len ) ; Ok ( ( ) ) }
Adds a new buffer, or returns an error if it overlaps with any existing
buffers.
Adds a new buffer or returns an error if it overlaps with any existing buffers .
&mut self
address
*mut u8
len
NonZeroUsize
&mut self
address
*mut u8
len
NonZeroUsize