Struct NgxString

Source
pub struct NgxString<A>(/* private fields */)
where
    A: Allocator + Clone;
Expand description

Owned byte string type with Allocator support.

Inspired by bstr and unstable feature(bstr), with two important differences:

  • Allocator always have to be specified,
  • any allocating methods are failible and require explicit handling of the result.

Implementations§

Source§

impl<A> NgxString<A>
where A: Allocator + Clone,

Source

pub fn new_in(alloc: A) -> Self

Constructs a new, empty NgxString<A>.

No allocations will be made until data is added to the string.

Source

pub fn try_from_bytes_in( bytes: impl AsRef<[u8]>, alloc: A, ) -> Result<Self, TryReserveError>

Tries to construct a new NgxString<A> from a byte slice.

Source

pub fn allocator(&self) -> &A

Returns a reference to the underlying allocator

Source

pub fn capacity(&self) -> usize

Returns this NgxString’s capacity, in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if this NgxString has a length of zero, and false otherwise.

Source

pub fn len(&self) -> usize

Return this NgxString’s length, in bytes.

Source

pub fn append_within_capacity( &mut self, other: impl AsRef<[u8]>, ) -> Result<(), usize>

Appends bytes if there is sufficient spare capacity.

Returns the number of remaining bytes on overflow.

Source

pub fn try_append( &mut self, other: impl AsRef<[u8]>, ) -> Result<(), TryReserveError>

Tries to append the bytes to the NgxString.

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Tries to reserve capacity for at least additional more bytes.

Source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

Tries to reserve the minimum capacity for at least additional more bytes.

Source

pub unsafe fn from_raw_parts( ptr: *mut u8, length: usize, capacity: usize, alloc: A, ) -> Self

Creates NgxString directly from a pointer, a capacity, a length and an allocator.

§Safety

See Vec::from_raw_parts_in

Source

pub fn into_raw_parts(self) -> (*mut u8, usize, usize, A)

Splits the NgxString into its raw components.

The caller becomes responsible for the memory previously managed by this NgxString.

Methods from Deref<Target = NgxStr>§

Source

pub fn as_bytes(&self) -> &[u8]

Access the NgxStr as a byte slice.

Source

pub fn to_str(&self) -> Result<&str, Utf8Error>

Yields a &str slice if the NgxStr contains valid UTF-8.

Source

pub fn to_string_lossy(&self) -> Cow<'_, str>

Converts an NgxStr into a Cow<str>, replacing invalid UTF-8 sequences.

See String::from_utf8_lossy.

Source

pub fn is_empty(&self) -> bool

Returns true if the NgxStr is empty, otherwise false.

Trait Implementations§

Source§

impl<A> AsMut<[u8]> for NgxString<A>
where A: Allocator + Clone,

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<A> AsMut<NgxStr> for NgxString<A>
where A: Allocator + Clone,

Source§

fn as_mut(&mut self) -> &mut NgxStr

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<A> AsRef<[u8]> for NgxString<A>
where A: Allocator + Clone,

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<A> AsRef<NgxStr> for NgxString<A>
where A: Allocator + Clone,

Source§

fn as_ref(&self) -> &NgxStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<A> Borrow<[u8]> for NgxString<A>
where A: Allocator + Clone,

Source§

fn borrow(&self) -> &[u8]

Immutably borrows from an owned value. Read more
Source§

impl<A> Borrow<NgxStr> for NgxString<A>
where A: Allocator + Clone,

Source§

fn borrow(&self) -> &NgxStr

Immutably borrows from an owned value. Read more
Source§

impl<A> Clone for NgxString<A>
where A: Allocator + Clone + Clone,

Source§

fn clone(&self) -> NgxString<A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A> Debug for NgxString<A>
where A: Allocator + Clone,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<A> Deref for NgxString<A>
where A: Allocator + Clone,

Source§

