Skip to main content

ArgvView

Trait ArgvView 

Source
pub trait ArgvView: Index<usize, Output = [u8]> {
    // Required methods
    fn len(&self) -> usize;
    fn get(&self, i: usize) -> Option<&[u8]>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn first(&self) -> Option<&[u8]> { ... }
    fn iter(&self) -> ArgvIter<'_, Self>
       where Self: Sized { ... }
    fn copy_into(&self, out: &mut Argv) { ... }
    fn to_argv(&self) -> Argv { ... }
}
Expand description

Read-only view over a parsed command’s argument vector.

Implemented by both Argv (owned) and ArgvBorrowed (zero-copy). The command runtime takes argvs as &impl ArgvView, so the local fast path can hand a borrowed argv straight to dispatch with no memcpy.

Required Methods§

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.

Provided Methods§

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§