From 3b31b423de60c51de63937390adbec7890f8c12a Mon Sep 17 00:00:00 2001 From: skb666 Date: Wed, 14 May 2025 12:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=98=E7=9B=AE=E4=BD=BF?= =?UTF-8?q?=E5=85=B6=E7=9B=AE=E7=9A=84=E6=9B=B4=E6=98=8E=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/src/generics-traits/const-generics.md | 6 +++--- solutions/generics-traits/const-generics.md | 12 ++++++------ zh-CN/src/generics-traits/const-generics.md | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/en/src/generics-traits/const-generics.md b/en/src/generics-traits/const-generics.md index 9546d42ab..20022649c 100644 --- a/en/src/generics-traits/const-generics.md +++ b/en/src/generics-traits/const-generics.md @@ -117,15 +117,15 @@ fn main() { fn check_size(val: T) where - Assert<{ core::mem::size_of::() < 768 }>: IsTrue, + Assert<{ core::mem::size_of::() == 768 }>: IsTrue, { //... } // Fix the errors in main. fn main() { - check_size([0u8; 767]); - check_size([0i32; 191]); + check_size([0u8; 768]); + check_size([0i32; 192]); check_size(["hello你好"; __]); // Size of &str ? check_size([(); __].map(|_| "hello你好".to_string())); // Size of String? check_size(['中'; __]); // Size of char ? diff --git a/solutions/generics-traits/const-generics.md b/solutions/generics-traits/const-generics.md index 12dff528d..e819e2400 100644 --- a/solutions/generics-traits/const-generics.md +++ b/solutions/generics-traits/const-generics.md @@ -43,18 +43,18 @@ fn main() { fn check_size(val: T) where - Assert<{ core::mem::size_of::() < 768 }>: IsTrue, + Assert<{ core::mem::size_of::() == 768 }>: IsTrue, { //... } // fix the errors in main fn main() { - check_size([0u8; 767]); - check_size([0i32; 191]); - check_size(["hello你好"; 47]); // &str is a string reference, containing a pointer and string length in it, so it takes two word long, in x86-64, 1 word = 8 bytes - check_size([(); 31].map(|_| "hello你好".to_string())); // String is a smart pointer struct, it has three fields: pointer, length and capacity, each takes 8 bytes - check_size(['中'; 191]); // A char takes 4 bytes in Rust + check_size([0u8; 768]); + check_size([0i32; 192]); + check_size(["hello你好"; 48]); // &str is a string reference, containing a pointer and string length in it, so it takes two word long, in x86-64, 1 word = 8 bytes + check_size([(); 32].map(|_| "hello你好".to_string())); // String is a smart pointer struct, it has three fields: pointer, length and capacity, each takes 8 bytes + check_size(['中'; 192]); // A char takes 4 bytes in Rust } diff --git a/zh-CN/src/generics-traits/const-generics.md b/zh-CN/src/generics-traits/const-generics.md index 89a0d8f12..86647a896 100644 --- a/zh-CN/src/generics-traits/const-generics.md +++ b/zh-CN/src/generics-traits/const-generics.md @@ -113,15 +113,15 @@ fn main() { fn check_size(val: T) where - Assert<{ core::mem::size_of::() < 768 }>: IsTrue, + Assert<{ core::mem::size_of::() == 768 }>: IsTrue, { //... } // 修复 main 函数中的错误 fn main() { - check_size([0u8; 767]); - check_size([0i32; 191]); + check_size([0u8; 768]); + check_size([0i32; 192]); check_size(["hello你好"; __]); // size of &str ? check_size([(); __].map(|_| "hello你好".to_string())); // size of String? check_size(['中'; __]); // size of char ?