+/livesplit-wrapper

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

P1n3appl3deploy: 9b9f353f3b0e319547cabc5dcadc542d5ab54386b0170e4

gh-pages
31.0 KiB772 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/lib.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>lib.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<span id="250">250</span>
251<span id="251">251</span>
252<span id="252">252</span>
253<span id="253">253</span>
254<span id="254">254</span>
255<span id="255">255</span>
256<span id="256">256</span>
257<span id="257">257</span>
258<span id="258">258</span>
259<span id="259">259</span>
260<span id="260">260</span>
261<span id="261">261</span>
262<span id="262">262</span>
263<span id="263">263</span>
264<span id="264">264</span>
265<span id="265">265</span>
266<span id="266">266</span>
267<span id="267">267</span>
268<span id="268">268</span>
269<span id="269">269</span>
270<span id="270">270</span>
271<span id="271">271</span>
272<span id="272">272</span>
273<span id="273">273</span>
274<span id="274">274</span>
275<span id="275">275</span>
276<span id="276">276</span>
277<span id="277">277</span>
278<span id="278">278</span>
279<span id="279">279</span>
280<span id="280">280</span>
281<span id="281">281</span>
282<span id="282">282</span>
283<span id="283">283</span>
284<span id="284">284</span>
285<span id="285">285</span>
286<span id="286">286</span>
287<span id="287">287</span>
288<span id="288">288</span>
289<span id="289">289</span>
290<span id="290">290</span>
291<span id="291">291</span>
292<span id="292">292</span>
293<span id="293">293</span>
294<span id="294">294</span>
295<span id="295">295</span>
296<span id="296">296</span>
297<span id="297">297</span>
298<span id="298">298</span>
299<span id="299">299</span>
300<span id="300">300</span>
301<span id="301">301</span>
302<span id="302">302</span>
303<span id="303">303</span>
304<span id="304">304</span>
305<span id="305">305</span>
306<span id="306">306</span>
307<span id="307">307</span>
308<span id="308">308</span>
309<span id="309">309</span>
310<span id="310">310</span>
311<span id="311">311</span>
312<span id="312">312</span>
313<span id="313">313</span>
314<span id="314">314</span>
315<span id="315">315</span>
316<span id="316">316</span>
317<span id="317">317</span>
318<span id="318">318</span>
319<span id="319">319</span>
320<span id="320">320</span>
321<span id="321">321</span>
322<span id="322">322</span>
323<span id="323">323</span>
324<span id="324">324</span>
325<span id="325">325</span>
326<span id="326">326</span>
327<span id="327">327</span>
328<span id="328">328</span>
329<span id="329">329</span>
330<span id="330">330</span>
331<span id="331">331</span>
332<span id="332">332</span>
333<span id="333">333</span>
334<span id="334">334</span>
335<span id="335">335</span>
336<span id="336">336</span>
337<span id="337">337</span>
338<span id="338">338</span>
339<span id="339">339</span>
340<span id="340">340</span>
341<span id="341">341</span>
342<span id="342">342</span>
343<span id="343">343</span>
344<span id="344">344</span>
345<span id="345">345</span>
346<span id="346">346</span>
347<span id="347">347</span>
348<span id="348">348</span>
349<span id="349">349</span>
350<span id="350">350</span>
351<span id="351">351</span>
352<span id="352">352</span>
353<span id="353">353</span>
354<span id="354">354</span>
355<span id="355">355</span>
356<span id="356">356</span>
357<span id="357">357</span>
358<span id="358">358</span>
359<span id="359">359</span>
360<span id="360">360</span>
361<span id="361">361</span>
362<span id="362">362</span>
363<span id="363">363</span>
364<span id="364">364</span>
365<span id="365">365</span>
366<span id="366">366</span>
367<span id="367">367</span>
368<span id="368">368</span>
369<span id="369">369</span>
370<span id="370">370</span>
371<span id="371">371</span>
372<span id="372">372</span>
373<span id="373">373</span>
374<span id="374">374</span>
375<span id="375">375</span>
376<span id="376">376</span>
377<span id="377">377</span>
378<span id="378">378</span>
379<span id="379">379</span>
380<span id="380">380</span>
381<span id="381">381</span>
382<span id="382">382</span>
383<span id="383">383</span>
384<span id="384">384</span>
385<span id="385">385</span>
386</pre><pre class="rust"><code><span class="attribute">#![no_std]
387#![warn(missing_docs)]
388#![cfg_attr(feature = <span class="string">&quot;nightly_portable_simd&quot;</span>, feature(portable_simd))]
389
390</span><span class="doccomment">//! This crate gives small utilities for casting between plain data types.
391//!
392//! ## Basics
393//!
394//! Data comes in five basic forms in Rust, so we have five basic casting
395//! functions:
396//!
397//! * `T` uses [`cast`]
398//! * `&amp;T` uses [`cast_ref`]
399//! * `&amp;mut T` uses [`cast_mut`]
400//! * `&amp;[T]` uses [`cast_slice`]
401//! * `&amp;mut [T]` uses [`cast_slice_mut`]
402//!
403//! Some casts will never fail (eg: `cast::&lt;u32, f32&gt;` always works), other
404//! casts might fail (eg: `cast_ref::&lt;[u8; 4], u32&gt;` will fail if the reference
405//! isn&#39;t already aligned to 4). Each casting function has a &quot;try&quot; version which
406//! will return a `Result`, and the &quot;normal&quot; version which will simply panic on
407//! invalid input.
408//!
409//! ## Using Your Own Types
410//!
411//! All the functions here are guarded by the [`Pod`] trait, which is a
412//! sub-trait of the [`Zeroable`] trait.
413//!
414//! If you&#39;re very sure that your type is eligible, you can implement those
415//! traits for your type and then they&#39;ll have full casting support. However,
416//! these traits are `unsafe`, and you should carefully read the requirements
417//! before adding the them to your own types.
418//!
419//! ## Features
420//!
421//! * This crate is core only by default, but if you&#39;re using Rust 1.36 or later
422//!   you can enable the `extern_crate_alloc` cargo feature for some additional
423//!   methods related to `Box` and `Vec`. Note that the `docs.rs` documentation
424//!   is always built with `extern_crate_alloc` cargo feature enabled.
425
426</span><span class="attribute">#[cfg(all(target_arch = <span class="string">&quot;aarch64&quot;</span>, feature = <span class="string">&quot;aarch64_simd&quot;</span>))]
427</span><span class="kw">use </span>core::arch::aarch64;
428<span class="attribute">#[cfg(all(target_arch = <span class="string">&quot;wasm32&quot;</span>, feature = <span class="string">&quot;wasm_simd&quot;</span>))]
429</span><span class="kw">use </span>core::arch::wasm32;
430<span class="attribute">#[cfg(target_arch = <span class="string">&quot;x86&quot;</span>)]
431</span><span class="kw">use </span>core::arch::x86;
432<span class="attribute">#[cfg(target_arch = <span class="string">&quot;x86_64&quot;</span>)]
433</span><span class="kw">use </span>core::arch::x86_64;
434<span class="comment">//
435</span><span class="kw">use </span>core::{marker::<span class="kw-2">*</span>, mem::<span class="kw-2">*</span>, num::<span class="kw-2">*</span>, ptr::<span class="kw-2">*</span>};
436
437<span class="comment">// Used from macros to ensure we aren&#39;t using some locally defined name and
438// actually are referencing libcore. This also would allow pre-2018 edition
439// crates to use our macros, but I&#39;m not sure how important that is.
440</span><span class="attribute">#[doc(hidden)]
441</span><span class="kw">pub use </span>::core <span class="kw">as </span>__core;
442
443<span class="attribute">#[cfg(not(feature = <span class="string">&quot;min_const_generics&quot;</span>))]
444</span><span class="macro">macro_rules! </span>impl_unsafe_marker_for_array {
445  ( <span class="macro-nonterminal">$marker</span>:ident , $( <span class="macro-nonterminal">$n</span>:expr ),* ) =&gt; {
446    $(<span class="kw">unsafe impl</span>&lt;T&gt; <span class="macro-nonterminal">$marker </span><span class="kw">for </span>[T; <span class="macro-nonterminal">$n</span>] <span class="kw">where </span>T: <span class="macro-nonterminal">$marker </span>{})*
447  }
448}
449
450<span class="doccomment">/// A macro to transmute between two types without requiring knowing size
451/// statically.
452</span><span class="macro">macro_rules! </span>transmute {
453  (<span class="macro-nonterminal">$val</span>:expr) =&gt; {
454    ::core::mem::transmute_copy(<span class="kw-2">&amp;</span>::core::mem::ManuallyDrop::new(<span class="macro-nonterminal">$val</span>))
455  };
456}
457
458<span class="attribute">#[cfg(feature = <span class="string">&quot;extern_crate_std&quot;</span>)]
459</span><span class="kw">extern crate </span>std;
460
461<span class="attribute">#[cfg(feature = <span class="string">&quot;extern_crate_alloc&quot;</span>)]
462</span><span class="kw">extern crate </span>alloc;
463<span class="attribute">#[cfg(feature = <span class="string">&quot;extern_crate_alloc&quot;</span>)]
464</span><span class="kw">pub mod </span>allocation;
465<span class="attribute">#[cfg(feature = <span class="string">&quot;extern_crate_alloc&quot;</span>)]
466</span><span class="kw">pub use </span>allocation::<span class="kw-2">*</span>;
467
468<span class="kw">mod </span>anybitpattern;
469<span class="kw">pub use </span>anybitpattern::<span class="kw-2">*</span>;
470
471<span class="kw">pub mod </span>checked;
472<span class="kw">pub use </span>checked::CheckedBitPattern;
473
474<span class="kw">mod </span>internal;
475
476<span class="kw">mod </span>zeroable;
477<span class="kw">pub use </span>zeroable::<span class="kw-2">*</span>;
478<span class="kw">mod </span>zeroable_in_option;
479<span class="kw">pub use </span>zeroable_in_option::<span class="kw-2">*</span>;
480
481<span class="kw">mod </span>pod;
482<span class="kw">pub use </span>pod::<span class="kw-2">*</span>;
483<span class="kw">mod </span>pod_in_option;
484<span class="kw">pub use </span>pod_in_option::<span class="kw-2">*</span>;
485
486<span class="kw">mod </span>no_uninit;
487<span class="kw">pub use </span>no_uninit::<span class="kw-2">*</span>;
488
489<span class="kw">mod </span>contiguous;
490<span class="kw">pub use </span>contiguous::<span class="kw-2">*</span>;
491
492<span class="kw">mod </span>offset_of;
493<span class="kw">pub use </span>offset_of::<span class="kw-2">*</span>;
494
495<span class="kw">mod </span>transparent;
496<span class="kw">pub use </span>transparent::<span class="kw-2">*</span>;
497
498<span class="attribute">#[cfg(feature = <span class="string">&quot;derive&quot;</span>)]
499</span><span class="kw">pub use </span>bytemuck_derive::{
500  AnyBitPattern, CheckedBitPattern, Contiguous, NoUninit, Pod,
501  TransparentWrapper, Zeroable,
502};
503
504<span class="doccomment">/// The things that can go wrong when casting between [`Pod`] data forms.
505</span><span class="attribute">#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
506</span><span class="kw">pub enum </span>PodCastError {
507  <span class="doccomment">/// You tried to cast a slice to an element type with a higher alignment
508  /// requirement but the slice wasn&#39;t aligned.
509  </span>TargetAlignmentGreaterAndInputNotAligned,
510  <span class="doccomment">/// If the element size changes then the output slice changes length
511  /// accordingly. If the output slice wouldn&#39;t be a whole number of elements
512  /// then the conversion fails.
513  </span>OutputSliceWouldHaveSlop,
514  <span class="doccomment">/// When casting a slice you can&#39;t convert between ZST elements and non-ZST
515  /// elements. When casting an individual `T`, `&amp;T`, or `&amp;mut T` value the
516  /// source size and destination size must be an exact match.
517  </span>SizeMismatch,
518  <span class="doccomment">/// For this type of cast the alignments must be exactly the same and they
519  /// were not so now you&#39;re sad.
520  ///
521  /// This error is generated **only** by operations that cast allocated types
522  /// (such as `Box` and `Vec`), because in that case the alignment must stay
523  /// exact.
524  </span>AlignmentMismatch,
525}
526<span class="attribute">#[cfg(not(target_arch = <span class="string">&quot;spirv&quot;</span>))]
527</span><span class="kw">impl </span>core::fmt::Display <span class="kw">for </span>PodCastError {
528  <span class="kw">fn </span>fmt(<span class="kw-2">&amp;</span><span class="self">self</span>, f: <span class="kw-2">&amp;mut </span>core::fmt::Formatter) -&gt; core::fmt::Result {
529    <span class="macro">write!</span>(f, <span class="string">&quot;{:?}&quot;</span>, <span class="self">self</span>)
530  }
531}
532<span class="attribute">#[cfg(feature = <span class="string">&quot;extern_crate_std&quot;</span>)]
533</span><span class="kw">impl </span>std::error::Error <span class="kw">for </span>PodCastError {}
534
535<span class="doccomment">/// Re-interprets `&amp;T` as `&amp;[u8]`.
536///
537/// Any ZST becomes an empty slice, and in that case the pointer value of that
538/// empty slice might not match the pointer value of the input reference.
539</span><span class="attribute">#[inline]
540</span><span class="kw">pub fn </span>bytes_of&lt;T: NoUninit&gt;(t: <span class="kw-2">&amp;</span>T) -&gt; <span class="kw-2">&amp;</span>[u8] {
541  <span class="kw">unsafe </span>{ internal::bytes_of(t) }
542}
543
544<span class="doccomment">/// Re-interprets `&amp;mut T` as `&amp;mut [u8]`.
545///
546/// Any ZST becomes an empty slice, and in that case the pointer value of that
547/// empty slice might not match the pointer value of the input reference.
548</span><span class="attribute">#[inline]
549</span><span class="kw">pub fn </span>bytes_of_mut&lt;T: NoUninit + AnyBitPattern&gt;(t: <span class="kw-2">&amp;mut </span>T) -&gt; <span class="kw-2">&amp;mut </span>[u8] {
550  <span class="kw">unsafe </span>{ internal::bytes_of_mut(t) }
551}
552
553<span class="doccomment">/// Re-interprets `&amp;[u8]` as `&amp;T`.
554///
555/// ## Panics
556///
557/// This is [`try_from_bytes`] but will panic on error.
558</span><span class="attribute">#[inline]
559</span><span class="kw">pub fn </span>from_bytes&lt;T: AnyBitPattern&gt;(s: <span class="kw-2">&amp;</span>[u8]) -&gt; <span class="kw-2">&amp;</span>T {
560  <span class="kw">unsafe </span>{ internal::from_bytes(s) }
561}
562
563<span class="doccomment">/// Re-interprets `&amp;mut [u8]` as `&amp;mut T`.
564///
565/// ## Panics
566///
567/// This is [`try_from_bytes_mut`] but will panic on error.
568</span><span class="attribute">#[inline]
569</span><span class="kw">pub fn </span>from_bytes_mut&lt;T: NoUninit + AnyBitPattern&gt;(s: <span class="kw-2">&amp;mut </span>[u8]) -&gt; <span class="kw-2">&amp;mut </span>T {
570  <span class="kw">unsafe </span>{ internal::from_bytes_mut(s) }
571}
572
573<span class="doccomment">/// Reads from the bytes as if they were a `T`.
574///
575/// ## Failure
576/// * If the `bytes` length is not equal to `size_of::&lt;T&gt;()`.
577</span><span class="attribute">#[inline]
578</span><span class="kw">pub fn </span>try_pod_read_unaligned&lt;T: AnyBitPattern&gt;(
579  bytes: <span class="kw-2">&amp;</span>[u8],
580) -&gt; <span class="prelude-ty">Result</span>&lt;T, PodCastError&gt; {
581  <span class="kw">unsafe </span>{ internal::try_pod_read_unaligned(bytes) }
582}
583
584<span class="doccomment">/// Reads the slice into a `T` value.
585///
586/// ## Panics
587/// * This is like `try_pod_read_unaligned` but will panic on failure.
588</span><span class="attribute">#[inline]
589</span><span class="kw">pub fn </span>pod_read_unaligned&lt;T: AnyBitPattern&gt;(bytes: <span class="kw-2">&amp;</span>[u8]) -&gt; T {
590  <span class="kw">unsafe </span>{ internal::pod_read_unaligned(bytes) }
591}
592
593<span class="doccomment">/// Re-interprets `&amp;[u8]` as `&amp;T`.
594///
595/// ## Failure
596///
597/// * If the slice isn&#39;t aligned for the new type
598/// * If the slice&#39;s length isn’t exactly the size of the new type
599</span><span class="attribute">#[inline]
600</span><span class="kw">pub fn </span>try_from_bytes&lt;T: AnyBitPattern&gt;(s: <span class="kw-2">&amp;</span>[u8]) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="kw-2">&amp;</span>T, PodCastError&gt; {
601  <span class="kw">unsafe </span>{ internal::try_from_bytes(s) }
602}
603
604<span class="doccomment">/// Re-interprets `&amp;mut [u8]` as `&amp;mut T`.
605///
606/// ## Failure
607///
608/// * If the slice isn&#39;t aligned for the new type
609/// * If the slice&#39;s length isn’t exactly the size of the new type
610</span><span class="attribute">#[inline]
611</span><span class="kw">pub fn </span>try_from_bytes_mut&lt;T: NoUninit + AnyBitPattern&gt;(
612  s: <span class="kw-2">&amp;mut </span>[u8],
613) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="kw-2">&amp;mut </span>T, PodCastError&gt; {
614  <span class="kw">unsafe </span>{ internal::try_from_bytes_mut(s) }
615}
616
617<span class="doccomment">/// Cast `T` into `U`
618///
619/// ## Panics
620///
621/// * This is like [`try_cast`](try_cast), but will panic on a size mismatch.
622</span><span class="attribute">#[inline]
623</span><span class="kw">pub fn </span>cast&lt;A: NoUninit, B: AnyBitPattern&gt;(a: A) -&gt; B {
624  <span class="kw">unsafe </span>{ internal::cast(a) }
625}
626
627<span class="doccomment">/// Cast `&amp;mut T` into `&amp;mut U`.
628///
629/// ## Panics
630///
631/// This is [`try_cast_mut`] but will panic on error.
632</span><span class="attribute">#[inline]
633</span><span class="kw">pub fn </span>cast_mut&lt;A: NoUninit + AnyBitPattern, B: NoUninit + AnyBitPattern&gt;(
634  a: <span class="kw-2">&amp;mut </span>A,
635) -&gt; <span class="kw-2">&amp;mut </span>B {
636  <span class="kw">unsafe </span>{ internal::cast_mut(a) }
637}
638
639<span class="doccomment">/// Cast `&amp;T` into `&amp;U`.
640///
641/// ## Panics
642///
643/// This is [`try_cast_ref`] but will panic on error.
644</span><span class="attribute">#[inline]
645</span><span class="kw">pub fn </span>cast_ref&lt;A: NoUninit, B: AnyBitPattern&gt;(a: <span class="kw-2">&amp;</span>A) -&gt; <span class="kw-2">&amp;</span>B {
646  <span class="kw">unsafe </span>{ internal::cast_ref(a) }
647}
648
649<span class="doccomment">/// Cast `&amp;[A]` into `&amp;[B]`.
650///
651/// ## Panics
652///
653/// This is [`try_cast_slice`] but will panic on error.
654</span><span class="attribute">#[inline]
655</span><span class="kw">pub fn </span>cast_slice&lt;A: NoUninit, B: AnyBitPattern&gt;(a: <span class="kw-2">&amp;</span>[A]) -&gt; <span class="kw-2">&amp;</span>[B] {
656  <span class="kw">unsafe </span>{ internal::cast_slice(a) }
657}
658
659<span class="doccomment">/// Cast `&amp;mut [T]` into `&amp;mut [U]`.
660///
661/// ## Panics
662///
663/// This is [`try_cast_slice_mut`] but will panic on error.
664</span><span class="attribute">#[inline]
665</span><span class="kw">pub fn </span>cast_slice_mut&lt;
666  A: NoUninit + AnyBitPattern,
667  B: NoUninit + AnyBitPattern,
668&gt;(
669  a: <span class="kw-2">&amp;mut </span>[A],
670) -&gt; <span class="kw-2">&amp;mut </span>[B] {
671  <span class="kw">unsafe </span>{ internal::cast_slice_mut(a) }
672}
673
674<span class="doccomment">/// As `align_to`, but safe because of the [`Pod`] bound.
675</span><span class="attribute">#[inline]
676</span><span class="kw">pub fn </span>pod_align_to&lt;T: NoUninit, U: AnyBitPattern&gt;(
677  vals: <span class="kw-2">&amp;</span>[T],
678) -&gt; (<span class="kw-2">&amp;</span>[T], <span class="kw-2">&amp;</span>[U], <span class="kw-2">&amp;</span>[T]) {
679  <span class="kw">unsafe </span>{ vals.align_to::&lt;U&gt;() }
680}
681
682<span class="doccomment">/// As `align_to_mut`, but safe because of the [`Pod`] bound.
683</span><span class="attribute">#[inline]
684</span><span class="kw">pub fn </span>pod_align_to_mut&lt;
685  T: NoUninit + AnyBitPattern,
686  U: NoUninit + AnyBitPattern,
687&gt;(
688  vals: <span class="kw-2">&amp;mut </span>[T],
689) -&gt; (<span class="kw-2">&amp;mut </span>[T], <span class="kw-2">&amp;mut </span>[U], <span class="kw-2">&amp;mut </span>[T]) {
690  <span class="kw">unsafe </span>{ vals.align_to_mut::&lt;U&gt;() }
691}
692
693<span class="doccomment">/// Try to cast `T` into `U`.
694///
695/// Note that for this particular type of cast, alignment isn&#39;t a factor. The
696/// input value is semantically copied into the function and then returned to a
697/// new memory location which will have whatever the required alignment of the
698/// output type is.
699///
700/// ## Failure
701///
702/// * If the types don&#39;t have the same size this fails.
703</span><span class="attribute">#[inline]
704</span><span class="kw">pub fn </span>try_cast&lt;A: NoUninit, B: AnyBitPattern&gt;(
705  a: A,
706) -&gt; <span class="prelude-ty">Result</span>&lt;B, PodCastError&gt; {
707  <span class="kw">unsafe </span>{ internal::try_cast(a) }
708}
709
710<span class="doccomment">/// Try to convert a `&amp;T` into `&amp;U`.
711///
712/// ## Failure
713///
714/// * If the reference isn&#39;t aligned in the new type
715/// * If the source type and target type aren&#39;t the same size.
716</span><span class="attribute">#[inline]
717</span><span class="kw">pub fn </span>try_cast_ref&lt;A: NoUninit, B: AnyBitPattern&gt;(
718  a: <span class="kw-2">&amp;</span>A,
719) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="kw-2">&amp;</span>B, PodCastError&gt; {
720  <span class="kw">unsafe </span>{ internal::try_cast_ref(a) }
721}
722
723<span class="doccomment">/// Try to convert a `&amp;mut T` into `&amp;mut U`.
724///
725/// As [`try_cast_ref`], but `mut`.
726</span><span class="attribute">#[inline]
727</span><span class="kw">pub fn </span>try_cast_mut&lt;
728  A: NoUninit + AnyBitPattern,
729  B: NoUninit + AnyBitPattern,
730&gt;(
731  a: <span class="kw-2">&amp;mut </span>A,
732) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="kw-2">&amp;mut </span>B, PodCastError&gt; {
733  <span class="kw">unsafe </span>{ internal::try_cast_mut(a) }
734}
735
736<span class="doccomment">/// Try to convert `&amp;[A]` into `&amp;[B]` (possibly with a change in length).
737///
738/// * `input.as_ptr() as usize == output.as_ptr() as usize`
739/// * `input.len() * size_of::&lt;A&gt;() == output.len() * size_of::&lt;B&gt;()`
740///
741/// ## Failure
742///
743/// * If the target type has a greater alignment requirement and the input slice
744///   isn&#39;t aligned.
745/// * If the target element type is a different size from the current element
746///   type, and the output slice wouldn&#39;t be a whole number of elements when
747///   accounting for the size change (eg: 3 `u16` values is 1.5 `u32` values, so
748///   that&#39;s a failure).
749/// * Similarly, you can&#39;t convert between a [ZST](https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts)
750///   and a non-ZST.
751</span><span class="attribute">#[inline]
752</span><span class="kw">pub fn </span>try_cast_slice&lt;A: NoUninit, B: AnyBitPattern&gt;(
753  a: <span class="kw-2">&amp;</span>[A],
754) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="kw-2">&amp;</span>[B], PodCastError&gt; {
755  <span class="kw">unsafe </span>{ internal::try_cast_slice(a) }
756}
757
758<span class="doccomment">/// Try to convert `&amp;mut [A]` into `&amp;mut [B]` (possibly with a change in
759/// length).
760///
761/// As [`try_cast_slice`], but `&amp;mut`.
762</span><span class="attribute">#[inline]
763</span><span class="kw">pub fn </span>try_cast_slice_mut&lt;
764  A: NoUninit + AnyBitPattern,
765  B: NoUninit + AnyBitPattern,
766&gt;(
767  a: <span class="kw-2">&amp;mut </span>[A],
768) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="kw-2">&amp;mut </span>[B], PodCastError&gt; {
769  <span class="kw">unsafe </span>{ internal::try_cast_slice_mut(a) }
770}
771</code></pre></div>
772</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>