Struct NgxQueue

Source
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,

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true if the queue contains no elements.

Source

pub fn push_back(&mut self, entry: &mut T)

Appends an element to the end of the queue.

Source

pub fn push_front(&mut self, entry: &mut T)

Appends an element to the beginning of the queue.

Source

pub fn iter(&self) -> NgxQueueIter<'_, T>

Returns an iterator over the entries of the queue.

Source

pub fn iter_mut(&mut self) -> NgxQueueIterMut<'_, T>

Returns a mutable iterator over the entries of the queue.

Trait Implementations§

Source§

impl<T: Debug> Debug for NgxQueue<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.