1+ <!--
12# Transmutes
3+ -->
24
5+ # トランスミュート
6+
7+ <!--
38Get out of our way type system! We're going to reinterpret these bits or die
49trying! Even though this book is all about doing things that are unsafe, I
510really can't emphasize that you should deeply think about finding Another Way
611than the operations covered in this section. This is really, truly, the most
712horribly unsafe thing you can do in Rust. The railguards here are dental floss.
13+ -->
14+
15+ 型システムから抜け出しましょう! 何がなんでもビットを再解釈します! この本は
16+ アンセーフなもの全てについて書かれていますが、この章でカバーされている操作を
17+ やるよりも、他の方法を見つけるよう深刻に考えるべきだということは、
18+ いくら強調しようとも、強調しきれません。これは本当に、マジで、 Rust で出来る
19+ 最も恐ろしいアンセーフなことです。ここではガードレールは爪楊枝のように脆いです。
820
21+ <!--
922`mem::transmute<T, U>` takes a value of type `T` and reinterprets it to have
1023type `U`. The only restriction is that the `T` and `U` are verified to have the
1124same size. The ways to cause Undefined Behavior with this are mind boggling.
25+ -->
26+
27+ ` mem::transmute<T, U> ` は型 ` T ` の値を受け取り、その値が型 ` U ` であると再解釈します。
28+ 唯一の制約は、 ` T ` と ` U ` が同じサイズを持つとされていることです。
29+ この操作によって未定義動作が起こる方法を考えると、気が遠くなります。
1230
31+ <!--
1332* First and foremost, creating an instance of *any* type with an invalid state
1433 is going to cause arbitrary chaos that can't really be predicted.
1534* Transmute has an overloaded return type. If you do not specify the return type
@@ -22,14 +41,38 @@ same size. The ways to cause Undefined Behavior with this are mind boggling.
2241 * No you're not special
2342* Transmuting to a reference without an explicitly provided lifetime
2443 produces an [unbounded lifetime]
44+ -->
2545
46+ * まず真っ先に、* いかなる* 型においても、無効状態のインスタンスを作ることは、本当に予測不可能な混沌状態を引き起こすでしょう。
47+ * transmute はオーバーロードされたリターン型を持ちます。もしリターン型を指定しなかった場合、
48+ 推論を満たす、びっくりするような型を生成するかもしれません。
49+ * 無効なプリミティブを生成することは未定義動作を引き起こします。
50+ * repr(C) でない型の間でのトランスミュートは未定義動作を引き起こします。
51+ * & から &mut へのトランスミュートは未定義動作を引き起こします。
52+ * & から &mut へのトランスミュートは* いつも* 未定義動作を引き起こします。
53+ * いいえ、これは出来ません。
54+ * いいか、君は特別じゃないんだ。
55+ * 明確にライフタイムが指定されていない参照へのトランスミュートは[ 無制限のライフタイム] を生成します。
56+
57+ <!--
2658`mem::transmute_copy<T, U>` somehow manages to be *even more* wildly unsafe than
2759this. It copies `size_of<U>` bytes out of an `&T` and interprets them as a `U`.
2860The size check that `mem::transmute` has is gone (as it may be valid to copy
2961out a prefix), though it is Undefined Behavior for `U` to be larger than `T`.
62+ -->
63+
64+ ` mem::transmute_copy<T, U> ` は、どうにかして transmute よりも* 本当に更に* アンセーフな事をしようとします。
65+ この関数は ` &T ` から ` size_of<U> ` バイトコピーし、これらを ` U ` として解釈します。
66+ もし ` U ` が ` T ` よりも大きい場合、未定義動作を引き起こしますが、 ` mem::transmute ` の
67+ サイズチェックはなくなっています ( ` T ` の先頭部分をコピーすることが有効である場合があるためです) 。
3068
69+ <!--
3170Also of course you can get most of the functionality of these functions using
3271pointer casts.
72+ -->
73+
74+ そしてもちろん、これらの関数の機能のほとんどを、ポインタのキャストを利用することで
75+ 得ることができます。
3376
3477
35- [ unbounded lifetime ] : unbounded-lifetimes.html
78+ [ 無制限のライフタイム ] : unbounded-lifetimes.html
0 commit comments