Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions en/src/generics-traits/const-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ fn main() {

fn check_size<T>(val: T)
where
Assert<{ core::mem::size_of::<T>() < 768 }>: IsTrue,
Assert<{ core::mem::size_of::<T>() == 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 ?
Expand Down
12 changes: 6 additions & 6 deletions solutions/generics-traits/const-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ fn main() {

fn check_size<T>(val: T)
where
Assert<{ core::mem::size_of::<T>() < 768 }>: IsTrue,
Assert<{ core::mem::size_of::<T>() == 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
}


Expand Down
6 changes: 3 additions & 3 deletions zh-CN/src/generics-traits/const-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ fn main() {

fn check_size<T>(val: T)
where
Assert<{ core::mem::size_of::<T>() < 768 }>: IsTrue,
Assert<{ core::mem::size_of::<T>() == 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 ?
Expand Down