Created
September 18, 2017 22:17
-
-
Save abonander/ba3605b099864f5ea75f3bbe19dc645d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 `SourceFile` struct in crate `proc_macro`."> | |
<meta name="keywords" content="rust, rustlang, rust-lang, SourceFile"> | |
<title>proc_macro::SourceFile - Rust</title> | |
<link rel="stylesheet" type="text/css" href="../normalize.css"> | |
<link rel="stylesheet" type="text/css" href="../rustdoc.css"> | |
<link rel="stylesheet" type="text/css" href="../main.css"> | |
<link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"> | |
</head> | |
<body class="rustdoc struct"> | |
<!--[if lte IE 8]> | |
<div class="warning"> | |
This old browser is unsupported and will most likely display funky | |
things. | |
</div> | |
<![endif]--> | |
<nav class="sidebar"> | |
<a href='../proc_macro/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a> | |
<p class='location'>Struct SourceFile</p><div class="block items"><ul><li><a href="#deref-methods">Methods from Deref<Target=Path></a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='index.html'>proc_macro</a></p><script>window.sidebarCurrent = {name: 'SourceFile', ty: 'struct', 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"> | |
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>proc_macro</a>::<wbr><a class="struct" href=''>SourceFile</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version '></span><span id='render-detail'> | |
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> | |
[<span class='inner'>−</span>] | |
</a> | |
</span><a class='srclink' href='../src/proc_macro/lib.rs.html#274' title='goto source code'>[src]</a></span></h1> | |
<pre class='rust struct'>pub struct SourceFile(_);</pre><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>proc_macro </code><a href="https://github.com/rust-lang/rust/issues/38356">#38356</a>)</div></div><div class='docblock'><p>The source file of a given <code>Span</code>. Can be dereferenced to <code>Path</code>.</p> | |
</div> | |
<h2 id='deref-methods' class='small-section-header'> | |
Methods from <a class="trait" href="../core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = <a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>><a href='#deref-methods' class='anchor'></a> | |
</h2> | |
<div class='impl-items'><h4 id='method.as_os_str' class="method"><span id='as_os_str.v' class='invisible'><code>fn <a href='#method.as_os_str' class='fnname'>as_os_str</a>(&self) -> &<a class="struct" href="../std/ffi/os_str/struct.OsStr.html" title="struct std::ffi::os_str::OsStr">OsStr</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1608-1610' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Yields the underlying <a href="../ffi/struct.OsStr.html"><code>OsStr</code></a> slice.</p> | |
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1> | |
<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">os_str</span> <span class="op">=</span> <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>).<span class="ident">as_os_str</span>(); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">os_str</span>, <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20os_str%20%3D%20Path%3A%3Anew(%22foo.txt%22).as_os_str()%3B%0Aassert_eq!(os_str%2C%20std%3A%3Affi%3A%3AOsStr%3A%3Anew(%22foo.txt%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.to_str' class="method"><span id='to_str.v' class='invisible'><code>fn <a href='#method.to_str' class='fnname'>to_str</a>(&self) -> <a class="enum" href="../core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="primitive" href="../std/primitive.str.html">str</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1627-1629' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Yields a <a href="../primitive.str.html"><code>&str</code></a> slice if the <code>Path</code> is valid unicode.</p> | |
<p>This conversion may entail doing a check for UTF-8 validity.</p> | |
<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1> | |
<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">"foo.txt"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">to_str</span>(), <span class="prelude-val">Some</span>(<span class="string">"foo.txt"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22foo.txt%22)%3B%0Aassert_eq!(path.to_str()%2C%20Some(%22foo.txt%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.to_string_lossy' class="method"><span id='to_string_lossy.v' class='invisible'><code>fn <a href='#method.to_string_lossy' class='fnname'>to_string_lossy</a>(&self) -> <a class="enum" href="../alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><<a class="primitive" href="../std/primitive.str.html">str</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1651-1653' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Converts a <code>Path</code> to a <a href="../borrow/enum.Cow.html"><code>Cow<str></code></a>.</p> | |
<p>Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.</p> | |
<h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1> | |
<p>Calling <code>to_string_lossy</code> on a <code>Path</code> with valid unicode:</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">"foo.txt"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">to_string_lossy</span>(), <span class="string">"foo.txt"</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22foo.txt%22)%3B%0Aassert_eq!(path.to_string_lossy()%2C%20%22foo.txt%22)%3B%0A%7D">Run</a></pre> | |
<p>Had <code>path</code> contained invalid unicode, the <code>to_string_lossy</code> call might | |
have returned <code>"fo�.txt"</code>.</p> | |
</div><h4 id='method.to_path_buf' class="method"><span id='to_path_buf.v' class='invisible'><code>fn <a href='#method.to_path_buf' class='fnname'>to_path_buf</a>(&self) -> <a class="struct" href="../std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1668-1670' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Converts a <code>Path</code> to an owned <a href="struct.PathBuf.html"><code>PathBuf</code></a>.</p> | |
<h1 id='examples-3' class='section-header'><a href='#examples-3'>Examples</a></h1> | |
<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_buf</span> <span class="op">=</span> <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>).<span class="ident">to_path_buf</span>(); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path_buf</span>, <span class="ident">std</span>::<span class="ident">path</span>::<span class="ident">PathBuf</span>::<span class="ident">from</span>(<span class="string">"foo.txt"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path_buf%20%3D%20Path%3A%3Anew(%22foo.txt%22).to_path_buf()%3B%0Aassert_eq!(path_buf%2C%20std%3A%3Apath%3A%3APathBuf%3A%3Afrom(%22foo.txt%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.is_absolute' class="method"><span id='is_absolute.v' class='invisible'><code>fn <a href='#method.is_absolute' class='fnname'>is_absolute</a>(&self) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1692-1699' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns <code>true</code> if the <code>Path</code> is absolute, i.e. if it is independent of | |
the current directory.</p> | |
<ul> | |
<li><p>On Unix, a path is absolute if it starts with the root, so | |
<code>is_absolute</code> and <a href="#method.has_root"><code>has_root</code></a> are equivalent.</p></li> | |
<li><p>On Windows, a path is absolute if it has a prefix and starts with the | |
root: <code>c:\windows</code> is absolute, while <code>c:temp</code> and <code>\temp</code> are not.</p></li> | |
</ul> | |
<h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1> | |
<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="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>).<span class="ident">is_absolute</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Aassert!(!Path%3A%3Anew(%22foo.txt%22).is_absolute())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.is_relative' class="method"><span id='is_relative.v' class='invisible'><code>fn <a href='#method.is_relative' class='fnname'>is_relative</a>(&self) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1715-1717' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns <code>true</code> if the <code>Path</code> is relative, i.e. not absolute.</p> | |
<p>See <a href="#method.is_absolute"><code>is_absolute</code></a>'s documentation for more details.</p> | |
<h1 id='examples-5' class='section-header'><a href='#examples-5'>Examples</a></h1> | |
<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="macro">assert</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>).<span class="ident">is_relative</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Aassert!(Path%3A%3Anew(%22foo.txt%22).is_relative())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.has_root' class="method"><span id='has_root.v' class='invisible'><code>fn <a href='#method.has_root' class='fnname'>has_root</a>(&self) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1740-1742' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns <code>true</code> if the <code>Path</code> has a root.</p> | |
<ul> | |
<li><p>On Unix, a path has a root if it begins with <code>/</code>.</p></li> | |
<li><p>On Windows, a path has a root if it:</p> | |
<ul> | |
<li>has no prefix and begins with a separator, e.g. <code>\\windows</code></li> | |
<li>has a prefix followed by a separator, e.g. <code>c:\windows</code> but not <code>c:windows</code></li> | |
<li>has any non-disk prefix, e.g. <code>\\server\share</code></li> | |
</ul></li> | |
</ul> | |
<h1 id='examples-6' class='section-header'><a href='#examples-6'>Examples</a></h1> | |
<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="macro">assert</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/etc/passwd"</span>).<span class="ident">has_root</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Aassert!(Path%3A%3Anew(%22%2Fetc%2Fpasswd%22).has_root())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.parent' class="method"><span id='parent.v' class='invisible'><code>fn <a href='#method.parent' class='fnname'>parent</a>(&self) -> <a class="enum" href="../core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1764-1775' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns the <code>Path</code> without its final component, if there is one.</p> | |
<p>Returns <a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a> if the path terminates in a root or prefix.</p> | |
<h1 id='examples-7' class='section-header'><a href='#examples-7'>Examples</a></h1> | |
<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">"/foo/bar"</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="ident">unwrap</span>(); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">parent</span>, <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/foo"</span>)); | |
<span class="kw">let</span> <span class="ident">grand_parent</span> <span class="op">=</span> <span class="ident">parent</span>.<span class="ident">parent</span>().<span class="ident">unwrap</span>(); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">grand_parent</span>, <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/"</span>)); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">grand_parent</span>.<span class="ident">parent</span>(), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Ffoo%2Fbar%22)%3B%0Alet%20parent%20%3D%20path.parent().unwrap()%3B%0Aassert_eq!(parent%2C%20Path%3A%3Anew(%22%2Ffoo%22))%3B%0A%0Alet%20grand_parent%20%3D%20parent.parent().unwrap()%3B%0Aassert_eq!(grand_parent%2C%20Path%3A%3Anew(%22%2F%22))%3B%0Aassert_eq!(grand_parent.parent()%2C%20None)%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.file_name' class="method"><span id='file_name.v' class='invisible'><code>fn <a href='#method.file_name' class='fnname'>file_name</a>(&self) -> <a class="enum" href="../core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../std/ffi/os_str/struct.OsStr.html" title="struct std::ffi::os_str::OsStr">OsStr</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1800-1807' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns the final component of the <code>Path</code>, if there is one.</p> | |
<p>If the path is a normal file, this is the file name. If it's the path of a directory, this | |
is the directory name.</p> | |
<p>Returns <a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a> If the path terminates in <code>..</code>.</p> | |
<h1 id='examples-8' class='section-header'><a href='#examples-8'>Examples</a></h1> | |
<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="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"bin"</span>)), <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/usr/bin/"</span>).<span class="ident">file_name</span>()); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>)), <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"tmp/foo.txt"</span>).<span class="ident">file_name</span>()); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>)), <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"foo.txt/."</span>).<span class="ident">file_name</span>()); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>)), <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"foo.txt/.//"</span>).<span class="ident">file_name</span>()); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"foo.txt/.."</span>).<span class="ident">file_name</span>()); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/"</span>).<span class="ident">file_name</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0Ause%20std%3A%3Affi%3A%3AOsStr%3B%0A%0Aassert_eq!(Some(OsStr%3A%3Anew(%22bin%22))%2C%20Path%3A%3Anew(%22%2Fusr%2Fbin%2F%22).file_name())%3B%0Aassert_eq!(Some(OsStr%3A%3Anew(%22foo.txt%22))%2C%20Path%3A%3Anew(%22tmp%2Ffoo.txt%22).file_name())%3B%0Aassert_eq!(Some(OsStr%3A%3Anew(%22foo.txt%22))%2C%20Path%3A%3Anew(%22foo.txt%2F.%22).file_name())%3B%0Aassert_eq!(Some(OsStr%3A%3Anew(%22foo.txt%22))%2C%20Path%3A%3Anew(%22foo.txt%2F.%2F%2F%22).file_name())%3B%0Aassert_eq!(None%2C%20Path%3A%3Anew(%22foo.txt%2F..%22).file_name())%3B%0Aassert_eq!(None%2C%20Path%3A%3Anew(%22%2F%22).file_name())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.strip_prefix' class="method"><span id='strip_prefix.v' class='invisible'><code>fn <a href='#method.strip_prefix' class='fnname'>strip_prefix</a><P>(&'a self, base: <a class="primitive" href="../std/primitive.reference.html">&'a </a>P) -> <a class="enum" href="../core/result/enum.Result.html" title="enum core::result::Result">Result</a><&'a <a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>, <a class="struct" href="../std/path/struct.StripPrefixError.html" title="struct std::path::StripPrefixError">StripPrefixError</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>> + ?<a class="trait" href="../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../src/std/path.rs.html#1831-1836' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns a path that, when joined onto <code>base</code>, yields <code>self</code>.</p> | |
<h1 id='errors' class='section-header'><a href='#errors'>Errors</a></h1> | |
<p>If <code>base</code> is not a prefix of <code>self</code> (i.e. <a href="#method.starts_with"><code>starts_with</code></a> | |
returns <code>false</code>), returns <a href="../../std/result/enum.Result.html#variant.Err"><code>Err</code></a>.</p> | |
<h1 id='examples-9' class='section-header'><a href='#examples-9'>Examples</a></h1> | |
<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">"/test/haha/foo.txt"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">strip_prefix</span>(<span class="string">"/test"</span>), <span class="prelude-val">Ok</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"haha/foo.txt"</span>))); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">strip_prefix</span>(<span class="string">"test"</span>).<span class="ident">is_ok</span>(), <span class="bool-val">false</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">strip_prefix</span>(<span class="string">"/haha"</span>).<span class="ident">is_ok</span>(), <span class="bool-val">false</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Ftest%2Fhaha%2Ffoo.txt%22)%3B%0A%0Aassert_eq!(path.strip_prefix(%22%2Ftest%22)%2C%20Ok(Path%3A%3Anew(%22haha%2Ffoo.txt%22)))%3B%0Aassert_eq!(path.strip_prefix(%22test%22).is_ok()%2C%20false)%3B%0Aassert_eq!(path.strip_prefix(%22%2Fhaha%22).is_ok()%2C%20false)%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.starts_with' class="method"><span id='starts_with.v' class='invisible'><code>fn <a href='#method.starts_with' class='fnname'>starts_with</a><P>(&self, base: P) -> <a class="primitive" href="../std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1861-1863' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Determines whether <code>base</code> is a prefix of <code>self</code>.</p> | |
<p>Only considers whole path components to match.</p> | |
<h1 id='examples-10' class='section-header'><a href='#examples-10'>Examples</a></h1> | |
<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">"/etc/passwd"</span>); | |
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">starts_with</span>(<span class="string">"/etc"</span>)); | |
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">path</span>.<span class="ident">starts_with</span>(<span class="string">"/e"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Fetc%2Fpasswd%22)%3B%0A%0Aassert!(path.starts_with(%22%2Fetc%22))%3B%0A%0Aassert!(!path.starts_with(%22%2Fe%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.ends_with' class="method"><span id='ends_with.v' class='invisible'><code>fn <a href='#method.ends_with' class='fnname'>ends_with</a><P>(&self, child: P) -> <a class="primitive" href="../std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1883-1885' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Determines whether <code>child</code> is a suffix of <code>self</code>.</p> | |
<p>Only considers whole path components to match.</p> | |
<h1 id='examples-11' class='section-header'><a href='#examples-11'>Examples</a></h1> | |
<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">"/etc/passwd"</span>); | |
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">ends_with</span>(<span class="string">"passwd"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Fetc%2Fpasswd%22)%3B%0A%0Aassert!(path.ends_with(%22passwd%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.file_stem' class="method"><span id='file_stem.v' class='invisible'><code>fn <a href='#method.file_stem' class='fnname'>file_stem</a>(&self) -> <a class="enum" href="../core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../std/ffi/os_str/struct.OsStr.html" title="struct std::ffi::os_str::OsStr">OsStr</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1914-1916' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Extracts the stem (non-extension) portion of <a href="struct.Path.html#method.file_name"><code>self.file_name</code></a>.</p> | |
<p>The stem is:</p> | |
<ul> | |
<li><a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a>, if there is no file name;</li> | |
<li>The entire file name if there is no embedded <code>.</code>;</li> | |
<li>The entire file name if the file name begins with <code>.</code> and has no other <code>.</code>s within;</li> | |
<li>Otherwise, the portion of the file name before the final <code>.</code></li> | |
</ul> | |
<h1 id='examples-12' class='section-header'><a href='#examples-12'>Examples</a></h1> | |
<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">"foo.rs"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"foo"</span>, <span class="ident">path</span>.<span class="ident">file_stem</span>().<span class="ident">unwrap</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22foo.rs%22)%3B%0A%0Aassert_eq!(%22foo%22%2C%20path.file_stem().unwrap())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.extension' class="method"><span id='extension.v' class='invisible'><code>fn <a href='#method.extension' class='fnname'>extension</a>(&self) -> <a class="enum" href="../core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<a class="struct" href="../std/ffi/os_str/struct.OsStr.html" title="struct std::ffi::os_str::OsStr">OsStr</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1940-1942' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Extracts the extension of <a href="struct.Path.html#method.file_name"><code>self.file_name</code></a>, if possible.</p> | |
<p>The extension is:</p> | |
<ul> | |
<li><a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a>, if there is no file name;</li> | |
<li><a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a>, if there is no embedded <code>.</code>;</li> | |
<li><a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a>, if the file name begins with <code>.</code> and has no other <code>.</code>s within;</li> | |
<li>Otherwise, the portion of the file name after the final <code>.</code></li> | |
</ul> | |
<h1 id='examples-13' class='section-header'><a href='#examples-13'>Examples</a></h1> | |
<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">"foo.rs"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">"rs"</span>, <span class="ident">path</span>.<span class="ident">extension</span>().<span class="ident">unwrap</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22foo.rs%22)%3B%0A%0Aassert_eq!(%22rs%22%2C%20path.extension().unwrap())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.join' class="method"><span id='join.v' class='invisible'><code>fn <a href='#method.join' class='fnname'>join</a><P>(&self, path: P) -> <a class="struct" href="../std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1959-1961' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Creates an owned <a href="struct.PathBuf.html"><code>PathBuf</code></a> with <code>path</code> adjoined to <code>self</code>.</p> | |
<p>See <a href="struct.PathBuf.html#method.push"><code>PathBuf::push</code></a> for more details on what it means to adjoin a path.</p> | |
<h1 id='examples-14' class='section-header'><a href='#examples-14'>Examples</a></h1> | |
<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="ident">PathBuf</span>}; | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/etc"</span>).<span class="ident">join</span>(<span class="string">"passwd"</span>), <span class="ident">PathBuf</span>::<span class="ident">from</span>(<span class="string">"/etc/passwd"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3A%7BPath%2C%20PathBuf%7D%3B%0A%0Aassert_eq!(Path%3A%3Anew(%22%2Fetc%22).join(%22passwd%22)%2C%20PathBuf%3A%3Afrom(%22%2Fetc%2Fpasswd%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.with_file_name' class="method"><span id='with_file_name.v' class='invisible'><code>fn <a href='#method.with_file_name' class='fnname'>with_file_name</a><S>(&self, file_name: S) -> <a class="struct" href="../std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a> <span class="where fmt-newline">where<br> S: <a class="trait" href="../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="../std/ffi/os_str/struct.OsStr.html" title="struct std::ffi::os_str::OsStr">OsStr</a>>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#1988-1990' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Creates an owned <a href="struct.PathBuf.html"><code>PathBuf</code></a> like <code>self</code> but with the given file name.</p> | |
<p>See <a href="struct.PathBuf.html#method.set_file_name"><code>PathBuf::set_file_name</code></a> for more details.</p> | |
<h1 id='examples-15' class='section-header'><a href='#examples-15'>Examples</a></h1> | |
<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="ident">PathBuf</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.txt"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">with_file_name</span>(<span class="string">"bar.txt"</span>), <span class="ident">PathBuf</span>::<span class="ident">from</span>(<span class="string">"/tmp/bar.txt"</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"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">with_file_name</span>(<span class="string">"var"</span>), <span class="ident">PathBuf</span>::<span class="ident">from</span>(<span class="string">"/var"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3A%7BPath%2C%20PathBuf%7D%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Ftmp%2Ffoo.txt%22)%3B%0Aassert_eq!(path.with_file_name(%22bar.txt%22)%2C%20PathBuf%3A%3Afrom(%22%2Ftmp%2Fbar.txt%22))%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Ftmp%22)%3B%0Aassert_eq!(path.with_file_name(%22var%22)%2C%20PathBuf%3A%3Afrom(%22%2Fvar%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.with_extension' class="method"><span id='with_extension.v' class='invisible'><code>fn <a href='#method.with_extension' class='fnname'>with_extension</a><S>(&self, extension: S) -> <a class="struct" href="../std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a> <span class="where fmt-newline">where<br> S: <a class="trait" href="../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="../std/ffi/os_str/struct.OsStr.html" title="struct std::ffi::os_str::OsStr">OsStr</a>>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#2014-2016' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Creates an owned <a href="struct.PathBuf.html"><code>PathBuf</code></a> like <code>self</code> but with the given extension.</p> | |
<p>See <a href="struct.PathBuf.html#method.set_extension"><code>PathBuf::set_extension</code></a> for more details.</p> | |
<h1 id='examples-16' class='section-header'><a href='#examples-16'>Examples</a></h1> | |
<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="ident">PathBuf</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">"foo.rs"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">with_extension</span>(<span class="string">"txt"</span>), <span class="ident">PathBuf</span>::<span class="ident">from</span>(<span class="string">"foo.txt"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3A%7BPath%2C%20PathBuf%7D%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22foo.rs%22)%3B%0Aassert_eq!(path.with_extension(%22txt%22)%2C%20PathBuf%3A%3Afrom(%22foo.txt%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.components' class="method"><span id='components.v' class='invisible'><code>fn <a href='#method.components' class='fnname'>components</a>(&self) -> <a class="struct" href="../std/path/struct.Components.html" title="struct std::path::Components">Components</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#2057-2067' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Produces an iterator over the <a href="enum.Component.html"><code>Component</code></a>s of the path.</p> | |
<p>When parsing the path, there is a small amount of normalization:</p> | |
<ul> | |
<li><p>Repeated separators are ignored, so <code>a/b</code> and <code>a//b</code> both have | |
<code>a</code> and <code>b</code> as components.</p></li> | |
<li><p>Occurrences of <code>.</code> are normalized away, except if they are at the | |
beginning of the path. For example, <code>a/./b</code>, <code>a/b/</code>, <code>a/b/.</code> and | |
<code>a/b</code> all have <code>a</code> and <code>b</code> as components, but <code>./a/b</code> starts with | |
an additional <a href="enum.Component.html#variant.CurDir"><code>CurDir</code></a> component.</p></li> | |
</ul> | |
<p>Note that no other normalization takes place; 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>).</p> | |
<h1 id='examples-17' class='section-header'><a href='#examples-17'>Examples</a></h1> | |
<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="ident">Component</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="kw-2">mut</span> <span class="ident">components</span> <span class="op">=</span> <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/tmp/foo.txt"</span>).<span class="ident">components</span>(); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">components</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="ident">Component</span>::<span class="ident">RootDir</span>)); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">components</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="ident">Component</span>::<span class="ident">Normal</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"tmp"</span>)))); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">components</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="ident">Component</span>::<span class="ident">Normal</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>)))); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">components</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>)<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3A%7BPath%2C%20Component%7D%3B%0Ause%20std%3A%3Affi%3A%3AOsStr%3B%0A%0Alet%20mut%20components%20%3D%20Path%3A%3Anew(%22%2Ftmp%2Ffoo.txt%22).components()%3B%0A%0Aassert_eq!(components.next()%2C%20Some(Component%3A%3ARootDir))%3B%0Aassert_eq!(components.next()%2C%20Some(Component%3A%3ANormal(OsStr%3A%3Anew(%22tmp%22))))%3B%0Aassert_eq!(components.next()%2C%20Some(Component%3A%3ANormal(OsStr%3A%3Anew(%22foo.txt%22))))%3B%0Aassert_eq!(components.next()%2C%20None)%0A%7D">Run</a></pre> | |
</div><h4 id='method.iter' class="method"><span id='iter.v' class='invisible'><code>fn <a href='#method.iter' class='fnname'>iter</a>(&self) -> <a class="struct" href="../std/path/struct.Iter.html" title="struct std::path::Iter">Iter</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#2091-2093' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Produces an iterator over the path's components viewed as <a href="../ffi/struct.OsStr.html"><code>OsStr</code></a> | |
slices.</p> | |
<p>For more information about the particulars of how the path is separated | |
into components, see <a href="#method.components"><code>components</code></a>.</p> | |
<h1 id='examples-18' class='section-header'><a href='#examples-18'>Examples</a></h1> | |
<pre class="rust rust-example-rendered"> | |
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">path</span>::{<span class="self">self</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="kw-2">mut</span> <span class="ident">it</span> <span class="op">=</span> <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"/tmp/foo.txt"</span>).<span class="ident">iter</span>(); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">it</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="kw-2">&</span><span class="ident">path</span>::<span class="ident">MAIN_SEPARATOR</span>.<span class="ident">to_string</span>()))); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">it</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"tmp"</span>))); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">it</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="ident">OsStr</span>::<span class="ident">new</span>(<span class="string">"foo.txt"</span>))); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">it</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>)<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3A%7Bself%2C%20Path%7D%3B%0Ause%20std%3A%3Affi%3A%3AOsStr%3B%0A%0Alet%20mut%20it%20%3D%20Path%3A%3Anew(%22%2Ftmp%2Ffoo.txt%22).iter()%3B%0Aassert_eq!(it.next()%2C%20Some(OsStr%3A%3Anew(%26path%3A%3AMAIN_SEPARATOR.to_string())))%3B%0Aassert_eq!(it.next()%2C%20Some(OsStr%3A%3Anew(%22tmp%22)))%3B%0Aassert_eq!(it.next()%2C%20Some(OsStr%3A%3Anew(%22foo.txt%22)))%3B%0Aassert_eq!(it.next()%2C%20None)%0A%7D">Run</a></pre> | |
</div><h4 id='method.display' class="method"><span id='display.v' class='invisible'><code>fn <a href='#method.display' class='fnname'>display</a>(&self) -> <a class="struct" href="../std/path/struct.Display.html" title="struct std::path::Display">Display</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/std/path.rs.html#2110-2112' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns an object that implements <a href="../fmt/trait.Display.html"><code>Display</code></a> for safely printing paths | |
that may contain non-Unicode data.</p> | |
<h1 id='examples-19' class='section-header'><a href='#examples-19'>Examples</a></h1> | |
<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.rs"</span>); | |
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">path</span>.<span class="ident">display</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Ftmp%2Ffoo.rs%22)%3B%0A%0Aprintln!(%22%7B%7D%22%2C%20path.display())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.metadata' class="method"><span id='metadata.v' class='invisible'><code>fn <a href='#method.metadata' class='fnname'>metadata</a>(&self) -> <a class="enum" href="../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../std/fs/struct.Metadata.html" title="struct std::fs::Metadata">Metadata</a>, <a class="struct" href="../std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2133-2135' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Queries the file system to get information about a file, directory, etc.</p> | |
<p>This function will traverse symbolic links to query information about the | |
destination file.</p> | |
<p>This is an alias to <a href="../fs/fn.metadata.html"><code>fs::metadata</code></a>.</p> | |
<h1 id='examples-20' class='section-header'><a href='#examples-20'>Examples</a></h1> | |
<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">"/Minas/tirith"</span>); | |
<span class="kw">let</span> <span class="ident">metadata</span> <span class="op">=</span> <span class="ident">path</span>.<span class="ident">metadata</span>().<span class="ident">expect</span>(<span class="string">"metadata call failed"</span>); | |
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">metadata</span>.<span class="ident">file_type</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2FMinas%2Ftirith%22)%3B%0Alet%20metadata%20%3D%20path.metadata().expect(%22metadata%20call%20failed%22)%3B%0Aprintln!(%22%7B%3A%3F%7D%22%2C%20metadata.file_type())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.symlink_metadata' class="method"><span id='symlink_metadata.v' class='invisible'><code>fn <a href='#method.symlink_metadata' class='fnname'>symlink_metadata</a>(&self) -> <a class="enum" href="../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../std/fs/struct.Metadata.html" title="struct std::fs::Metadata">Metadata</a>, <a class="struct" href="../std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2153-2155' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Queries the metadata about a file without following symlinks.</p> | |
<p>This is an alias to <a href="../fs/fn.symlink_metadata.html"><code>fs::symlink_metadata</code></a>.</p> | |
<h1 id='examples-21' class='section-header'><a href='#examples-21'>Examples</a></h1> | |
<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">"/Minas/tirith"</span>); | |
<span class="kw">let</span> <span class="ident">metadata</span> <span class="op">=</span> <span class="ident">path</span>.<span class="ident">symlink_metadata</span>().<span class="ident">expect</span>(<span class="string">"symlink_metadata call failed"</span>); | |
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">metadata</span>.<span class="ident">file_type</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2FMinas%2Ftirith%22)%3B%0Alet%20metadata%20%3D%20path.symlink_metadata().expect(%22symlink_metadata%20call%20failed%22)%3B%0Aprintln!(%22%7B%3A%3F%7D%22%2C%20metadata.file_type())%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.canonicalize' class="method"><span id='canonicalize.v' class='invisible'><code>fn <a href='#method.canonicalize' class='fnname'>canonicalize</a>(&self) -> <a class="enum" href="../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>, <a class="struct" href="../std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2173-2175' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns the canonical form of the path with all intermediate components | |
normalized and symbolic links resolved.</p> | |
<p>This is an alias to <a href="../fs/fn.canonicalize.html"><code>fs::canonicalize</code></a>.</p> | |
<h1 id='examples-22' class='section-header'><a href='#examples-22'>Examples</a></h1> | |
<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="ident">PathBuf</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">"/foo/test/../test/bar.rs"</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">path</span>.<span class="ident">canonicalize</span>().<span class="ident">unwrap</span>(), <span class="ident">PathBuf</span>::<span class="ident">from</span>(<span class="string">"/foo/test/bar.rs"</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3A%7BPath%2C%20PathBuf%7D%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Ffoo%2Ftest%2F..%2Ftest%2Fbar.rs%22)%3B%0Aassert_eq!(path.canonicalize().unwrap()%2C%20PathBuf%3A%3Afrom(%22%2Ffoo%2Ftest%2Fbar.rs%22))%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.read_link' class="method"><span id='read_link.v' class='invisible'><code>fn <a href='#method.read_link' class='fnname'>read_link</a>(&self) -> <a class="enum" href="../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>, <a class="struct" href="../std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2192-2194' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Reads a symbolic link, returning the file that the link points to.</p> | |
<p>This is an alias to <a href="../fs/fn.read_link.html"><code>fs::read_link</code></a>.</p> | |
<h1 id='examples-23' class='section-header'><a href='#examples-23'>Examples</a></h1> | |
<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">"/laputa/sky_castle.rs"</span>); | |
<span class="kw">let</span> <span class="ident">path_link</span> <span class="op">=</span> <span class="ident">path</span>.<span class="ident">read_link</span>().<span class="ident">expect</span>(<span class="string">"read_link call failed"</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Flaputa%2Fsky_castle.rs%22)%3B%0Alet%20path_link%20%3D%20path.read_link().expect(%22read_link%20call%20failed%22)%3B%0A%7D">Run</a></pre> | |
</div><h4 id='method.read_dir' class="method"><span id='read_dir.v' class='invisible'><code>fn <a href='#method.read_dir' class='fnname'>read_dir</a>(&self) -> <a class="enum" href="../core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../std/fs/struct.ReadDir.html" title="struct std::fs::ReadDir">ReadDir</a>, <a class="struct" href="../std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2220-2222' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns an iterator over the entries within a directory.</p> | |
<p>The iterator will yield instances of <a href="../io/type.Result.html"><code>io::Result</code></a><code><</code><a href="../fs/struct.DirEntry.html"><code>DirEntry</code></a><code>></code>. New | |
errors may be encountered after an iterator is initially constructed.</p> | |
<p>This is an alias to <a href="../fs/fn.read_dir.html"><code>fs::read_dir</code></a>.</p> | |
<h1 id='examples-24' class='section-header'><a href='#examples-24'>Examples</a></h1> | |
<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">"/laputa"</span>); | |
<span class="kw">for</span> <span class="ident">entry</span> <span class="kw">in</span> <span class="ident">path</span>.<span class="ident">read_dir</span>().<span class="ident">expect</span>(<span class="string">"read_dir call failed"</span>) { | |
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Ok</span>(<span class="ident">entry</span>) <span class="op">=</span> <span class="ident">entry</span> { | |
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">entry</span>.<span class="ident">path</span>()); | |
} | |
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0A%0Alet%20path%20%3D%20Path%3A%3Anew(%22%2Flaputa%22)%3B%0Afor%20entry%20in%20path.read_dir().expect(%22read_dir%20call%20failed%22)%20%7B%0A%20%20%20%20if%20let%20Ok(entry)%20%3D%20entry%20%7B%0A%20%20%20%20%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20entry.path())%3B%0A%20%20%20%20%7D%0A%7D%0A%7D">Run</a></pre> | |
</div><h4 id='method.exists' class="method"><span id='exists.v' class='invisible'><code>fn <a href='#method.exists' class='fnname'>exists</a>(&self) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2246-2248' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns whether the path points at an existing entity.</p> | |
<p>This function will traverse symbolic links to query information about the | |
destination file. In case of broken symbolic links this will return <code>false</code>.</p> | |
<p>If you cannot access the directory containing the file, e.g. because of a | |
permission error, this will return <code>false</code>.</p> | |
<h1 id='examples-25' class='section-header'><a href='#examples-25'>Examples</a></h1> | |
<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="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"does_not_exist.txt"</span>).<span class="ident">exists</span>(), <span class="bool-val">false</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0Aassert_eq!(Path%3A%3Anew(%22does_not_exist.txt%22).exists()%2C%20false)%3B%0A%7D">Run</a></pre> | |
<h1 id='see-also' class='section-header'><a href='#see-also'>See Also</a></h1> | |
<p>This is a convenience function that coerces errors to false. If you want to | |
check errors, call <a href="../../std/fs/fn.metadata.html">fs::metadata</a>.</p> | |
</div><h4 id='method.is_file' class="method"><span id='is_file.v' class='invisible'><code>fn <a href='#method.is_file' class='fnname'>is_file</a>(&self) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2275-2277' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns whether the path exists on disk and is pointing at a regular file.</p> | |
<p>This function will traverse symbolic links to query information about the | |
destination file. In case of broken symbolic links this will return <code>false</code>.</p> | |
<p>If you cannot access the directory containing the file, e.g. because of a | |
permission error, this will return <code>false</code>.</p> | |
<h1 id='examples-26' class='section-header'><a href='#examples-26'>Examples</a></h1> | |
<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="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"./is_a_directory/"</span>).<span class="ident">is_file</span>(), <span class="bool-val">false</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"a_file.txt"</span>).<span class="ident">is_file</span>(), <span class="bool-val">true</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0Aassert_eq!(Path%3A%3Anew(%22.%2Fis_a_directory%2F%22).is_file()%2C%20false)%3B%0Aassert_eq!(Path%3A%3Anew(%22a_file.txt%22).is_file()%2C%20true)%3B%0A%7D">Run</a></pre> | |
<h1 id='see-also-1' class='section-header'><a href='#see-also-1'>See Also</a></h1> | |
<p>This is a convenience function that coerces errors to false. If you want to | |
check errors, call <a href="../../std/fs/fn.metadata.html">fs::metadata</a> and handle its Result. Then call | |
<a href="../../std/fs/struct.Metadata.html#method.is_file">fs::Metadata::is_file</a> if it was Ok.</p> | |
</div><h4 id='method.is_dir' class="method"><span id='is_dir.v' class='invisible'><code>fn <a href='#method.is_dir' class='fnname'>is_dir</a>(&self) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../src/std/path.rs.html#2304-2306' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns whether the path exists on disk and is pointing at a directory.</p> | |
<p>This function will traverse symbolic links to query information about the | |
destination file. In case of broken symbolic links this will return <code>false</code>.</p> | |
<p>If you cannot access the directory containing the file, e.g. because of a | |
permission error, this will return <code>false</code>.</p> | |
<h1 id='examples-27' class='section-header'><a href='#examples-27'>Examples</a></h1> | |
<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="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"./is_a_directory/"</span>).<span class="ident">is_dir</span>(), <span class="bool-val">true</span>); | |
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">"a_file.txt"</span>).<span class="ident">is_dir</span>(), <span class="bool-val">false</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Apath%3A%3APath%3B%0Aassert_eq!(Path%3A%3Anew(%22.%2Fis_a_directory%2F%22).is_dir()%2C%20true)%3B%0Aassert_eq!(Path%3A%3Anew(%22a_file.txt%22).is_dir()%2C%20false)%3B%0A%7D">Run</a></pre> | |
<h1 id='see-also-2' class='section-header'><a href='#see-also-2'>See Also</a></h1> | |
<p>This is a convenience function that coerces errors to false. If you want to | |
check errors, call <a href="../../std/fs/fn.metadata.html">fs::metadata</a> and handle its Result. Then call | |
<a href="../../std/fs/struct.Metadata.html#method.is_dir">fs::Metadata::is_dir</a> if it was Ok.</p> | |
</div></div> | |
<h2 id='implementations' class='small-section-header'> | |
Trait Implementations<a href='#implementations' class='anchor'></a> | |
</h2> | |
<h3 id='impl-Clone' class='impl'><span class='in-band'><code>impl <a class="trait" href="../core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code><a href='#impl-Clone' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#273' title='goto source code'>[src]</a></span></h3> | |
<div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='../core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#273' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Returns a copy of the value. <a href="../core/clone/trait.Clone.html#tymethod.clone">Read more</a></p> | |
</div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='../core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: <a class="primitive" href="../std/primitive.reference.html">&</a>Self)</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/core/clone.rs.html#112-114' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="../core/clone/trait.Clone.html#method.clone_from">Read more</a></p> | |
</div></div><h3 id='impl-AsRef<Path>' class='impl'><span class='in-band'><code>impl <a class="trait" href="../core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>> for <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code><a href='#impl-AsRef<Path>' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#277-281' title='goto source code'>[src]</a></span></h3> | |
<div class='impl-items'><h4 id='method.as_ref' class="method"><span id='as_ref.v' class='invisible'><code>fn <a href='../core/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> &<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#278-280' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Performs the conversion.</p> | |
</div></div><h3 id='impl-Deref' class='impl'><span class='in-band'><code>impl <a class="trait" href="../core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code><a href='#impl-Deref' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#284-290' title='goto source code'>[src]</a></span></h3> | |
<div class='impl-items'><h4 id='associatedtype.Target' class="type"><span id='Target.t' class='invisible'><code>type <a href='../core/ops/deref/trait.Deref.html#associatedtype.Target' class="type">Target</a> = <a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a></code></span></h4> | |
<div class='docblock'><p>The resulting type after dereferencing.</p> | |
</div><h4 id='method.deref' class="method"><span id='deref.v' class='invisible'><code>fn <a href='../core/ops/deref/trait.Deref.html#tymethod.deref' class='fnname'>deref</a>(&self) -> &Self::<a class="type" href="../core/ops/deref/trait.Deref.html#associatedtype.Target" title="type core::ops::deref::Deref::Target">Target</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#287-289' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Dereferences the value.</p> | |
</div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl <a class="trait" href="../core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#293-299' title='goto source code'>[src]</a></span></h3> | |
<div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -> <a class="type" href="../core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#294-298' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>Formats the value using the given formatter.</p> | |
</div></div><h3 id='impl-PartialEq' class='impl'><span class='in-band'><code>impl <a class="trait" href="../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a> for <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code><a href='#impl-PartialEq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#302-306' title='goto source code'>[src]</a></span></h3> | |
<div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: <a class="primitive" href="../std/primitive.reference.html">&</a>Self) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#303-305' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p> | |
</div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: <a class="primitive" href="../std/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/core/cmp.rs.html#121' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>This method tests for <code>!=</code>.</p> | |
</div></div><h3 id='impl-Eq' class='impl'><span class='in-band'><code>impl <a class="trait" href="../core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code><a href='#impl-Eq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#309' title='goto source code'>[src]</a></span></h3> | |
<div class='impl-items'></div><h3 id='impl-PartialEq<Path>' class='impl'><span class='in-band'><code>impl <a class="trait" href="../core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>> for <a class="struct" href="../proc_macro/struct.SourceFile.html" title="struct proc_macro::SourceFile">SourceFile</a></code><a href='#impl-PartialEq<Path>' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#312-316' title='goto source code'>[src]</a></span></h3> | |
<div class='impl-items'><h4 id='method.eq-1' class="method"><span id='eq.v-1' class='invisible'><code>fn <a href='../core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../std/path/struct.Path.html" title="struct std::path::Path">Path</a>) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/proc_macro/lib.rs.html#313-315' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p> | |
</div><h4 id='method.ne-1' class="method"><span id='ne.v-1' class='invisible'><code>fn <a href='../core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: <a class="primitive" href="../std/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="../std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../src/core/cmp.rs.html#121' title='goto source code'>[src]</a></span></h4> | |
<div class='docblock'><p>This method tests for <code>!=</code>.</p> | |
</div></div></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> | |
<dt>+</dt> | |
<dd>Collapse/expand 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> | |
</div> | |
</div> | |
</aside> | |
<script> | |
window.rootPath = "../"; | |
window.currentCrate = "proc_macro"; | |
</script> | |
<script src="../main.js"></script> | |
<script defer src="../search-index.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment