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