Skip to content

Commit a52ee5a

Browse files
docs: auto-sync documentation and rosetta examples
1 parent a0c2d32 commit a52ee5a

8 files changed

Lines changed: 161 additions & 12 deletions

docs.zenc-lang.org/content/tour/08-memory-management.de.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,29 @@ fn main() {
6969
```
7070

7171
#### RAII / Drop Trait
72-
Implementiere `Drop`, um automatische Aufräumlogik auszuführen.
72+
73+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
74+
7375
```zc
7476
impl Drop for MyStruct {
7577
fn drop(self) {
7678
self.free();
7779
}
7880
}
7981
```
82+
83+
**Umhüllen eines RAII-Typs.** Wenn dein Struct ein Feld enthält, das bereits `Drop` implementiert (wie `Vec` oder `String`), kümmert sich der Compiler automatisch um die Bereinigung. Du musst kein `impl Drop` für das äußere Struct schreiben.
84+
85+
```zc
86+
struct MyVecWrapper {
87+
inner: Vec<int>; // Vec::drop() called automatically
88+
}
89+
```
90+
91+
{% alert(type="note") %}
92+
**Beispiel:** `String` ist als `struct String { vec: Vec<char>; }` definiert -- es benötigt keine explizite `Drop`-Implementierung, da `Vec<char>` den gesamten Speicher verwaltet. `Set<T>` hingegen verwendet rohe `T*`-Zeiger und benötigt explizites `Drop`.
93+
{% end %}
94+
95+
**Faustregel:**
96+
- Felder vom Typ `Vec<T>`, `String` oder andere RAII-Typen → automatisches Drop
97+
- Felder vom Typ `T*`, `malloc`-Zeiger oder Dateihandles → explizites Drop erforderlich

docs.zenc-lang.org/content/tour/08-memory-management.es.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,29 @@ fn main() {
6363
```
6464

6565
#### RAII / Drop Trait
66-
Implementa `Drop` para ejecutar lógica de limpieza automáticamente.
66+
67+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
68+
6769
```zc
68-
impl Drop for MiEstructura {
70+
impl Drop for MyStruct {
6971
fn drop(self) {
7072
self.free();
7173
}
7274
}
7375
```
76+
77+
**Envolver un tipo RAII.** Si tu struct contiene un campo que ya implementa `Drop` (como `Vec` o `String`), el compilador maneja la limpieza automáticamente. NO necesitas escribir `impl Drop` para el struct externo.
78+
79+
```zc
80+
struct MyVecWrapper {
81+
inner: Vec<int>; // Vec::drop() called automatically
82+
}
83+
```
84+
85+
{% alert(type="note") %}
86+
**Ejemplo:** `String` se define como `struct String { vec: Vec<char>; }` — NO necesita una implementación explícita de `Drop` porque `Vec<char>` gestiona toda la memoria. `Set<T>` por otro lado usa punteros `T*` sin procesar y SÍ necesita `Drop` explícito.
87+
{% end %}
88+
89+
**Regla general:**
90+
- Campos que son `Vec<T>`, `String` u otros tipos RAII → Drop automático
91+
- Campos que son `T*`, punteros `malloc` o manejadores de archivos → Drop explícito requerido

docs.zenc-lang.org/content/tour/08-memory-management.it.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,29 @@ fn main() {
6363
```
6464

6565
#### RAII / Rilascio Tratti
66-
Implementa `Drop` per una logica di pulizia automatica.
66+
67+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
68+
6769
```zc
68-
impl Drop for MioStruct {
70+
impl Drop for MyStruct {
6971
fn drop(self) {
7072
self.free();
7173
}
7274
}
7375
```
76+
77+
**Avvolgere un tipo RAII.** Se la tua struttura contiene un campo che implementa già `Drop` (come `Vec` o `String`), il compilatore gestisce automaticamente la pulizia. NON è necessario scrivere `impl Drop` per la struttura esterna.
78+
79+
```zc
80+
struct MyVecWrapper {
81+
inner: Vec<int>; // Vec::drop() called automatically
82+
}
83+
```
84+
85+
{% alert(type="note") %}
86+
**Esempio:** `String` è definita come `struct String { vec: Vec<char>; }` -- NON necessita di un'implementazione esplicita di `Drop` perché `Vec<char>` gestisce tutta la memoria. `Set<T>` invece usa puntatori `T*` grezzi e necessita di `Drop` esplicito.
87+
{% end %}
88+
89+
**Regola pratica:**
90+
- Campi che sono `Vec<T>`, `String` o altri tipi RAII → Drop automatico
91+
- Campi che sono `T*`, puntatori `malloc` o handle di file → Drop esplicito richiesto

docs.zenc-lang.org/content/tour/08-memory-management.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,34 @@ fn main() {
6767
```
6868

6969
#### RAII / Drop Trait
70-
Implement `Drop` to run cleanup logic automatically.
70+
71+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
72+
7173
```zc
7274
impl Drop for MyStruct {
7375
fn drop(self) {
7476
self.free();
7577
}
7678
}
7779
```
80+
81+
**Wrapping an RAII type.** If your struct contains a field that already implements
82+
`Drop` (like `Vec` or `String`), the compiler handles cleanup automatically.
83+
You do NOT need to write `impl Drop` for the outer struct.
84+
85+
```zc
86+
struct MyVecWrapper {
87+
inner: Vec<int>; // Vec::drop() called automatically
88+
}
89+
```
90+
91+
{% alert(type="note") %}
92+
**Example:** `String` is defined as `struct String { vec: Vec<char>; }` — it
93+
does NOT need an explicit `Drop` implementation because `Vec<char>` handles
94+
all the memory. `Set<T>` on the other hand uses raw `T*` pointers and
95+
DOES need explicit `Drop`.
96+
{% end %}
97+
98+
**Rule of thumb:**
99+
- Fields that are `Vec<T>`, `String`, or other RAII types → automatic Drop
100+
- Fields that are raw `T*`, `malloc`'d pointers, or file handles → explicit Drop required

docs.zenc-lang.org/content/tour/08-memory-management.pt.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,29 @@ fn main() {
6767
```
6868

6969
#### RAII / Drop Trait
70-
Implementa `Drop` para executar lógica de limpeza automaticamente.
70+
71+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
72+
7173
```zc
7274
impl Drop for MyStruct {
7375
fn drop(self) {
7476
self.free();
7577
}
7678
}
7779
```
80+
81+
**Encapsulando um tipo RAII.** Se seu struct contém um campo que já implementa `Drop` (como `Vec` ou `String`), o compilador cuida da limpeza automaticamente. Você NÃO precisa escrever `impl Drop` para o struct externo.
82+
83+
```zc
84+
struct MyVecWrapper {
85+
inner: Vec<int>; // Vec::drop() called automatically
86+
}
87+
```
88+
89+
{% alert(type="note") %}
90+
**Exemplo:** `String` é definida como `struct String { vec: Vec<char>; }` — NÃO precisa de uma implementação explícita de `Drop` porque `Vec<char>` gerencia toda a memória. `Set<T>` por outro lado usa ponteiros `T*` brutos e PRECISA de `Drop` explícito.
91+
{% end %}
92+
93+
**Regra prática:**
94+
- Campos que são `Vec<T>`, `String` ou outros tipos RAII → Drop automático
95+
- Campos que são `T*`, ponteiros `malloc` ou handles de arquivo → Drop explícito necessário

docs.zenc-lang.org/content/tour/08-memory-management.ru.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,29 @@ fn main() {
6363
```
6464

6565
#### RAII / Трейт Drop
66-
Реализуйте `Drop` для автоматического запуска логики очистки.
66+
67+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
68+
6769
```zc
6870
impl Drop for MyStruct {
6971
fn drop(self) {
7072
self.free();
7173
}
7274
}
7375
```
76+
77+
**Обёртка RAII-типа.** Если ваша структура содержит поле, которое уже реализует `Drop` (например, `Vec` или `String`), компилятор обрабатывает очистку автоматически. Вам НЕ нужно писать `impl Drop` для внешней структуры.
78+
79+
```zc
80+
struct MyVecWrapper {
81+
inner: Vec<int>; // Vec::drop() called automatically
82+
}
83+
```
84+
85+
{% alert(type="note") %}
86+
**Пример:** `String` определён как `struct String { vec: Vec<char>; }` -- ему НЕ нужна явная реализация `Drop`, потому что `Vec<char>` управляет всей памятью. `Set<T>` напротив использует сырые указатели `T*` и ТРЕБУЕТ явного `Drop`.
87+
{% end %}
88+
89+
**Правило:**
90+
- Поля `Vec<T>`, `String` или другие RAII-типы → автоматический Drop
91+
- Поля `T*`, `malloc`-указатели или файловые дескрипторы → требуется явный Drop

docs.zenc-lang.org/content/tour/08-memory-management.zh-cn.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,30 @@ fn main() {
6666
}
6767
```
6868

69-
#### RAII / Drop Trait
70-
实现 `Drop` 以自动运行清理逻辑。
69+
#### RAII / Drop 特性
70+
71+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
72+
7173
```zc
7274
impl Drop for MyStruct {
7375
fn drop(self) {
7476
self.free();
7577
}
7678
}
7779
```
80+
81+
**包装 RAII 类型。**如果结构体包含已经实现了 `Drop` 的字段(如 `Vec``String`),编译器会自动处理清理。你**不需要**为外部结构体编写 `impl Drop`
82+
83+
```zc
84+
struct MyVecWrapper {
85+
inner: Vec<int>; // Vec::drop() called automatically
86+
}
87+
```
88+
89+
{% alert(type="note") %}
90+
**示例:** `String` 定义为 `struct String { vec: Vec<char>; }` -- 它**不需要**显式的 `Drop` 实现,因为 `Vec<char>` 管理所有内存。而 `Set<T>` 使用原始 `T*` 指针,**需要**显式的 `Drop`
91+
{% end %}
92+
93+
**经验法则:**
94+
- `Vec<T>``String` 或其他 RAII 类型的字段 → 自动 Drop
95+
- `T*``malloc` 分配的指针或文件句柄 → 需要显式 Drop

docs.zenc-lang.org/content/tour/08-memory-management.zh-tw.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,30 @@ fn main() {
6666
}
6767
```
6868

69-
#### RAII / Drop Trait
70-
實現 `Drop` 以自動運行清理邏輯。
69+
#### RAII / Drop 特性
70+
71+
Implement `Drop` to run cleanup logic automatically when a value goes out of scope.
72+
7173
```zc
7274
impl Drop for MyStruct {
7375
fn drop(self) {
7476
self.free();
7577
}
7678
}
7779
```
80+
81+
**包裝 RAII 類型。**如果結構體包含已經實作了 `Drop` 的欄位(如 `Vec``String`),編譯器會自動處理清理。你**不需要**為外部結構體編寫 `impl Drop`
82+
83+
```zc
84+
struct MyVecWrapper {
85+
inner: Vec<int>; // Vec::drop() called automatically
86+
}
87+
```
88+
89+
{% alert(type="note") %}
90+
**範例:** `String` 定義為 `struct String { vec: Vec<char>; }` -- 它**不需要**顯式的 `Drop` 實作,因為 `Vec<char>` 管理所有記憶體。而 `Set<T>` 使用原始 `T*` 指標,**需要**顯式的 `Drop`
91+
{% end %}
92+
93+
**經驗法則:**
94+
- `Vec<T>``String` 或其他 RAII 類型的欄位 → 自動 Drop
95+
- `T*``malloc` 分配的指標或檔案控制代碼 → 需要顯式 Drop

0 commit comments

Comments
 (0)