Skip to content
Merged
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
24 changes: 12 additions & 12 deletions docs/src/appendix/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let arr = [3; 5]; // [3, 3, 3, 3, 3]

## Functions

```rust
```rust,ignore
// Basic function
fn greet() {
println!("Hello!");
Expand Down Expand Up @@ -128,7 +128,7 @@ for item in &vec {

## Ownership

```rust
```rust,ignore
// Move
let s1 = String::from("hello");
let s2 = s1; // s1 is invalid now
Expand All @@ -151,7 +151,7 @@ fn change(s: &mut String) {

## Structs

```rust
```rust,ignore
// Define
struct User {
username: String,
Expand Down Expand Up @@ -186,7 +186,7 @@ impl User {

## Enums & Match

```rust
```rust,ignore
// Define
enum Message {
Quit,
Expand Down Expand Up @@ -220,7 +220,7 @@ if let Some(value) = x {

## Error Handling

```rust
```rust,ignore
// Result
fn divide(a: f64, b: f64) -> Result<f64, String> {
if b == 0.0 {
Expand Down Expand Up @@ -256,7 +256,7 @@ let content = std::fs::read_to_string("file.txt")

### Vec

```rust
```rust,ignore
let mut v: Vec<i32> = Vec::new();
let v = vec![1, 2, 3];

Expand All @@ -273,7 +273,7 @@ for i in &v {

### String

```rust
```rust,ignore
let mut s = String::new();
let s = String::from("hello");
let s = "hello".to_string();
Expand All @@ -286,7 +286,7 @@ let s3 = format!("{} {}", s1, s2);

### HashMap

```rust
```rust,ignore
use std::collections::HashMap;

let mut map = HashMap::new();
Expand All @@ -303,7 +303,7 @@ for (key, value) in &map {

## Iterators

```rust
```rust,ignore
let v = vec![1, 2, 3, 4, 5];

// Common methods
Expand All @@ -321,7 +321,7 @@ v.iter().all(|x| *x > 0);

## Smart Pointers

```rust
```rust,ignore
// Box - Heap allocation
let b = Box::new(5);

Expand All @@ -340,7 +340,7 @@ let data = RefCell::new(5);

## Traits

```rust
```rust,ignore
// Define
trait Summary {
fn summarize(&self) -> String;
Expand Down Expand Up @@ -376,7 +376,7 @@ where

## Async

```rust
```rust,ignore
// Async function
async fn fetch_data() -> String {
// ...
Expand Down
6 changes: 3 additions & 3 deletions docs/src/appendix/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cargo run --example web_server

## 📝 โครงสร้างไฟล์

```
```text
examples/
├── hello_world.rs # บทที่ 1-4
├── ownership.rs # บทที่ 5
Expand All @@ -73,7 +73,7 @@ examples/

### hello_world

```
```text
🦀 สวัสดี Rust!
Hello, World!

Expand All @@ -85,7 +85,7 @@ Is Learning: true

### ownership

```
```text
🦀 Ownership Demo

1️⃣ Move:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/appendix/exercises/ch01-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ cargo run
<details>
<summary>ดูเฉลย</summary>

```
```text
my_project/
├── Cargo.toml
└── src/
Expand Down
2 changes: 1 addition & 1 deletion docs/src/appendix/exercises/ch02-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() {
```
inner: 12
outer: 6
```
```text
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing code fence is being marked as text, which is incorrect. Language specifiers should only appear on opening code fences. This appears to be closing a code block that contains expected output text.

Copilot uses AI. Check for mistakes.

**อธิบาย:**

Expand Down
2 changes: 1 addition & 1 deletion docs/src/appendix/exercises/ch04-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn main() {
let numbers = [10, 20, 30, 40, 50];

Expand Down
18 changes: 9 additions & 9 deletions docs/src/appendix/exercises/ch05-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

โค้ดนี้มี error อะไร? แก้ไขให้ทำงานได้

```rust
```rust,ignore
fn main() {
let s1 = String::from("hello");
let s2 = s1;
Expand All @@ -19,7 +19,7 @@ fn main() {

**วิธีแก้ 1: ใช้ clone**

```rust
```rust,ignore
fn main() {
let s1 = String::from("hello");
let s2 = s1.clone();
Expand All @@ -29,7 +29,7 @@ fn main() {

**วิธีแก้ 2: ใช้ reference**

```rust
```rust,ignore
fn main() {
let s1 = String::from("hello");
let s2 = &s1;
Expand All @@ -45,7 +45,7 @@ fn main() {

โค้ดนี้มี error อะไร? แก้ไขให้ทำงานได้

```rust
```rust,ignore
fn print_string(s: String) {
println!("{}", s);
}
Expand All @@ -64,7 +64,7 @@ fn main() {

**วิธีแก้: ใช้ reference**

```rust
```rust,ignore
fn print_string(s: &String) { // รับ reference
println!("{}", s);
}
Expand All @@ -90,7 +90,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn append_world(s: &mut String) {
s.push_str(" World");
}
Expand All @@ -110,7 +110,7 @@ fn main() {

โค้ดนี้ถูกหรือผิด? อธิบาย

```rust
```rust,ignore
fn main() {
let mut s = String::from("hello");

Expand All @@ -129,7 +129,7 @@ fn main() {

**วิธีแก้:**

```rust
```rust,ignore
fn main() {
let mut s = String::from("hello");

Expand All @@ -156,7 +156,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn first_word(s: &String) -> &str {
let bytes = s.as_bytes();

Expand Down
6 changes: 3 additions & 3 deletions docs/src/appendix/exercises/ch06-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
struct Person {
name: String,
age: u32,
Expand Down Expand Up @@ -40,7 +40,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
struct Person {
name: String,
age: u32,
Expand Down Expand Up @@ -73,7 +73,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
struct Person {
name: String,
age: u32,
Expand Down
6 changes: 3 additions & 3 deletions docs/src/appendix/exercises/ch07-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
enum Message {
Quit,
Move { x: i32, y: i32 },
Expand Down Expand Up @@ -74,7 +74,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn divide(a: f64, b: f64) -> Option<f64> {
if b == 0.0 {
None
Expand Down Expand Up @@ -114,7 +114,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn describe(value: Option<i32>) {
match value {
Some(n) if n > 0 => println!("positive"),
Expand Down
4 changes: 2 additions & 2 deletions docs/src/appendix/exercises/ch08-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn reverse_string(s: &str) -> String {
s.chars().rev().collect()
}
Expand Down Expand Up @@ -128,7 +128,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
enum Value {
Int(i32),
Float(f64),
Expand Down
10 changes: 5 additions & 5 deletions docs/src/appendix/exercises/ch09-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn parse_number(s: &str) -> Result<i32, String> {
s.parse::<i32>()
.map_err(|_| format!("'{}' is not a valid number", s))
Expand All @@ -37,7 +37,7 @@ fn main() {

แปลงโค้ดนี้ให้ใช้ `?`:

```rust
```rust,ignore
fn read_username() -> Result<String, std::io::Error> {
let file = match std::fs::read_to_string("username.txt") {
Ok(content) => content,
Expand All @@ -50,7 +50,7 @@ fn read_username() -> Result<String, std::io::Error> {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn read_username() -> Result<String, std::io::Error> {
let content = std::fs::read_to_string("username.txt")?;
Ok(content.trim().to_string())
Expand Down Expand Up @@ -93,7 +93,7 @@ let value = some_option.unwrap_or_default();
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
use std::fmt;

#[derive(Debug)]
Expand Down Expand Up @@ -142,7 +142,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn parse_and_double(s: &str) -> Result<i32, std::num::ParseIntError> {
s.parse::<i32>().map(|n| n * 2)
}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/appendix/exercises/ch10-exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn main() {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
trait Describable {
fn describe(&self) -> String;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ fn longest(x: &str, y: &str) -> &str {
<details>
<summary>ดูเฉลย</summary>

```rust
```rust,ignore
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
Expand Down
Loading