pub struct Example {
pub description: String,
pub command: String,
pub output: Option<String>,
}Expand description
A usage example for a command.
Examples are rendered in help output and Markdown documentation pages. Each example has a short human-readable description, the command string as it would be typed, and an optional expected output snippet.
§Examples
let ex = Example::new("list all items", "myapp list")
.with_output("item1\nitem2");
assert_eq!(ex.description, "list all items");
assert_eq!(ex.command, "myapp list");
assert_eq!(ex.output.as_deref(), Some("item1\nitem2"));Fields§
§description: StringShort description of what the example demonstrates.
command: StringThe full command string as it would be typed by the user.
output: Option<String>Optional expected output shown below the command in help and documentation.
Implementations§
Source§impl Example
impl Example
Sourcepub fn new(description: impl Into<String>, command: impl Into<String>) -> Self
pub fn new(description: impl Into<String>, command: impl Into<String>) -> Self
Create a new Example with a description and command string.
The output field is None by default; use Example::with_output
to attach expected output.
§Arguments
description— Short explanation of what the example shows.command— The command string as typed (including the program name).
§Examples
let ex = Example::new("deploy to staging", "myapp deploy staging");
assert_eq!(ex.command, "myapp deploy staging");
assert!(ex.output.is_none());Sourcepub fn with_output(self, output: impl Into<String>) -> Self
pub fn with_output(self, output: impl Into<String>) -> Self
Attach an expected output snippet to this example.
The output is rendered as a comment in plain-text help and as a code block annotation in Markdown documentation.
§Examples
let ex = Example::new("check version", "myapp --version")
.with_output("myapp 1.0.0");
assert_eq!(ex.output.as_deref(), Some("myapp 1.0.0"));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Example
impl<'de> Deserialize<'de> for Example
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Example
impl Ord for Example
Source§impl PartialOrd for Example
impl PartialOrd for Example
impl Eq for Example
impl StructuralPartialEq for Example
Auto Trait Implementations§
impl Freeze for Example
impl RefUnwindSafe for Example
impl Send for Example
impl Sync for Example
impl Unpin for Example
impl UnsafeUnpin for Example
impl UnwindSafe for Example
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more