280 lines
No EOL
14 KiB
HTML
280 lines
No EOL
14 KiB
HTML
<!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 `bitflags`.">
|
||
<meta name="keywords" content="rust, rustlang, rust-lang, path">
|
||
|
||
<title>bitflags::__core::path - Rust</title>
|
||
|
||
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
|
||
<link rel="stylesheet" type="text/css" href="../../../main.css">
|
||
|
||
|
||
|
||
|
||
</head>
|
||
<body class="rustdoc">
|
||
<!--[if lte IE 8]>
|
||
<div class="warning">
|
||
This old browser is unsupported and will most likely display funky
|
||
things.
|
||
</div>
|
||
<![endif]-->
|
||
|
||
|
||
|
||
<nav class="sidebar">
|
||
|
||
<p class='location'><a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a></p><script>window.sidebarCurrent = {name: 'path', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script>
|
||
</nav>
|
||
|
||
<nav class="sub">
|
||
<form class="search-form js-only">
|
||
<div class="search-container">
|
||
<input class="search-input" name="search"
|
||
autocomplete="off"
|
||
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
|
||
type="search">
|
||
</div>
|
||
</form>
|
||
</nav>
|
||
|
||
<section id='main' class="content mod">
|
||
<h1 class='fqn'><span class='in-band'>Module <a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a class='mod' href=''>path</a></span><span class='out-of-band'><span id='render-detail'>
|
||
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
|
||
[<span class='inner'>−</span>]
|
||
</a>
|
||
</span><a id='src-6829' class='srclink' href='https://doc.rust-lang.org/nightly/std/path/index.html?gotosrc=6829' title='goto source code'>[src]</a></span></h1>
|
||
<div class='docblock'><p>Cross-platform path manipulation.</p>
|
||
|
||
<p>This module provides two types, <code>PathBuf</code> and <code>Path</code> (akin to <code>String</code> and
|
||
<code>str</code>), for working with paths abstractly. These types are thin wrappers
|
||
around <code>OsString</code> and <code>OsStr</code> respectively, meaning that they work directly
|
||
on strings according to the local platform's path syntax.</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 <code>Path</code> slice from a <code>str</code>
|
||
slice and start asking questions:</p>
|
||
|
||
<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'>let</span> <span class='ident'>path</span> <span class='op'>=</span> <span class='ident'>Path</span>::<span class='ident'>new</span>(<span class='string'>"/tmp/foo/bar.txt"</span>);
|
||
<span class='kw'>let</span> <span class='ident'>file</span> <span class='op'>=</span> <span class='ident'>path</span>.<span class='ident'>file_name</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='kw'>let</span> <span class='ident'>parent_dir</span> <span class='op'>=</span> <span class='ident'>path</span>.<span class='ident'>parent</span>();</pre>
|
||
|
||
<p>To build or modify paths, use <code>PathBuf</code>:</p>
|
||
|
||
<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='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'>"c:\\"</span>);
|
||
<span class='ident'>path</span>.<span class='ident'>push</span>(<span class='string'>"windows"</span>);
|
||
<span class='ident'>path</span>.<span class='ident'>push</span>(<span class='string'>"system32"</span>);
|
||
<span class='ident'>path</span>.<span class='ident'>set_extension</span>(<span class='string'>"dll"</span>);</pre>
|
||
|
||
<h2 id='path-components-and-normalization' class='section-header'><a href='#path-components-and-normalization'>Path components and normalization</a></h2>
|
||
<p>The path APIs are built around the notion of "components", which roughly
|
||
correspond to the substrings between path separators (<code>/</code> and, on Windows,
|
||
<code>\</code>). The APIs for path parsing are largely specified in terms of the path's
|
||
components, so it's important to clearly understand how those are
|
||
determined.</p>
|
||
|
||
<p>A path can always be reconstructed into an <em>equivalent</em> path by
|
||
putting together its components via <code>push</code>. Syntactically, the
|
||
paths may differ by the normalization described below.</p>
|
||
|
||
<h3 id='component-types' class='section-header'><a href='#component-types'>Component types</a></h3>
|
||
<p>Components come in several types:</p>
|
||
|
||
<ul>
|
||
<li><p>Normal components are the default: standard references to files or
|
||
directories. The path <code>a/b</code> has two normal components, <code>a</code> and <code>b</code>.</p></li>
|
||
<li><p>Current directory components represent the <code>.</code> character. For example,
|
||
<code>./a</code> has a current directory component and a normal component <code>a</code>.</p></li>
|
||
<li><p>The root directory component represents a separator that designates
|
||
starting from root. For example, <code>/a/b</code> has a root directory component
|
||
followed by normal components <code>a</code> and <code>b</code>.</p></li>
|
||
</ul>
|
||
|
||
<p>On Windows, an additional component type comes into play:</p>
|
||
|
||
<ul>
|
||
<li>Prefix components, of which there is a large variety. For example, <code>C:</code>
|
||
and <code>\\server\share</code> are prefixes. The path <code>C:windows</code> has a prefix
|
||
component <code>C:</code> and a normal component <code>windows</code>; the path <code>C:\windows</code> has a
|
||
prefix component <code>C:</code>, a root directory component, and a normal component
|
||
<code>windows</code>.</li>
|
||
</ul>
|
||
|
||
<h3 id='normalization' class='section-header'><a href='#normalization'>Normalization</a></h3>
|
||
<p>Aside from splitting on the separator(s), there is a small amount of
|
||
"normalization":</p>
|
||
|
||
<ul>
|
||
<li><p>Repeated separators are ignored: <code>a/b</code> and <code>a//b</code> both have components <code>a</code>
|
||
and <code>b</code>.</p></li>
|
||
<li><p>Occurrences of <code>.</code> are normalized away, <em>except</em> if they are at
|
||
the beginning of the path (in which case they are often meaningful
|
||
in terms of path searching). So, for example, <code>a/./b</code>, <code>a/b/</code>,
|
||
<code>/a/b/.</code> and <code>a/b</code> all have components <code>a</code> and <code>b</code>, but <code>./a/b</code>
|
||
has a leading current directory component.</p></li>
|
||
</ul>
|
||
|
||
<p>No other normalization takes place by default. In particular,
|
||
<code>a/c</code> and <code>a/b/../c</code> are distinct, to account for the possibility
|
||
that <code>b</code> is a symbolic link (so its parent isn't <code>a</code>). Further
|
||
normalization is possible to build on top of the components APIs,
|
||
and will be included in this library in the near future.</p>
|
||
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class='struct' href='struct.Components.html'
|
||
title='bitflags::__core::path::Components'>Components</a></td>
|
||
<td class='docblock short'>
|
||
<p>The core iterator giving the components of a path.</p>
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class='struct' href='struct.Display.html'
|
||
title='bitflags::__core::path::Display'>Display</a></td>
|
||
<td class='docblock short'>
|
||
<p>Helper struct for safely printing paths with <code>format!()</code> and <code>{}</code></p>
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class='struct' href='struct.Iter.html'
|
||
title='bitflags::__core::path::Iter'>Iter</a></td>
|
||
<td class='docblock short'>
|
||
<p>An iterator over the components of a path, as <code>OsStr</code> slices.</p>
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class='struct' href='struct.Path.html'
|
||
title='bitflags::__core::path::Path'>Path</a></td>
|
||
<td class='docblock short'>
|
||
<p>A slice of a path (akin to <code>str</code>).</p>
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class='struct' href='struct.PathBuf.html'
|
||
title='bitflags::__core::path::PathBuf'>PathBuf</a></td>
|
||
<td class='docblock short'>
|
||
<p>An owned, mutable path (akin to <code>String</code>).</p>
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class='struct' href='struct.PrefixComponent.html'
|
||
title='bitflags::__core::path::PrefixComponent'>PrefixComponent</a></td>
|
||
<td class='docblock short'>
|
||
<p>A Windows path prefix, e.g. <code>C:</code> or <code>\\server\share</code>.</p>
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class='struct' href='struct.StripPrefixError.html'
|
||
title='bitflags::__core::path::StripPrefixError'>StripPrefixError</a></td>
|
||
<td class='docblock short'>
|
||
<p>An error returned from the <code>Path::strip_prefix</code> method indicating that the
|
||
prefix was not found in <code>self</code>.</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='bitflags::__core::path::Component'>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='bitflags::__core::path::Prefix'>Prefix</a></td>
|
||
<td class='docblock short'>
|
||
<p>Path prefixes (Windows only).</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='bitflags::__core::path::MAIN_SEPARATOR'>MAIN_SEPARATOR</a></td>
|
||
<td class='docblock short'>
|
||
<p>The primary separator 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='bitflags::__core::path::is_separator'>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>?</dt>
|
||
<dd>Show this help dialog</dd>
|
||
<dt>S</dt>
|
||
<dd>Focus the search field</dd>
|
||
<dt>⇤</dt>
|
||
<dd>Move up in search results</dd>
|
||
<dt>⇥</dt>
|
||
<dd>Move down in search results</dd>
|
||
<dt>⏎</dt>
|
||
<dd>Go to active search result</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>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
|
||
|
||
<script>
|
||
window.rootPath = "../../../";
|
||
window.currentCrate = "bitflags";
|
||
window.playgroundUrl = "";
|
||
</script>
|
||
<script src="../../../jquery.js"></script>
|
||
<script src="../../../main.js"></script>
|
||
|
||
<script defer src="../../../search-index.js"></script>
|
||
</body>
|
||
</html> |