+/livesplit-wrapper

git clone https://git.julia.blue/+/livesplit-wrapper

P1n3appl3deploy: 9b9f353f3b0e319547cabc5dcadc542d5ab54386b0170e4

gh-pages
23.2 KiB500 linesraw
1<!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/bytemuck-1.12.1/src/transparent.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>transparent.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../source-script.js"></script><script defer src="../../source-files.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../bytemuck/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../bytemuck/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../bytemuck/index.html"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="example-wrap"><pre class="line-numbers"><span id="1">1</span>
2<span id="2">2</span>
3<span id="3">3</span>
4<span id="4">4</span>
5<span id="5">5</span>
6<span id="6">6</span>
7<span id="7">7</span>
8<span id="8">8</span>
9<span id="9">9</span>
10<span id="10">10</span>
11<span id="11">11</span>
12<span id="12">12</span>
13<span id="13">13</span>
14<span id="14">14</span>
15<span id="15">15</span>
16<span id="16">16</span>
17<span id="17">17</span>
18<span id="18">18</span>
19<span id="19">19</span>
20<span id="20">20</span>
21<span id="21">21</span>
22<span id="22">22</span>
23<span id="23">23</span>
24<span id="24">24</span>
25<span id="25">25</span>
26<span id="26">26</span>
27<span id="27">27</span>
28<span id="28">28</span>
29<span id="29">29</span>
30<span id="30">30</span>
31<span id="31">31</span>
32<span id="32">32</span>
33<span id="33">33</span>
34<span id="34">34</span>
35<span id="35">35</span>
36<span id="36">36</span>
37<span id="37">37</span>
38<span id="38">38</span>
39<span id="39">39</span>
40<span id="40">40</span>
41<span id="41">41</span>
42<span id="42">42</span>
43<span id="43">43</span>
44<span id="44">44</span>
45<span id="45">45</span>
46<span id="46">46</span>
47<span id="47">47</span>
48<span id="48">48</span>
49<span id="49">49</span>
50<span id="50">50</span>
51<span id="51">51</span>
52<span id="52">52</span>
53<span id="53">53</span>
54<span id="54">54</span>
55<span id="55">55</span>
56<span id="56">56</span>
57<span id="57">57</span>
58<span id="58">58</span>
59<span id="59">59</span>
60<span id="60">60</span>
61<span id="61">61</span>
62<span id="62">62</span>
63<span id="63">63</span>
64<span id="64">64</span>
65<span id="65">65</span>
66<span id="66">66</span>
67<span id="67">67</span>
68<span id="68">68</span>
69<span id="69">69</span>
70<span id="70">70</span>
71<span id="71">71</span>
72<span id="72">72</span>
73<span id="73">73</span>
74<span id="74">74</span>
75<span id="75">75</span>
76<span id="76">76</span>
77<span id="77">77</span>
78<span id="78">78</span>
79<span id="79">79</span>
80<span id="80">80</span>
81<span id="81">81</span>
82<span id="82">82</span>
83<span id="83">83</span>
84<span id="84">84</span>
85<span id="85">85</span>
86<span id="86">86</span>
87<span id="87">87</span>
88<span id="88">88</span>
89<span id="89">89</span>
90<span id="90">90</span>
91<span id="91">91</span>
92<span id="92">92</span>
93<span id="93">93</span>
94<span id="94">94</span>
95<span id="95">95</span>
96<span id="96">96</span>
97<span id="97">97</span>
98<span id="98">98</span>
99<span id="99">99</span>
100<span id="100">100</span>
101<span id="101">101</span>
102<span id="102">102</span>
103<span id="103">103</span>
104<span id="104">104</span>
105<span id="105">105</span>
106<span id="106">106</span>
107<span id="107">107</span>
108<span id="108">108</span>
109<span id="109">109</span>
110<span id="110">110</span>
111<span id="111">111</span>
112<span id="112">112</span>
113<span id="113">113</span>
114<span id="114">114</span>
115<span id="115">115</span>
116<span id="116">116</span>
117<span id="117">117</span>
118<span id="118">118</span>
119<span id="119">119</span>
120<span id="120">120</span>
121<span id="121">121</span>
122<span id="122">122</span>
123<span id="123">123</span>
124<span id="124">124</span>
125<span id="125">125</span>
126<span id="126">126</span>
127<span id="127">127</span>
128<span id="128">128</span>
129<span id="129">129</span>
130<span id="130">130</span>
131<span id="131">131</span>
132<span id="132">132</span>
133<span id="133">133</span>
134<span id="134">134</span>
135<span id="135">135</span>
136<span id="136">136</span>
137<span id="137">137</span>
138<span id="138">138</span>
139<span id="139">139</span>
140<span id="140">140</span>
141<span id="141">141</span>
142<span id="142">142</span>
143<span id="143">143</span>
144<span id="144">144</span>
145<span id="145">145</span>
146<span id="146">146</span>
147<span id="147">147</span>
148<span id="148">148</span>
149<span id="149">149</span>
150<span id="150">150</span>
151<span id="151">151</span>
152<span id="152">152</span>
153<span id="153">153</span>
154<span id="154">154</span>
155<span id="155">155</span>
156<span id="156">156</span>
157<span id="157">157</span>
158<span id="158">158</span>
159<span id="159">159</span>
160<span id="160">160</span>
161<span id="161">161</span>
162<span id="162">162</span>
163<span id="163">163</span>
164<span id="164">164</span>
165<span id="165">165</span>
166<span id="166">166</span>
167<span id="167">167</span>
168<span id="168">168</span>
169<span id="169">169</span>
170<span id="170">170</span>
171<span id="171">171</span>
172<span id="172">172</span>
173<span id="173">173</span>
174<span id="174">174</span>
175<span id="175">175</span>
176<span id="176">176</span>
177<span id="177">177</span>
178<span id="178">178</span>
179<span id="179">179</span>
180<span id="180">180</span>
181<span id="181">181</span>
182<span id="182">182</span>
183<span id="183">183</span>
184<span id="184">184</span>
185<span id="185">185</span>
186<span id="186">186</span>
187<span id="187">187</span>
188<span id="188">188</span>
189<span id="189">189</span>
190<span id="190">190</span>
191<span id="191">191</span>
192<span id="192">192</span>
193<span id="193">193</span>
194<span id="194">194</span>
195<span id="195">195</span>
196<span id="196">196</span>
197<span id="197">197</span>
198<span id="198">198</span>
199<span id="199">199</span>
200<span id="200">200</span>
201<span id="201">201</span>
202<span id="202">202</span>
203<span id="203">203</span>
204<span id="204">204</span>
205<span id="205">205</span>
206<span id="206">206</span>
207<span id="207">207</span>
208<span id="208">208</span>
209<span id="209">209</span>
210<span id="210">210</span>
211<span id="211">211</span>
212<span id="212">212</span>
213<span id="213">213</span>
214<span id="214">214</span>
215<span id="215">215</span>
216<span id="216">216</span>
217<span id="217">217</span>
218<span id="218">218</span>
219<span id="219">219</span>
220<span id="220">220</span>
221<span id="221">221</span>
222<span id="222">222</span>
223<span id="223">223</span>
224<span id="224">224</span>
225<span id="225">225</span>
226<span id="226">226</span>
227<span id="227">227</span>
228<span id="228">228</span>
229<span id="229">229</span>
230<span id="230">230</span>
231<span id="231">231</span>
232<span id="232">232</span>
233<span id="233">233</span>
234<span id="234">234</span>
235<span id="235">235</span>
236<span id="236">236</span>
237<span id="237">237</span>
238<span id="238">238</span>
239<span id="239">239</span>
240<span id="240">240</span>
241<span id="241">241</span>
242<span id="242">242</span>
243<span id="243">243</span>
244<span id="244">244</span>
245<span id="245">245</span>
246<span id="246">246</span>
247<span id="247">247</span>
248<span id="248">248</span>
249<span id="249">249</span>
250</pre><pre class="rust"><code><span class="kw">use super</span>::<span class="kw-2">*</span>;
251
252<span class="doccomment">/// A trait which indicates that a type is a `#[repr(transparent)]` wrapper
253/// around the `Inner` value.
254///
255/// This allows safely copy transmuting between the `Inner` type and the
256/// `TransparentWrapper` type. Functions like `wrap_{}` convert from the inner
257/// type to the wrapper type and `peel_{}` functions do the inverse conversion
258/// from the wrapper type to the inner type. We deliberately do not call the
259/// wrapper-removing methods &quot;unwrap&quot; because at this point that word is too
260/// strongly tied to the Option/ Result methods.
261///
262/// # Safety
263///
264/// The safety contract of `TransparentWrapper` is relatively simple:
265///
266/// For a given `Wrapper` which implements `TransparentWrapper&lt;Inner&gt;`:
267///
268/// 1. `Wrapper` must be a wrapper around `Inner` with an identical data
269///    representations. This    either means that it must be a
270///    `#[repr(transparent)]` struct which    contains a either a field of type
271///    `Inner` (or a field of some other    transparent wrapper for `Inner`) as
272///    the only non-ZST field.
273///
274/// 2. Any fields *other* than the `Inner` field must be trivially constructable
275///    ZSTs, for example `PhantomData`, `PhantomPinned`, etc.
276///
277/// 3. The `Wrapper` may not impose additional alignment requirements over
278///    `Inner`.
279///     - Note: this is currently guaranteed by `repr(transparent)`, but there
280///       have been discussions of lifting it, so it&#39;s stated here explicitly.
281///
282/// 4. All functions on `TransparentWrapper` **may not** be overridden.
283///
284/// ## Caveats
285///
286/// If the wrapper imposes additional constraints upon the inner type which are
287/// required for safety, it&#39;s responsible for ensuring those still hold -- this
288/// generally requires preventing access to instances of the inner type, as
289/// implementing `TransparentWrapper&lt;U&gt; for T` means anybody can call
290/// `T::cast_ref(any_instance_of_u)`.
291///
292/// For example, it would be invalid to implement TransparentWrapper for `str`
293/// to implement `TransparentWrapper` around `[u8]` because of this.
294///
295/// # Examples
296///
297/// ## Basic
298///
299/// ```
300/// use bytemuck::TransparentWrapper;
301/// # #[derive(Default)]
302/// # struct SomeStruct(u32);
303///
304/// #[repr(transparent)]
305/// struct MyWrapper(SomeStruct);
306///
307/// unsafe impl TransparentWrapper&lt;SomeStruct&gt; for MyWrapper {}
308///
309/// // interpret a reference to &amp;SomeStruct as a &amp;MyWrapper
310/// let thing = SomeStruct::default();
311/// let inner_ref: &amp;MyWrapper = MyWrapper::wrap_ref(&amp;thing);
312///
313/// // Works with &amp;mut too.
314/// let mut mut_thing = SomeStruct::default();
315/// let inner_mut: &amp;mut MyWrapper = MyWrapper::wrap_mut(&amp;mut mut_thing);
316///
317/// # let _ = (inner_ref, inner_mut); // silence warnings
318/// ```
319///
320/// ## Use with dynamically sized types
321///
322/// ```
323/// use bytemuck::TransparentWrapper;
324///
325/// #[repr(transparent)]
326/// struct Slice&lt;T&gt;([T]);
327///
328/// unsafe impl&lt;T&gt; TransparentWrapper&lt;[T]&gt; for Slice&lt;T&gt; {}
329///
330/// let s = Slice::wrap_ref(&amp;[1u32, 2, 3]);
331/// assert_eq!(&amp;s.0, &amp;[1, 2, 3]);
332///
333/// let mut buf = [1, 2, 3u8];
334/// let sm = Slice::wrap_mut(&amp;mut buf);
335/// ```
336</span><span class="kw">pub unsafe trait </span>TransparentWrapper&lt;Inner: <span class="question-mark">?</span>Sized&gt; {
337  <span class="doccomment">/// Convert the inner type into the wrapper type.
338  </span><span class="attribute">#[inline]
339  </span><span class="kw">fn </span>wrap(s: Inner) -&gt; <span class="self">Self
340  </span><span class="kw">where
341    </span><span class="self">Self</span>: Sized,
342    Inner: Sized,
343  {
344    <span class="comment">// SAFETY: The unsafe contract requires that `Self` and `Inner` have
345    // identical representations.
346    </span><span class="kw">unsafe </span>{ <span class="macro">transmute!</span>(s) }
347  }
348
349  <span class="doccomment">/// Convert a reference to the inner type into a reference to the wrapper
350  /// type.
351  </span><span class="attribute">#[inline]
352  </span><span class="kw">fn </span>wrap_ref(s: <span class="kw-2">&amp;</span>Inner) -&gt; <span class="kw-2">&amp;</span><span class="self">Self </span>{
353    <span class="kw">unsafe </span>{
354      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*const </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*const </span><span class="self">Self</span>&gt;());
355      <span class="comment">// A pointer cast doesn&#39;t work here because rustc can&#39;t tell that
356      // the vtables match (because of the `?Sized` restriction relaxation).
357      // A `transmute` doesn&#39;t work because the sizes are unspecified.
358      //
359      // SAFETY: The unsafe contract requires that these two have
360      // identical representations.
361      </span><span class="kw">let </span>inner_ptr = s <span class="kw">as </span><span class="kw-2">*const </span>Inner;
362      <span class="kw">let </span>wrapper_ptr: <span class="kw-2">*const </span><span class="self">Self </span>= <span class="macro">transmute!</span>(inner_ptr);
363      <span class="kw-2">&amp;*</span>wrapper_ptr
364    }
365  }
366
367  <span class="doccomment">/// Convert a mutable reference to the inner type into a mutable reference to
368  /// the wrapper type.
369  </span><span class="attribute">#[inline]
370  </span><span class="kw">fn </span>wrap_mut(s: <span class="kw-2">&amp;mut </span>Inner) -&gt; <span class="kw-2">&amp;mut </span><span class="self">Self </span>{
371    <span class="kw">unsafe </span>{
372      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*mut </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*mut </span><span class="self">Self</span>&gt;());
373      <span class="comment">// A pointer cast doesn&#39;t work here because rustc can&#39;t tell that
374      // the vtables match (because of the `?Sized` restriction relaxation).
375      // A `transmute` doesn&#39;t work because the sizes are unspecified.
376      //
377      // SAFETY: The unsafe contract requires that these two have
378      // identical representations.
379      </span><span class="kw">let </span>inner_ptr = s <span class="kw">as </span><span class="kw-2">*mut </span>Inner;
380      <span class="kw">let </span>wrapper_ptr: <span class="kw-2">*mut </span><span class="self">Self </span>= <span class="macro">transmute!</span>(inner_ptr);
381      <span class="kw-2">&amp;mut *</span>wrapper_ptr
382    }
383  }
384
385  <span class="doccomment">/// Convert a slice to the inner type into a slice to the wrapper type.
386  </span><span class="attribute">#[inline]
387  </span><span class="kw">fn </span>wrap_slice(s: <span class="kw-2">&amp;</span>[Inner]) -&gt; <span class="kw-2">&amp;</span>[<span class="self">Self</span>]
388  <span class="kw">where
389    </span><span class="self">Self</span>: Sized,
390    Inner: Sized,
391  {
392    <span class="kw">unsafe </span>{
393      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*const </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*const </span><span class="self">Self</span>&gt;());
394      <span class="macro">assert!</span>(align_of::&lt;<span class="kw-2">*const </span>Inner&gt;() == align_of::&lt;<span class="kw-2">*const </span><span class="self">Self</span>&gt;());
395      <span class="comment">// SAFETY: The unsafe contract requires that these two have
396      // identical representations (size and alignment).
397      </span>core::slice::from_raw_parts(s.as_ptr() <span class="kw">as </span><span class="kw-2">*const </span><span class="self">Self</span>, s.len())
398    }
399  }
400
401  <span class="doccomment">/// Convert a mutable slice to the inner type into a mutable slice to the
402  /// wrapper type.
403  </span><span class="attribute">#[inline]
404  </span><span class="kw">fn </span>wrap_slice_mut(s: <span class="kw-2">&amp;mut </span>[Inner]) -&gt; <span class="kw-2">&amp;mut </span>[<span class="self">Self</span>]
405  <span class="kw">where
406    </span><span class="self">Self</span>: Sized,
407    Inner: Sized,
408  {
409    <span class="kw">unsafe </span>{
410      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*mut </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*mut </span><span class="self">Self</span>&gt;());
411      <span class="macro">assert!</span>(align_of::&lt;<span class="kw-2">*mut </span>Inner&gt;() == align_of::&lt;<span class="kw-2">*mut </span><span class="self">Self</span>&gt;());
412      <span class="comment">// SAFETY: The unsafe contract requires that these two have
413      // identical representations (size and alignment).
414      </span>core::slice::from_raw_parts_mut(s.as_mut_ptr() <span class="kw">as </span><span class="kw-2">*mut </span><span class="self">Self</span>, s.len())
415    }
416  }
417
418  <span class="doccomment">/// Convert the wrapper type into the inner type.
419  </span><span class="attribute">#[inline]
420  </span><span class="kw">fn </span>peel(s: <span class="self">Self</span>) -&gt; Inner
421  <span class="kw">where
422    </span><span class="self">Self</span>: Sized,
423    Inner: Sized,
424  {
425    <span class="kw">unsafe </span>{ <span class="macro">transmute!</span>(s) }
426  }
427
428  <span class="doccomment">/// Convert a reference to the wrapper type into a reference to the inner
429  /// type.
430  </span><span class="attribute">#[inline]
431  </span><span class="kw">fn </span>peel_ref(s: <span class="kw-2">&amp;</span><span class="self">Self</span>) -&gt; <span class="kw-2">&amp;</span>Inner {
432    <span class="kw">unsafe </span>{
433      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*const </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*const </span><span class="self">Self</span>&gt;());
434      <span class="comment">// A pointer cast doesn&#39;t work here because rustc can&#39;t tell that
435      // the vtables match (because of the `?Sized` restriction relaxation).
436      // A `transmute` doesn&#39;t work because the sizes are unspecified.
437      //
438      // SAFETY: The unsafe contract requires that these two have
439      // identical representations.
440      </span><span class="kw">let </span>wrapper_ptr = s <span class="kw">as </span><span class="kw-2">*const </span><span class="self">Self</span>;
441      <span class="kw">let </span>inner_ptr: <span class="kw-2">*const </span>Inner = <span class="macro">transmute!</span>(wrapper_ptr);
442      <span class="kw-2">&amp;*</span>inner_ptr
443    }
444  }
445
446  <span class="doccomment">/// Convert a mutable reference to the wrapper type into a mutable reference
447  /// to the inner type.
448  </span><span class="attribute">#[inline]
449  </span><span class="kw">fn </span>peel_mut(s: <span class="kw-2">&amp;mut </span><span class="self">Self</span>) -&gt; <span class="kw-2">&amp;mut </span>Inner {
450    <span class="kw">unsafe </span>{
451      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*mut </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*mut </span><span class="self">Self</span>&gt;());
452      <span class="comment">// A pointer cast doesn&#39;t work here because rustc can&#39;t tell that
453      // the vtables match (because of the `?Sized` restriction relaxation).
454      // A `transmute` doesn&#39;t work because the sizes are unspecified.
455      //
456      // SAFETY: The unsafe contract requires that these two have
457      // identical representations.
458      </span><span class="kw">let </span>wrapper_ptr = s <span class="kw">as </span><span class="kw-2">*mut </span><span class="self">Self</span>;
459      <span class="kw">let </span>inner_ptr: <span class="kw-2">*mut </span>Inner = <span class="macro">transmute!</span>(wrapper_ptr);
460      <span class="kw-2">&amp;mut *</span>inner_ptr
461    }
462  }
463
464  <span class="doccomment">/// Convert a slice to the wrapped type into a slice to the inner type.
465  </span><span class="attribute">#[inline]
466  </span><span class="kw">fn </span>peel_slice(s: <span class="kw-2">&amp;</span>[<span class="self">Self</span>]) -&gt; <span class="kw-2">&amp;</span>[Inner]
467  <span class="kw">where
468    </span><span class="self">Self</span>: Sized,
469    Inner: Sized,
470  {
471    <span class="kw">unsafe </span>{
472      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*const </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*const </span><span class="self">Self</span>&gt;());
473      <span class="macro">assert!</span>(align_of::&lt;<span class="kw-2">*const </span>Inner&gt;() == align_of::&lt;<span class="kw-2">*const </span><span class="self">Self</span>&gt;());
474      <span class="comment">// SAFETY: The unsafe contract requires that these two have
475      // identical representations (size and alignment).
476      </span>core::slice::from_raw_parts(s.as_ptr() <span class="kw">as </span><span class="kw-2">*const </span>Inner, s.len())
477    }
478  }
479
480  <span class="doccomment">/// Convert a mutable slice to the wrapped type into a mutable slice to the
481  /// inner type.
482  </span><span class="attribute">#[inline]
483  </span><span class="kw">fn </span>peel_slice_mut(s: <span class="kw-2">&amp;mut </span>[<span class="self">Self</span>]) -&gt; <span class="kw-2">&amp;mut </span>[Inner]
484  <span class="kw">where
485    </span><span class="self">Self</span>: Sized,
486    Inner: Sized,
487  {
488    <span class="kw">unsafe </span>{
489      <span class="macro">assert!</span>(size_of::&lt;<span class="kw-2">*mut </span>Inner&gt;() == size_of::&lt;<span class="kw-2">*mut </span><span class="self">Self</span>&gt;());
490      <span class="macro">assert!</span>(align_of::&lt;<span class="kw-2">*mut </span>Inner&gt;() == align_of::&lt;<span class="kw-2">*mut </span><span class="self">Self</span>&gt;());
491      <span class="comment">// SAFETY: The unsafe contract requires that these two have
492      // identical representations (size and alignment).
493      </span>core::slice::from_raw_parts_mut(s.as_mut_ptr() <span class="kw">as </span><span class="kw-2">*mut </span>Inner, s.len())
494    }
495  }
496}
497
498<span class="kw">unsafe impl</span>&lt;T&gt; TransparentWrapper&lt;T&gt; <span class="kw">for </span>core::num::Wrapping&lt;T&gt; {}
499</code></pre></div>
500</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="bytemuck" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (4a1467723 2022-09-23)" ></div></body></html>