silk.cli.value.

How a struct field reads its value from the command line.

When to use#

Every field of a command struct needs ArgValue. This module implements it for String, Bytes, bool, the integer types, Option<T>, and List<T>. Implement it for your own type to read that type from an argument.

Details#

A bool field is a flag: it takes no value and becomes true when the flag is present. An Option<T> field becomes present when the option is given. A List<T> field collects every occurrence, and as a positional argument it takes every remaining argument. A Bytes field takes the argument's exact bytes, so it also reads a path that is not valid UTF-8; every other type reads Arg.text, where each byte that is not valid UTF-8 reads as ?.

Import as ArgValue with import silk.cli.value { ArgValue }.

Public declarations: 3.

Arg#

silk
pub struct Arg<'a>

One argument, or the part of one after = or after an option letter.

Field text#

silk
pub text: string<'a>

The argument as text. Each byte that is not valid UTF-8 reads as ?, so the text has the same length as bytes.

Field bytes#

silk
pub bytes: &'a [u8]

The argument's exact bytes, as the program received them.

Implementation Copy for Arg<'a>#

silk
impl<'a> Copy for Arg<'a>

FromArg#

silk
pub interface FromArg

A type that reads one value from command-line text.

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<Self, bool> ! OutOfMemoryError ? &mut Allocator

Returns the value that arg spells, or false in Result.Failure when it is not a valid value.

ArgValue#

silk
pub interface ArgValue

A field type that the parser can fill from the command line.

Operation takesValue#

silk
fn takesValue() -> bool

Whether an occurrence of the option takes a value. false makes the option a flag.

Operation repeats#

silk
fn repeats() -> bool

Whether the field accepts more than one occurrence.

Operation initial#

silk
effect fn initial() -> Self ! OutOfMemoryError ? &mut Allocator

Returns the value of a field that the command line does not give: empty text, zero, false, none, or an empty list.

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool ! OutOfMemoryError ? &mut Allocator

Stores one occurrence. arg is empty for a flag. Returns false when it is not a valid value.

Implementation FromArg for String#

silk
impl FromArg for String

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<String, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for i8#

silk
impl FromArg for i8

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<i8, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for i16#

silk
impl FromArg for i16

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<i16, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for i32#

silk
impl FromArg for i32

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<i32, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for i64#

silk
impl FromArg for i64

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<i64, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for u8#

silk
impl FromArg for u8

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<u8, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for u16#

silk
impl FromArg for u16

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<u16, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for u32#

silk
impl FromArg for u32

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<u32, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for u64#

silk
impl FromArg for u64

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<u64, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for usize#

silk
impl FromArg for usize

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<usize, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation FromArg for Bytes#

silk
impl FromArg for Bytes

Operation fromArg#

silk
effect fn fromArg(arg: Arg<'_>) -> Result<Bytes, bool>
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for Bytes#

silk
impl ArgValue for Bytes

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for String#

silk
impl ArgValue for String

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for i8#

silk
impl ArgValue for i8

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for i16#

silk
impl ArgValue for i16

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for i32#

silk
impl ArgValue for i32

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for i64#

silk
impl ArgValue for i64

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for u8#

silk
impl ArgValue for u8

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for u16#

silk
impl ArgValue for u16

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for u32#

silk
impl ArgValue for u32

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for u64#

silk
impl ArgValue for u64

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for usize#

silk
impl ArgValue for usize

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for bool#

silk
impl ArgValue for bool

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for Option<T>#

silk
impl<T: FromArg> ArgValue for Option<T>

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Implementation ArgValue for List<T>#

silk
impl<T: FromArg> ArgValue for List<T>

Operation takesValue#

silk
fn takesValue() -> bool

Operation repeats#

silk
fn repeats() -> bool

Operation initial#

silk
effect fn initial() -> Self
    ! OutOfMemoryError
    ? &mut Allocator

Operation accept#

silk
effect fn accept(self: &mut Self, arg: Arg<'_>) -> bool
    ! OutOfMemoryError
    ? &mut Allocator

Category: Command line.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page