forked from pola-rs/polars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
additional_attributes.rs.html
143 lines (143 loc) · 9.52 KB
/
additional_attributes.rs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!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="Source of the Rust file `/home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/strum-0.20.0/src/additional_attributes.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>additional_attributes.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../strum/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
<span id="34">34</span>
<span id="35">35</span>
<span id="36">36</span>
<span id="37">37</span>
<span id="38">38</span>
<span id="39">39</span>
<span id="40">40</span>
<span id="41">41</span>
<span id="42">42</span>
<span id="43">43</span>
<span id="44">44</span>
<span id="45">45</span>
<span id="46">46</span>
<span id="47">47</span>
<span id="48">48</span>
<span id="49">49</span>
<span id="50">50</span>
<span id="51">51</span>
<span id="52">52</span>
<span id="53">53</span>
<span id="54">54</span>
<span id="55">55</span>
<span id="56">56</span>
<span id="57">57</span>
<span id="58">58</span>
<span id="59">59</span>
<span id="60">60</span>
<span id="61">61</span>
<span id="62">62</span>
<span id="63">63</span>
<span id="64">64</span>
<span id="65">65</span>
<span id="66">66</span>
<span id="67">67</span>
<span id="68">68</span>
</pre><div class="example-wrap"><pre class="rust ">
<span class="doccomment">//! # Documentation for Additional Attributes</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! Strum supports several custom attributes to modify the generated code. At the enum level, the</span>
<span class="doccomment">//! `#[strum(serialize_all = "snake_case")]` attribute can be used to change the case used when</span>
<span class="doccomment">//! serializing to and deserializing from strings:</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! ```rust</span>
<span class="doccomment">//! use std::string::ToString;</span>
<span class="doccomment">//! use strum;</span>
<span class="doccomment">//! use strum_macros;</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! #[derive(Debug, Eq, PartialEq, strum_macros::ToString)]</span>
<span class="doccomment">//! #[strum(serialize_all = "snake_case")]</span>
<span class="doccomment">//! enum Brightness {</span>
<span class="doccomment">//! DarkBlack,</span>
<span class="doccomment">//! Dim {</span>
<span class="doccomment">//! glow: usize,</span>
<span class="doccomment">//! },</span>
<span class="doccomment">//! #[strum(serialize = "bright")]</span>
<span class="doccomment">//! BrightWhite,</span>
<span class="doccomment">//! }</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! assert_eq!(</span>
<span class="doccomment">//! String::from("dark_black"),</span>
<span class="doccomment">//! Brightness::DarkBlack.to_string().as_ref()</span>
<span class="doccomment">//! );</span>
<span class="doccomment">//! assert_eq!(</span>
<span class="doccomment">//! String::from("dim"),</span>
<span class="doccomment">//! Brightness::Dim { glow: 0 }.to_string().as_ref()</span>
<span class="doccomment">//! );</span>
<span class="doccomment">//! assert_eq!(</span>
<span class="doccomment">//! String::from("bright"),</span>
<span class="doccomment">//! Brightness::BrightWhite.to_string().as_ref()</span>
<span class="doccomment">//! );</span>
<span class="doccomment">//! ```</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! Custom attributes are applied to a variant by adding `#[strum(parameter="value")]` to the variant.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! - `serialize="..."`: Changes the text that `FromStr()` looks for when parsing a string. This attribute can</span>
<span class="doccomment">//! be applied multiple times to an element and the enum variant will be parsed if any of them match.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! - `to_string="..."`: Similar to `serialize`. This value will be included when using `FromStr()`. More importantly,</span>
<span class="doccomment">//! this specifies what text to use when calling `variant.to_string()` with the `ToString` derivation, or when calling `variant.as_ref()` with `AsRefStr`.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! - `default`: Applied to a single variant of an enum. The variant must be a Tuple-like</span>
<span class="doccomment">//! variant with a single piece of data that can be create from a `&str` i.e. `T: From<&str>`.</span>
<span class="doccomment">//! The generated code will now return the variant with the input string captured as shown below</span>
<span class="doccomment">//! instead of failing.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! ```rust,ignore</span>
<span class="doccomment">//! // Replaces this:</span>
<span class="doccomment">//! _ => Err(strum::ParseError::VariantNotFound)</span>
<span class="doccomment">//! // With this in generated code:</span>
<span class="doccomment">//! default => Ok(Variant(default.into()))</span>
<span class="doccomment">//! ```</span>
<span class="doccomment">//! The plugin will fail if the data doesn't implement From<&str>. You can only have one `default`</span>
<span class="doccomment">//! on your enum.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! - `disabled`: removes variant from generated code.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! - `message=".."`: Adds a message to enum variant. This is used in conjunction with the `EnumMessage`</span>
<span class="doccomment">//! trait to associate a message with a variant. If `detailed_message` is not provided,</span>
<span class="doccomment">//! then `message` will also be returned when get_detailed_message() is called.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! - `detailed_message=".."`: Adds a more detailed message to a variant. If this value is omitted, then</span>
<span class="doccomment">//! `message` will be used in it's place.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! - `props(key="value")`: Enables associating additional information with a given variant.</span>
</pre></div>
</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="strum" data-search-js="../../search-index.js"></div>
<script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>