Skip to content

Commit 77f3251

Browse files
author
Document updater
committed
Merge remote-tracking branch 'origin/master'
2 parents 20f6756 + e7c83ee commit 77f3251

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* [型強制](coercions.md)
2525
* [ドットオペレータ](dot-operator.md)
2626
* [キャスト](casts.md)
27-
* [Transmutes](transmutes.md)
27+
* [トランスミュート](transmutes.md)
2828
* [初期化されないメモリ](uninitialized.md)
2929
* [チェックされるメモリ](checked-uninit.md)
3030
* [Drop Flags](drop-flags.md)

src/transmutes.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1+
<!--
12
# Transmutes
3+
-->
24

5+
# トランスミュート
6+
7+
<!--
38
Get out of our way type system! We're going to reinterpret these bits or die
49
trying! Even though this book is all about doing things that are unsafe, I
510
really can't emphasize that you should deeply think about finding Another Way
611
than the operations covered in this section. This is really, truly, the most
712
horribly 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
1023
type `U`. The only restriction is that the `T` and `U` are verified to have the
1124
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+
この操作によって未定義動作が起こる方法を考えると、気が遠くなります。
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
2759
this. It copies `size_of<U>` bytes out of an `&T` and interprets them as a `U`.
2860
The size check that `mem::transmute` has is gone (as it may be valid to copy
2961
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` の先頭部分をコピーすることが有効である場合があるためです) 。
3068

69+
<!--
3170
Also of course you can get most of the functionality of these functions using
3271
pointer casts.
72+
-->
73+
74+
そしてもちろん、これらの関数の機能のほとんどを、ポインタのキャストを利用することで
75+
得ることができます。
3376

3477

35-
[unbounded lifetime]: unbounded-lifetimes.html
78+
[無制限のライフタイム]: unbounded-lifetimes.html

0 commit comments

Comments
 (0)