feat: reorganize workbook into 3 tracks (core, engineering-2026, ecosystems)
This commit is contained in:
1 parent
82677455b2
commit
2e002b6176
64 files changed
+2295
-196
No files matched your search
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "eco03-shared-core-ffi"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
thiserror = "2"
|
||||
@@ -0,0 +1,17 @@
|
||||
# 03 — Wspólny Rdzeń pod Mobile (iOS/Android UniFFI) i Desktop (Tauri)
|
||||
|
||||
W projektach mobilnych (Swift/Kotlin) oraz desktopowych (Tauri v2) w Ruście pisze się **wspólny, niezależny od platformy rdzeń logiki**, a następnie wystawia go przez cienką granicę FFI/IPC (`UniFFI`, `tauri::command`).
|
||||
|
||||
## Kluczowe zasady projektowania granicy FFI/IPC
|
||||
* Płaskie, serializowalne DTO (`String`, `u64`, `Vec<T>`, `Option<T>`) — bez referencji z lifetime'ami `'a` w publicznym API.
|
||||
* Jawne, serializowalne błędy (`thiserror::Error` + `Serialize`) — **zero `panic!` przez granicę FFI** (panika przez FFI to Undefined Behavior w C/Swift/Kotlin).
|
||||
* Zero typów zależnych od systemu operacyjnego (`std::os::unix`) na granicy API.
|
||||
|
||||
## Zadania (`src/lib.rs`)
|
||||
1. Zaimplementuj `validate_and_create_note(input: CreateNoteDto) -> Result<NoteDto, CoreError>` (walidacja pustego tytułu, generowanie prostego sluga lowercase z `-` zamiast spacji).
|
||||
2. Wykorzystaj `thiserror::Error` w `CoreError` dla czytelnych komunikatów błędów.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test PKG=eco03-shared-core-ffi
|
||||
```
|
||||
@@ -0,0 +1,66 @@
|
||||
#![allow(unused_variables, dead_code)]
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct CreateNoteDto {
|
||||
pub title: String,
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct NoteDto {
|
||||
pub slug: String,
|
||||
pub title: String,
|
||||
pub word_count: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum CoreError {
|
||||
#[error("note title cannot be empty")]
|
||||
EmptyTitle,
|
||||
#[error("note body exceeds maximum length of {max} characters")]
|
||||
BodyTooLong { max: usize },
|
||||
}
|
||||
|
||||
pub fn validate_and_create_note(input: CreateNoteDto) -> Result<NoteDto, CoreError> {
|
||||
todo!(
|
||||
"Odrzuć pusty title (EmptyTitle), body > 500 znaków (BodyTooLong {{ max: 500 }}), zbuduj slug (lowercase, spacje -> '-') i policz word_count"
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn builds_ffi_friendly_note_dto() {
|
||||
let dto = CreateNoteDto {
|
||||
title: String::from(" Hello Rust Mobile "),
|
||||
body: String::from("Shared core works on iOS and Android"),
|
||||
};
|
||||
let note = validate_and_create_note(dto).unwrap();
|
||||
assert_eq!(note.slug, "hello-rust-mobile");
|
||||
assert_eq!(note.title, "Hello Rust Mobile");
|
||||
assert_eq!(note.word_count, 7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_typed_errors_instead_of_panicking() {
|
||||
let empty = CreateNoteDto {
|
||||
title: String::from(" "),
|
||||
body: String::from("ok"),
|
||||
};
|
||||
assert_eq!(validate_and_create_note(empty), Err(CoreError::EmptyTitle));
|
||||
|
||||
let huge = CreateNoteDto {
|
||||
title: String::from("Valid"),
|
||||
body: "a".repeat(501),
|
||||
};
|
||||
assert_eq!(
|
||||
validate_and_create_note(huge),
|
||||
Err(CoreError::BodyTooLong { max: 500 })
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user