172 lines
7.8 KiB
HTML
172 lines
7.8 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 `modifiers` mod in crate `iron`.">
|
|||
|
<meta name="keywords" content="rust, rustlang, rust-lang, modifiers">
|
|||
|
|
|||
|
<title>iron::modifiers - Rust</title>
|
|||
|
|
|||
|
<link rel="stylesheet" type="text/css" href="../../rustdoc.css">
|
|||
|
<link rel="stylesheet" type="text/css" href="../../main.css">
|
|||
|
|
|||
|
|
|||
|
<link rel="shortcut icon" href="https://avatars0.githubusercontent.com/u/7853871?s=256">
|
|||
|
|
|||
|
</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">
|
|||
|
<a href='../../iron/index.html'><img src='https://avatars0.githubusercontent.com/u/7853871?s=128' alt='logo' width='100'></a>
|
|||
|
<p class='location'><a href='../index.html'>iron</a></p><script>window.sidebarCurrent = {name: 'modifiers', 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'>iron</a>::<wbr><a class='mod' href=''>modifiers</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-543' class='srclink' href='../../src/iron/modifiers.rs.html#1-197' title='goto source code'>[src]</a></span></h1>
|
|||
|
<div class='docblock'><p>This module defines a series of convenience modifiers for changing
|
|||
|
Responses.</p>
|
|||
|
|
|||
|
<p>Modifiers can be used to edit <code>Response</code>s through the owning method <code>set</code>
|
|||
|
or the mutating <code>set_mut</code>, both of which are defined in the <code>Set</code> trait.</p>
|
|||
|
|
|||
|
<p>For Iron, the <code>Modifier</code> interface offers extensible and ergonomic response
|
|||
|
creation while avoiding the introduction of many highly specific <code>Response</code>
|
|||
|
constructors.</p>
|
|||
|
|
|||
|
<p>The simplest case of a modifier is probably the one used to change the
|
|||
|
return status code:</p>
|
|||
|
|
|||
|
<pre class='rust rust-example-rendered'>
|
|||
|
<span class='kw'>let</span> <span class='ident'>r</span> <span class='op'>=</span> <span class='ident'>Response</span>::<span class='ident'>with</span>(<span class='ident'>status</span>::<span class='ident'>NotFound</span>);
|
|||
|
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>r</span>.<span class='ident'>status</span>.<span class='ident'>unwrap</span>().<span class='ident'>to_u16</span>(), <span class='number'>404</span>);</pre>
|
|||
|
|
|||
|
<p>You can also pass in a tuple of modifiers, they will all be applied. Here's
|
|||
|
an example of a modifier 2-tuple that will change the status code and the
|
|||
|
body message:</p>
|
|||
|
|
|||
|
<pre class='rust rust-example-rendered'>
|
|||
|
<span class='ident'>Response</span>::<span class='ident'>with</span>((<span class='ident'>status</span>::<span class='ident'>ImATeapot</span>, <span class='string'>"I am a tea pot!"</span>));</pre>
|
|||
|
|
|||
|
<p>There is also a <code>Redirect</code> modifier:</p>
|
|||
|
|
|||
|
<pre class='rust rust-example-rendered'>
|
|||
|
<span class='kw'>let</span> <span class='ident'>url</span> <span class='op'>=</span> <span class='ident'>Url</span>::<span class='ident'>parse</span>(<span class='string'>"http://doc.rust-lang.org"</span>).<span class='ident'>unwrap</span>();
|
|||
|
<span class='ident'>Response</span>::<span class='ident'>with</span>((<span class='ident'>status</span>::<span class='ident'>Found</span>, <span class='ident'>modifiers</span>::<span class='ident'>Redirect</span>(<span class='ident'>url</span>)));</pre>
|
|||
|
|
|||
|
<p>The modifiers are applied depending on their type. Currently the easiest
|
|||
|
way to see how different types are used as modifiers, take a look at <a href="https://github.com/iron/iron/blob/master/src/modifiers.rs">the
|
|||
|
source code</a>.</p>
|
|||
|
|
|||
|
<p>For more information about the modifier system, see
|
|||
|
<a href="https://github.com/reem/rust-modifier">rust-modifier</a>.</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.Header.html'
|
|||
|
title='iron::modifiers::Header'>Header</a></td>
|
|||
|
<td class='docblock short'>
|
|||
|
<p>A modifier for changing headers on requests and responses.</p>
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
<tr class=' module-item'>
|
|||
|
<td><a class='struct' href='struct.Redirect.html'
|
|||
|
title='iron::modifiers::Redirect'>Redirect</a></td>
|
|||
|
<td class='docblock short'>
|
|||
|
<p>A modifier for creating redirect responses.</p>
|
|||
|
</td>
|
|||
|
</tr>
|
|||
|
<tr class=' module-item'>
|
|||
|
<td><a class='struct' href='struct.RedirectRaw.html'
|
|||
|
title='iron::modifiers::RedirectRaw'>RedirectRaw</a></td>
|
|||
|
<td class='docblock short'>
|
|||
|
<p>A modifier for creating redirect responses.</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>
|
|||
|
<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 = "iron";
|
|||
|
window.playgroundUrl = "";
|
|||
|
</script>
|
|||
|
<script src="../../jquery.js"></script>
|
|||
|
<script src="../../main.js"></script>
|
|||
|
|
|||
|
<script defer src="../../search-index.js"></script>
|
|||
|
</body>
|
|||
|
</html>
|