blob: 46867e5a75219f5ff469324ade328498baa120e1 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A struct that is converted from command line arguments."><meta name="keywords" content="rust, rustlang, rust-lang, StructOpt"><title>StructOpt in structopt - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../structopt/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../structopt/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">StructOpt</a></h2><div class="sidebar-elems"><section><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.clap">clap</a></li><li><a href="#tymethod.from_clap">from_clap</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.from_args">from_args</a></li><li><a href="#method.from_args_safe">from_args_safe</a></li><li><a href="#method.from_iter">from_iter</a></li><li><a href="#method.from_iter_safe">from_iter_safe</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-StructOpt-for-Box%3CT%3E">Box&lt;T&gt;</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In structopt</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="index.html">structopt</a>::<wbr><a class="trait" href="#">StructOpt</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/structopt/lib.rs.html#1132-1192">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait StructOpt {
fn <a href="#tymethod.clap" class="fnname">clap</a>&lt;'a, 'b&gt;() -&gt; <a class="struct" href="../clap/app/struct.App.html" title="struct clap::app::App">App</a>&lt;'a, 'b&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.from_clap" class="fnname">from_clap</a>(matches: &amp;<a class="struct" href="../clap/args/arg_matches/struct.ArgMatches.html" title="struct clap::args::arg_matches::ArgMatches">ArgMatches</a>&lt;'_&gt;) -&gt; Self;
fn <a href="#method.from_args" class="fnname">from_args</a>() -&gt; Self<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.from_args_safe" class="fnname">from_args_safe</a>() -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self, <a class="struct" href="../clap/errors/struct.Error.html" title="struct clap::errors::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.from_iter" class="fnname">from_iter</a>&lt;I&gt;(iter: I) -&gt; Self<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/os_str/struct.OsString.html" title="struct std::ffi::os_str::OsString">OsString</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.from_iter_safe" class="fnname">from_iter_safe</a>&lt;I&gt;(iter: I) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self, <a class="struct" href="../clap/errors/struct.Error.html" title="struct clap::errors::Error">Error</a>&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/os_str/struct.OsString.html" title="struct std::ffi::os_str::OsString">OsString</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span>,
{ ... }
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A struct that is converted from command line arguments.</p>
</div></details><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.clap" class="method has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1134">source</a><h4 class="code-header">fn <a href="#tymethod.clap" class="fnname">clap</a>&lt;'a, 'b&gt;() -&gt; <a class="struct" href="../clap/app/struct.App.html" title="struct clap::app::App">App</a>&lt;'a, 'b&gt;</h4></section></summary><div class="docblock"><p>Returns <a href="../clap/app/struct.App.html" title="clap::App"><code>clap::App</code></a> corresponding to the struct.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.from_clap" class="method has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1139">source</a><h4 class="code-header">fn <a href="#tymethod.from_clap" class="fnname">from_clap</a>(matches: &amp;<a class="struct" href="../clap/args/arg_matches/struct.ArgMatches.html" title="struct clap::args::arg_matches::ArgMatches">ArgMatches</a>&lt;'_&gt;) -&gt; Self</h4></section></summary><div class="docblock"><p>Builds the struct from <a href="../clap/args/arg_matches/struct.ArgMatches.html" title="clap::ArgMatches"><code>clap::ArgMatches</code></a>. It’s guaranteed to succeed
if <code>matches</code> originates from an <code>App</code> generated by <a href="trait.StructOpt.html#tymethod.clap" title="StructOpt::clap"><code>StructOpt::clap</code></a> called on
the same type, otherwise it must panic.</p>
</div></details></div><h2 id="provided-methods" class="small-section-header">Provided Methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_args" class="method has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1143-1148">source</a><h4 class="code-header">fn <a href="#method.from_args" class="fnname">from_args</a>() -&gt; Self<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h4></section></summary><div class="docblock"><p>Builds the struct from the command line arguments (<a href="https://doc.rust-lang.org/nightly/std/env/fn.args_os.html" title="std::env::args_os"><code>std::env::args_os</code></a>).
Calls <a href="../clap/errors/struct.Error.html#method.exit" title="clap::Error::exit"><code>clap::Error::exit</code></a> on failure, printing the error message and aborting the program.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_args_safe" class="method has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1153-1160">source</a><h4 class="code-header">fn <a href="#method.from_args_safe" class="fnname">from_args_safe</a>() -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self, <a class="struct" href="../clap/errors/struct.Error.html" title="struct clap::errors::Error">Error</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h4></section></summary><div class="docblock"><p>Builds the struct from the command line arguments (<a href="https://doc.rust-lang.org/nightly/std/env/fn.args_os.html" title="std::env::args_os"><code>std::env::args_os</code></a>).
Unlike <a href="trait.StructOpt.html#method.from_args" title="StructOpt::from_args"><code>StructOpt::from_args</code></a>, returns <a href="../clap/errors/struct.Error.html" title="clap::Error"><code>clap::Error</code></a> on failure instead of aborting the program,
so calling <a href="../clap/errors/struct.Error.html#method.exit" title="clap::Error::exit"><code>.exit</code></a> is up to you.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_iter" class="method has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1167-1174">source</a><h4 class="code-header">fn <a href="#method.from_iter" class="fnname">from_iter</a>&lt;I&gt;(iter: I) -&gt; Self<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;I::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/os_str/struct.OsString.html" title="struct std::ffi::os_str::OsString">OsString</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</span></h4></section></summary><div class="docblock"><p>Gets the struct from any iterator such as a <code>Vec</code> of your making.
Print the error message and quit the program in case of failure.</p>
<p><strong>NOTE</strong>: The first argument will be parsed as the binary name unless
<a href="../clap/app/settings/enum.AppSettings.html#variant.NoBinaryName" title="clap::AppSettings::NoBinaryName"><code>clap::AppSettings::NoBinaryName</code></a> has been used.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_iter_safe" class="method has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1184-1191">source</a><h4 class="code-header">fn <a href="#method.from_iter_safe" class="fnname">from_iter_safe</a>&lt;I&gt;(iter: I) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self, <a class="struct" href="../clap/errors/struct.Error.html" title="struct clap::errors::Error">Error</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;I::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/os_str/struct.OsString.html" title="struct std::ffi::os_str::OsString">OsString</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</span></h4></section></summary><div class="docblock"><p>Gets the struct from any iterator such as a <code>Vec</code> of your making.</p>
<p>Returns a <a href="../clap/errors/struct.Error.html" title="clap::Error"><code>clap::Error</code></a> in case of failure. This does <em>not</em> exit in the
case of <code>--help</code> or <code>--version</code>, to achieve the same behavior as
<a href="trait.StructOpt.html#method.from_iter" title="StructOpt::from_iter"><code>from_iter()</code></a> you must call <a href="../clap/errors/struct.Error.html#method.exit" title="clap::Error::exit"><code>.exit()</code></a> on the error value.</p>
<p><strong>NOTE</strong>: The first argument will be parsed as the binary name unless
<a href="../clap/app/settings/enum.AppSettings.html#variant.NoBinaryName" title="clap::AppSettings::NoBinaryName"><code>clap::AppSettings::NoBinaryName</code></a> has been used.</p>
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-StructOpt-for-Box%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1213-1221">source</a><a href="#impl-StructOpt-for-Box%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;<a class="trait" href="trait.StructOpt.html" title="trait structopt::StructOpt">StructOpt</a>&gt; <a class="trait" href="trait.StructOpt.html" title="trait structopt::StructOpt">StructOpt</a> for <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.clap" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1214-1216">source</a><a href="#method.clap" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.clap" class="fnname">clap</a>&lt;'a, 'b&gt;() -&gt; <a class="struct" href="../clap/app/struct.App.html" title="struct clap::app::App">App</a>&lt;'a, 'b&gt;</h4></section><section id="method.from_clap" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/structopt/lib.rs.html#1218-1220">source</a><a href="#method.from_clap" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.from_clap" class="fnname">from_clap</a>(matches: &amp;<a class="struct" href="../clap/args/arg_matches/struct.ArgMatches.html" title="struct clap::args::arg_matches::ArgMatches">ArgMatches</a>&lt;'_&gt;) -&gt; Self</h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"></div><script src="../implementors/structopt/trait.StructOpt.js" data-ignore-extern-crates="alloc" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="structopt" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>