From 7f4d145e9a96f137945af9589795e88f21df0581 Mon Sep 17 00:00:00 2001 From: toku-sa-n Date: Fri, 17 Jul 2020 13:30:02 +0900 Subject: [PATCH 1/3] Translate title --- src/SUMMARY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 3423f4b..1012386 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -51,5 +51,5 @@ * [RawVec](vec-raw.md) * [Drain](vec-drain.md) * [Handling Zero-Sized Types](vec-zsts.md) - * [Final Code](vec-final.md) + * [最終コード](vec-final.md) * [Implementing Arc and Mutex](arc-and-mutex.md) From 8b87ef71ee85c813cfdb07e1bddfefd32d0e7523 Mon Sep 17 00:00:00 2001 From: toku-sa-n Date: Fri, 17 Jul 2020 13:30:22 +0900 Subject: [PATCH 2/3] Translate title --- src/vec-final.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vec-final.md b/src/vec-final.md index 39746ca..b1df5cf 100644 --- a/src/vec-final.md +++ b/src/vec-final.md @@ -1,4 +1,8 @@ + + +# 最終コード ```rust #![feature(unique)] From e04cd5613ad36d596f7ebd13441dc9144ae36fa6 Mon Sep 17 00:00:00 2001 From: toku-sa-n Date: Fri, 17 Jul 2020 13:51:54 +0900 Subject: [PATCH 3/3] Translate code comments --- src/vec-final.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/vec-final.md b/src/vec-final.md index b1df5cf..ac5259f 100644 --- a/src/vec-final.md +++ b/src/vec-final.md @@ -25,10 +25,11 @@ struct RawVec { impl RawVec { fn new() -> Self { unsafe { - // !0 is usize::MAX. This branch should be stripped at compile time. + // !0 は usize::MAX です。この分岐はコンパイル時に取り除かれるはずです。 let cap = if mem::size_of::() == 0 { !0 } else { 0 }; - // heap::EMPTY doubles as "unallocated" and "zero-sized allocation" + // heap::EMPTY は "アロケートされていない" と "サイズが 0 の型のアロケーション" の + // 2 つの意味を兼ねることになります。 RawVec { ptr: Unique::new(heap::EMPTY as *mut T), cap: cap } } } @@ -37,8 +38,9 @@ impl RawVec { unsafe { let elem_size = mem::size_of::(); - // since we set the capacity to usize::MAX when elem_size is - // 0, getting to here necessarily means the Vec is overfull. + // elem_size が 0 の時にキャパシティを usize::MAX にしたので、 + // ここにたどり着いてしまうということは、 Vec が満杯であることを必然的に + // 意味します。 assert!(elem_size != 0, "capacity overflow"); let align = mem::align_of::(); @@ -55,7 +57,7 @@ impl RawVec { (new_cap, ptr) }; - // If allocate or reallocate fail, we'll get `null` back + // もしアロケートや、リアロケートに失敗すると、 `null` が返ってきます if ptr.is_null() { oom() } self.ptr = Unique::new(ptr as *mut _); @@ -102,7 +104,7 @@ impl Vec { ptr::write(self.ptr().offset(self.len as isize), elem); } - // Can't fail, we'll OOM first. + // 絶対成功します。 OOM はこの前に起きるからです。 self.len += 1; } @@ -161,9 +163,9 @@ impl Vec { unsafe { let iter = RawValIter::new(&self); - // this is a mem::forget safety thing. If Drain is forgotten, we just - // leak the whole Vec's contents. Also we need to do this *eventually* - // anyway, so why not do it now? + // これは mem::forget の安全版です。もし Drain が forget されたら、 + // 単に Vec の内容全体をリークします。そして*結局*これをしなければ + // なりません。なら今やっちゃいましょう。 self.len = 0; Drain { @@ -177,7 +179,7 @@ impl Vec { impl Drop for Vec { fn drop(&mut self) { while let Some(_) = self.pop() {} - // allocation is handled by RawVec + // デアロケートは RawVec が対処します } } @@ -269,7 +271,7 @@ impl DoubleEndedIterator for RawValIter { pub struct IntoIter { - _buf: RawVec, // we don't actually care about this. Just need it to live. + _buf: RawVec, // これを扱うことはないのですが、その存在は必要です。 iter: RawValIter, } @@ -314,9 +316,9 @@ impl<'a, T> Drop for Drain<'a, T> { } } -/// Abort the process, we're out of memory! +/// プロセスをアボートします。メモリ不足だ! /// -/// In practice this is probably dead code on most OSes +/// 実際にはこのコードは、多分ほとんどの OS においてデッドコードとなるでしょう fn oom() { ::std::process::exit(-9999); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy