Skip to main content

Record

Struct Record 

Source
pub struct Record {
Show 20 fields pub key: String, pub ty: String, pub default: Option<Value>, pub allowed: Vec<String>, pub separators: Vec<String>, pub required: bool, pub stability: String, pub since: Option<String>, pub deprecation: Option<Value>, pub group: Option<String>, pub maps_to: Option<String>, pub example: Option<String>, pub observe: Option<String>, pub reviewed: Option<String>, pub summary: Option<String>, pub modified: Option<String>, pub source: Option<String>, pub env: Option<EnvBinding>, pub arg: Option<ArgBinding>, pub subcommands: Vec<String>,
}
Expand description

One input, flattened to plain JSON-friendly types.

This is the shape every language binding implements and the JSON Schema describes. Rich types collapse to strings here on purpose: the contract must be expressible in C, Python, and JSON, none of which have const-validated newtypes.

Unknown fields are ignored rather than rejected on read: the format grows by adding optional fields, so a consumer pinned to this version must keep reading documents produced by a later one. Authoring mistakes are caught by the command-line checker, which reports unrecognised fields explicitly.

Fields§

§key: String

Transport-free identity, snake_case. The join key across every source.

§ty: String

Wire kind: one of crate::Type::ALL.

§default: Option<Value>

The declared default, in its natural JSON form.

§allowed: Vec<String>

Accepted tokens for the enum and list kinds.

§separators: Vec<String>

Characters that separate items in a list value.

§required: bool

Whether the program requires this input.

§stability: String§since: Option<String>

Introducing version, major.minor.patch.

§deprecation: Option<Value>

{ since, replaced_by, migration }, present only when deprecated.

§group: Option<String>

Grouping tag for documentation and help output.

§maps_to: Option<String>

A key in another configuration surface this input bridges to.

§example: Option<String>

A copy-pasteable example.

§observe: Option<String>

A resolved-configuration field this input visibly changes.

§reviewed: Option<String>

Date a human last verified the entry, YYYY-MM-DD.

§summary: Option<String>

Prose description.

§modified: Option<String>

Date the declaration was last edited. Stamped by tooling from version control, never hand-written.

§source: Option<String>

Which project and revision this record came from; populated when records from several documents are merged.

§env: Option<EnvBinding>

The environment binding, if this input accepts one.

§arg: Option<ArgBinding>

The argument-vector binding, if this input accepts one.

§subcommands: Vec<String>

Restricts this input to one or more subcommands, by their token — see crate::Input::subcommands. Empty means always active.

Implementations§

Source§

impl Record

Source

pub fn env_names(&self) -> Vec<&str>

Every environment name this input answers to.

Examples found in repository?
examples/minigrep.rs (line 107)
99pub fn usage() -> String {
100    let mut text = String::from("usage: minigrep [OPTIONS] <QUERY> <FILE>\n\n");
101    for record in Contract::records() {
102        text.push_str(&format!(
103            "  {:<20} {}\n",
104            record.usage(),
105            record.summary.as_deref().unwrap_or("")
106        ));
107        if !record.env_names().is_empty() {
108            text.push_str(&format!(
109                "  {:<20} (or set {})\n",
110                "",
111                record.env_names().join(", ")
112            ));
113        }
114    }
115    text
116}
Source

pub fn arg_labels(&self) -> Vec<String>

Every argument spelling this input answers to, dashes included.

Source

pub fn usage(&self) -> String

The signature as it would appear in help output, e.g. -l, --log-level <LEVEL>. Empty when the input has no argument form.

Examples found in repository?
examples/minigrep.rs (line 104)
99pub fn usage() -> String {
100    let mut text = String::from("usage: minigrep [OPTIONS] <QUERY> <FILE>\n\n");
101    for record in Contract::records() {
102        text.push_str(&format!(
103            "  {:<20} {}\n",
104            record.usage(),
105            record.summary.as_deref().unwrap_or("")
106        ));
107        if !record.env_names().is_empty() {
108            text.push_str(&format!(
109                "  {:<20} (or set {})\n",
110                "",
111                record.env_names().join(", ")
112            ));
113        }
114    }
115    text
116}
Source

pub fn accepts(&self, raw: &str) -> Result<(), String>

Whether raw is a legal value, judged from the declaration’s metadata alone.

This is the cross-language check: it uses only what the published contract carries, so any consumer can perform it without the originating program’s types.

Source

pub fn tokens<'a>(&self, raw: &'a str) -> Vec<&'a str>

Split a list value into its tokens using the declared separators. Empty when this input is not a list.

Trait Implementations§

Source§

impl Clone for Record

Source§

fn clone(&self) -> Record

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 Record

Source§

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

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

impl<'de> Deserialize<'de> for Record

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Record, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Record

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Record

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Record

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.