pub struct NgxQueue<T> { /* private fields */ }
Expand description
A wrapper over a raw ngx_queue_t
, an intrusive doubly-linked list.
This wrapper is defined in terms of type T
that embeds and can be converted from or to the
list entries.
Example:
// We need a wrapper type to define [NgxQueueEntry] on.
#[repr(transparent)]
struct PostedEvent(ngx_event_t);
unsafe impl NgxQueueEntry for PostedEvent {
fn from_queue(queue: NonNull<ngx_queue_t>) -> NonNull<Self> {
// We can safely cast obtained ngx_event_t to a transparent wrapper.
unsafe { ngx_queue_data!(queue, ngx_event_t, queue) }.cast()
}
fn to_queue(&mut self) -> &mut ngx_queue_t {
&mut self.0.queue
}
}
// SAFETY: `ngx_posted_events` global static is a list of `ngx_event_t` linked via
// `ngx_event_t.queue`.
// NGINX is single-threaded, so we get exclusive access to the static.
let posted: &mut NgxQueue<PostedEvent> =
unsafe { NgxQueue::from_ptr_mut(addr_of_mut!(ngx_posted_events)) };
See https://nginx.org/en/docs/dev/development_guide.html#queue.
Implementations§
Source§impl<T> NgxQueue<T>where
T: NgxQueueEntry,
impl<T> NgxQueue<T>where
T: NgxQueueEntry,
Sourcepub unsafe fn from_ptr<'a>(head: *const ngx_queue_t) -> &'a Self
pub unsafe fn from_ptr<'a>(head: *const ngx_queue_t) -> &'a Self
Creates a queue reference from a pointer to ngx_queue_t.
§Safety
head
is a valid pointer to a list head, and T::from_queue
on the list entries results in
valid pointers to T
.
Sourcepub unsafe fn from_ptr_mut<'a>(head: *mut ngx_queue_t) -> &'a mut Self
pub unsafe fn from_ptr_mut<'a>(head: *mut ngx_queue_t) -> &'a mut Self
Creates a mutable queue reference from a pointer to ngx_queue_t.
§Safety
head
is a valid pointer to a list head, and T::from_queue
on the list entries results in
valid pointers to T
.
Sourcepub fn push_front(&mut self, entry: &mut T)
pub fn push_front(&mut self, entry: &mut T)
Appends an element to the beginning of the queue.
Sourcepub fn iter(&self) -> NgxQueueIter<'_, T> ⓘ
pub fn iter(&self) -> NgxQueueIter<'_, T> ⓘ
Returns an iterator over the entries of the queue.
Sourcepub fn iter_mut(&mut self) -> NgxQueueIterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> NgxQueueIterMut<'_, T> ⓘ
Returns a mutable iterator over the entries of the queue.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for NgxQueue<T>
impl<T> RefUnwindSafe for NgxQueue<T>where
T: RefUnwindSafe,
impl<T> !Send for NgxQueue<T>
impl<T> !Sync for NgxQueue<T>
impl<T> Unpin for NgxQueue<T>where
T: Unpin,
impl<T> UnwindSafe for NgxQueue<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more