type Target = NgxStr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<A> DerefMut for NgxString<A>
where A: Allocator + Clone,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<A> Display for NgxString<A>
where A: Allocator + Clone,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<A> Hash for NgxString<A>
where A: Allocator + Clone,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<A> Ord for NgxString<A>
where A: Allocator + Clone,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a, A: Allocator + Clone> PartialEq<&'a [u8]> for NgxString<A>

Source§

fn eq(&self, other: &&'a [u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone, const N: usize> PartialEq<&'a [u8; N]> for NgxString<A>

Source§

fn eq(&self, other: &&'a [u8; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone> PartialEq<&'a NgxStr> for NgxString<A>

Source§

fn eq(&self, other: &&'a NgxStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone> PartialEq<NgxString<A>> for &'a [u8]

Source§

fn eq(&self, other: &NgxString<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone, const N: usize> PartialEq<NgxString<A>> for &'a [u8; N]

Source§

fn eq(&self, other: &NgxString<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone> PartialEq<NgxString<A>> for &'a NgxStr

Source§

fn eq(&self, other: &NgxString<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone> PartialEq<NgxString<A>> for ngx_str_t

Source§

fn eq(&self, other: &NgxString<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A1, A2> PartialEq<NgxString<A2>> for NgxString<A1>
where A1: Allocator + Clone, A2: Allocator + Clone,

Source§

fn eq(&self, other: &NgxString<A2>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone> PartialEq<ngx_str_t> for NgxString<A>

Source§

fn eq(&self, other: &ngx_str_t) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, A: Allocator + Clone> PartialOrd<&'a [u8]> for NgxString<A>

Source§

fn partial_cmp(&self, other: &&'a [u8]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, A: Allocator + Clone, const N: usize> PartialOrd<&'a [u8; N]> for NgxString<A>

Source§

fn partial_cmp(&self, other: &&'a [u8; N]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, A: Allocator + Clone> PartialOrd<&'a NgxStr> for NgxString<A>

Source§

fn partial_cmp(&self, other: &&'a NgxStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, A: Allocator + Clone> PartialOrd<NgxString<A>> for &'a [u8]

Source§

fn partial_cmp(&self, other: &NgxString<A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, A: Allocator + Clone, const N: usize> PartialOrd<NgxString<A>> for &'a [u8; N]

Source§

fn partial_cmp(&self, other: &NgxString<A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, A: Allocator + Clone> PartialOrd<NgxString<A>> for &'a NgxStr

Source§

fn partial_cmp(&self, other: &NgxString<A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, A: Allocator + Clone> PartialOrd<NgxString<A>> for ngx_str_t

Source§

fn partial_cmp(&self, other: &NgxString<A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<A1, A2> PartialOrd<NgxString<A2>> for NgxString<A1>
where A1: Allocator + Clone, A2: Allocator + Clone,

Source§

fn partial_cmp(&self, other: &NgxString<A2>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, A: Allocator + Clone> PartialOrd<ngx_str_t> for NgxString<A>

Source§

fn partial_cmp(&self, other: &ngx_str_t) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<OA: Allocator + Clone> TryCloneIn for NgxString<OA>

Source§

type Target<A: Allocator + Clone> = NgxString<A>

Target type, generic over an allocator.
Source§

fn try_clone_in<A: Allocator + Clone>( &self, alloc: A, ) -> Result<Self::Target<A>, AllocError>

Attempts to copy the value using alloc as an underlying Allocator.
Source§

impl<A> Write for NgxString<A>
where A: Allocator + Clone,

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
Source§

impl<A> Eq for NgxString<A>
where A: Allocator + Clone,

Auto Trait Implementations§

§

impl<A> Freeze for NgxString<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for NgxString<A>
where A: RefUnwindSafe,

§

impl<A> Send for NgxString<A>
where A: Send,

§

impl<A> Sync for NgxString<A>
where A: Sync,

§

impl<A> Unpin for NgxString<A>
where A: Unpin,

§

impl<A> UnwindSafe for NgxString<A>
where A: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.