feat: reorganize workbook into 3 tracks (core, engineering-2026, ecosystems)

This commit is contained in:
soda64 committed 2026-11-30 22:30:53 +01:00
1 parent 82677455b2
commit 2e002b6176
64 files changed
+2295 -196

No files matched your search

@@ -0,0 +1,8 @@
[package]
name = "eco04-wasm-logic"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
@@ -0,0 +1,13 @@
# 04 — Logika pod WebAssembly (Frontend / Przeglądarka)
Na froncie Rust najczęściej pełni rolę **szybkiego, deterministycznego modułu obliczeniowego (WASM)** wywoływanego z TypeScriptu (np. parsery, walidatory, wyszukiwarki, edytory), wymieniającego dane przez JSON lub binarne bufory.
Moduł testujesz normalnie natywnie (`make test PKG=eco04-wasm-logic`), a w docelowej aplikacji webowej wystarczy dodać atrybut `#[wasm_bindgen]` i skompilować pod target `wasm32-unknown-unknown`.
## Zadania (`src/lib.rs`)
1. `analyze_text_json(input_json: &str) -> Result<String, String>` — zdeserializuj `TextInput { text: String }`, policz liczbę znaków (`chars().count()`), słów i linii, a wynik zwróć jako zserializowany JSON `TextStats`.
## Uruchomienie testów
```bash
make test PKG=eco04-wasm-logic
```
@@ -0,0 +1,44 @@
#![allow(unused_variables, dead_code)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
pub struct TextInput {
pub text: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct TextStats {
pub chars: usize,
pub words: usize,
pub lines: usize,
}
pub fn analyze_text_json(input_json: &str) -> Result<String, String> {
todo!("Deserializuj TextInput z JSON, policz chars/words/lines i zserializuj TextStats do JSON")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn processes_json_boundary_for_js_interop() {
let raw = r#"{"text":"Rust\nin browser"}"#;
let out_json = analyze_text_json(raw).unwrap();
let stats: TextStats = serde_json::from_str(&out_json).unwrap();
assert_eq!(
stats,
TextStats {
chars: 15,
words: 3,
lines: 2
}
);
}
#[test]
fn returns_error_on_invalid_json() {
assert!(analyze_text_json("{invalid").is_err());
}
}