Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 0c2243f8a1696816431e7210e991fa52 > files > 16417

rust-doc-1.35.0-1.mga7.armv7hl.rpm

<!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="API documentation for the Rust `path` mod in crate `std`."><meta name="keywords" content="rust, rustlang, rust-lang, path"><title>std::path - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize1.35.0.css"><link rel="stylesheet" type="text/css" href="../../rustdoc1.35.0.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark1.35.0.css"><link rel="stylesheet" type="text/css" href="../../light1.35.0.css" id="themeStyle"><script src="../../storage1.35.0.js"></script><noscript><link rel="stylesheet" href="../../noscript1.35.0.css"></noscript><link rel="shortcut icon" href="../../favicon1.35.0.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow1.35.0.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../std/index.html'><img src='../../rust-logo1.35.0.png' alt='logo' width='100'></a><p class='location'>Module path</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#constants">Constants</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'><a href='../index.html'>std</a></p><script>window.sidebarCurrent = {name: 'path', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush1.35.0.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme1.35.0.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../../settings.html"><img src="../../wheel1.35.0.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../../src/std/path.rs.html#1-4242' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>std</a>::<wbr><a class="mod" href=''>path</a></span></h1><div class='docblock'><p>Cross-platform path manipulation.</p>
<p>This module provides two types, <a href="../../std/path/struct.PathBuf.html"><code>PathBuf</code></a> and <a href="../../std/path/struct.Path.html"><code>Path</code></a> (akin to <a href="../../std/string/struct.String.html"><code>String</code></a>
and <a href="../../std/primitive.str.html"><code>str</code></a>), for working with paths abstractly. These types are thin wrappers
around <a href="../../std/ffi/struct.OsString.html"><code>OsString</code></a> and <a href="../../std/ffi/struct.OsStr.html"><code>OsStr</code></a> respectively, meaning that they work directly
on strings according to the local platform's path syntax.</p>
<p>Paths can be parsed into <a href="../../std/path/enum.Component.html"><code>Component</code></a>s by iterating over the structure
returned by the <a href="../../std/path/struct.Path.html#method.components"><code>components</code></a> method on <a href="../../std/path/struct.Path.html"><code>Path</code></a>. <a href="../../std/path/enum.Component.html"><code>Component</code></a>s roughly
correspond to the substrings between path separators (<code>/</code> or <code>\</code>). You can
reconstruct an equivalent path from components with the <a href="../../std/path/struct.PathBuf.html#method.push"><code>push</code></a> method on
<a href="../../std/path/struct.PathBuf.html"><code>PathBuf</code></a>; note that the paths may differ syntactically by the
normalization described in the documentation for the <a href="../../std/path/struct.Path.html#method.components"><code>components</code></a> method.</p>
<h2 id="simple-usage" class="section-header"><a href="#simple-usage">Simple usage</a></h2>
<p>Path manipulation includes both parsing components from slices and building
new owned paths.</p>
<p>To parse a path, you can create a <a href="../../std/path/struct.Path.html"><code>Path</code></a> slice from a <a href="../../std/primitive.str.html"><code>str</code></a>
slice and start asking questions:</p>

<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">path</span>::<span class="ident">Path</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">OsStr</span>;

<span class="kw">let</span> <span class="ident">path</span> <span class="op">=</span> <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">&quot;/tmp/foo/bar.txt&quot;</span>);

<span class="kw">let</span> <span class="ident">parent</span> <span class="op">=</span> <span class="ident">path</span>.<span class="ident">parent</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">parent</span>, <span class="prelude-val">Some</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">&quot;/tmp/foo&quot;</span>)));

<span class="kw">let</span> <span class="ident">file_stem</span> <span class="op">=</span> <span class="ident">path</span>.<span class="ident">file_stem</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">file_stem</span>, <span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">&quot;bar&quot;</span>)));

<span class="kw">let</span> <span class="ident">extension</span> <span class="op">=</span> <span class="ident">path</span>.<span class="ident">extension</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">extension</span>, <span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">&quot;txt&quot;</span>)));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0Ause%20std%3A%3Affi%3A%3AOsStr%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Ftmp%2Ffoo%2Fbar.txt%22)%3B%0A%0Alet%20parent%20%3D%20path.parent()%3B%0Aassert_eq!(parent%2C%20Some(Path%3A%3Anew(%22%2Ftmp%2Ffoo%22)))%3B%0A%0Alet%20file_stem%20%3D%20path.file_stem()%3B%0Aassert_eq!(file_stem%2C%20Some(OsStr%3A%3Anew(%22bar%22)))%3B%0A%0Alet%20extension%20%3D%20path.extension()%3B%0Aassert_eq!(extension%2C%20Some(OsStr%3A%3Anew(%22txt%22)))%3B%0A%7D">Run</a></pre></div>
<p>To build or modify paths, use <a href="../../std/path/struct.PathBuf.html"><code>PathBuf</code></a>:</p>

