Skip to main content

Argv

Struct Argv 

Source
pub struct Argv { /* private fields */ }
Expand description

A parsed command’s argument vector.

Stored in two allocations — all argument bytes concatenated in buf, with ends[i] the end offset of argument i — instead of the N+1 a Vec<Vec<u8>> needs (one outer Vec plus one per argument). Parsing a SET drops from 4 allocations to 2. It is Send (two Vecs), so the thread-per-core runtime still forwards it across cores by value.

Index/get/first/iter return &[u8] argument slices. It compares equal to a Vec<Vec<u8>> of the same arguments, so call sites and tests read naturally.

Implementations§

Source§

impl Argv

Source

pub fn with_capacity(argc: usize, bytes: usize) -> Self

An empty argv, pre-sizing for argc args totalling bytes bytes.

Source

pub fn clear(&mut self)

Drop all args while keeping the buf + ends capacity. Used by the reactor’s per-command scratch Argv: parse_command_into clears then refills, so the hot path’s malloc rate drops to ~0.

Source

pub fn reserve_for(&mut self, argc: usize, bytes: usize)

Reserve room for argc args totalling bytes bytes on top of what is already there (no shrink).

Source

pub fn push(&mut self, arg: &[u8])

Append one argument.

Source

pub fn len(&self) -> usize

Number of arguments.

Source

pub fn is_empty(&self) -> bool

Whether there are no arguments.

Source

pub fn get(&self, i: usize) -> Option<&[u8]>

Argument i as a byte slice, or None if out of range.

Source

pub fn first(&self) -> Option<&[u8]>

The first argument (the command name), or None if empty.

Source

pub fn iter(&self) -> impl Iterator<Item = &[u8]>

Iterate the arguments as byte slices.

Trait Implementations§

Source§

impl ArgvView for Argv

Source§

fn len(&self) -> usize

Number of arguments.
Source§

fn get(&self, i: usize) -> Option<&[u8]>

Argument i as a byte slice, or None if out of range.
Source§

fn is_empty(&self) -> bool

Whether there are no arguments.
Source§

fn first(&self) -> Option<&[u8]>

The first argument (the command name), or None if empty.
Source§

fn iter(&self) -> ArgvIter<'_, Self>
where Self: Sized,

Iterate the arguments as byte slices.
Source§

fn copy_into(&self, out: &mut Argv)

Clear out and refill it with this view’s arguments. out keeps its buffer capacity across the clear, so refilling a recycled Argv (see crate::ArgvPool) is allocation-free in steady state. Object-safe (no Self: Sized bound).
Source§

fn to_argv(&self) -> Argv

Materialise an owned Argv — copies arg bytes into a fresh buffer. Used at handoff junctures (cross-shard dispatch, MULTI queue, AOF logging) that need to outlive the original input buffer. Object-safe (no Self: Sized bound) so callers can hold &dyn ArgvView.
Source§

impl Clone for Argv

Source§

fn clone(&self) -> Argv

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Argv

Source§

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

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

impl Default for Argv

Source§

fn default() -> Argv

Returns the “default value” for a type. Read more
Source§

impl Eq for Argv

Source§

impl From<Vec<Vec<u8>>> for Argv

Build from a vec-of-vecs (test/embedding convenience; the wire path uses parse_command, which builds an Argv directly without the intermediate allocations).

Source§

fn from(v: Vec<Vec<u8>>) -> Self

Converts to this type from the input type.
Source§

impl Index<usize> for Argv

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &[u8]

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for Argv

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Vec<Vec<u8>>> for Argv

Compare to a Vec<Vec<u8>> of the same arguments (keeps call sites + tests that build the expected value as a vec-of-vecs readable).

Source§

fn eq(&self, other: &Vec<Vec<u8>>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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.

Auto Trait Implementations§

§

impl Freeze for Argv

§

impl RefUnwindSafe for Argv

§

impl Send for Argv

§

impl Sync for Argv

§

impl Unpin for Argv

§

impl UnsafeUnpin for Argv

§

impl UnwindSafe for Argv

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