<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">path</span>::<span class="ident">PathBuf</span>;

<span class="comment">// This way works...</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">path</span> <span class="op">=</span> <span class="ident">PathBuf</span>::<span class="ident">from</span>(<span class="string">&quot;c:\\&quot;</span>);

<span class="ident">path</span>.<span class="ident">push</span>(<span class="string">&quot;windows&quot;</span>);
<span class="ident">path</span>.<span class="ident">push</span>(<span class="string">&quot;system32&quot;</span>);

<span class="ident">path</span>.<span class="ident">set_extension</span>(<span class="string">&quot;dll&quot;</span>);

<span class="comment">// ... but push is best used if you don&#39;t know everything up</span>
<span class="comment">// front. If you do, this way is better:</span>
<span class="kw">let</span> <span class="ident">path</span>: <span class="ident">PathBuf</span> <span class="op">=</span> [<span class="string">&quot;c:\\&quot;</span>, <span class="string">&quot;windows&quot;</span>, <span class="string">&quot;system32.dll&quot;</span>].<span class="ident">iter</span>().<span class="ident">collect</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APathBuf%3B%0A%0A%2F%2F%20This%20way%20works...%0Alet%20mut%20path%20%3D%20PathBuf%3A%3Afrom(%22c%3A%5C%5C%22)%3B%0A%0Apath.push(%22windows%22)%3B%0Apath.push(%22system32%22)%3B%0A%0Apath.set_extension(%22dll%22)%3B%0A%0A%2F%2F%20...%20but%20push%20is%20best%20used%20if%20you%20don't%20know%20everything%20up%0A%2F%2F%20front.%20If%20you%20do%2C%20this%20way%20is%20better%3A%0Alet%20path%3A%20PathBuf%20%3D%20%5B%22c%3A%5C%5C%22%2C%20%22windows%22%2C%20%22system32.dll%22%5D.iter().collect()%3B%0A%7D">Run</a></pre></div>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Ancestors.html" title='std::path::Ancestors struct'>Ancestors</a></td><td class='docblock-short'><p>An iterator over <a href="struct.Path.html"><code>Path</code></a> and its ancestors.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Components.html" title='std::path::Components struct'>Components</a></td><td class='docblock-short'><p>An iterator over the <a href="enum.Component.html"><code>Component</code></a>s of a <a href="struct.Path.html"><code>Path</code></a>.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Display.html" title='std::path::Display struct'>Display</a></td><td class='docblock-short'><p>Helper struct for safely printing paths with <a href="../../std/macro.format.html"><code>format!</code></a> and <code>{}</code>.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Iter.html" title='std::path::Iter struct'>Iter</a></td><td class='docblock-short'><p>An iterator over the <a href="enum.Component.html"><code>Component</code></a>s of a <a href="struct.Path.html"><code>Path</code></a>, as <a href="../../std/ffi/struct.OsStr.html"><code>OsStr</code></a> slices.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Path.html" title='std::path::Path struct'>Path</a></td><td class='docblock-short'><p>A slice of a path (akin to <a href="../primitive.str.html"><code>str</code></a>).</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.PathBuf.html" title='std::path::PathBuf struct'>PathBuf</a></td><td class='docblock-short'><p>An owned, mutable path (akin to <a href="../string/struct.String.html"><code>String</code></a>).</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.PrefixComponent.html" title='std::path::PrefixComponent struct'>PrefixComponent</a></td><td class='docblock-short'><p>A structure wrapping a Windows path prefix as well as its unparsed string
representation.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.StripPrefixError.html" title='std::path::StripPrefixError struct'>StripPrefixError</a></td><td class='docblock-short'><p>An error returned from <a href="struct.Path.html#method.strip_prefix"><code>Path::strip_prefix</code></a> if the prefix
was not found.</p>
</td></tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table><tr class='module-item'><td><a class="enum" href="enum.Component.html" title='std::path::Component enum'>Component</a></td><td class='docblock-short'><p>A single component of a path.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.Prefix.html" title='std::path::Prefix enum'>Prefix</a></td><td class='docblock-short'><p>Windows path prefixes, e.g., <code>C:</code> or <code>\\server\share</code>.</p>
</td></tr></table><h2 id='constants' class='section-header'><a href="#constants">Constants</a></h2>
<table><tr class='module-item'><td><a class="constant" href="constant.MAIN_SEPARATOR.html" title='std::path::MAIN_SEPARATOR constant'>MAIN_SEPARATOR</a></td><td class='docblock-short'><p>The primary separator of path components for the current platform.</p>
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table><tr class='module-item'><td><a class="fn" href="fn.is_separator.html" title='std::path::is_separator fn'>is_separator</a></td><td class='docblock-short'><p>Determines whether the character is one of the permitted path
separators for the current platform.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "std";</script><script src="../../aliases.js"></script><script src="../../main1.35.0.js"></script><script defer src="../../search-index.js"></script></body></html>