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,4 @@
[package]
name = "core05-generics-traits"
version = "0.1.0"
edition = "2021"
@@ -0,0 +1,16 @@
# 05 — Generyki, Traity i Lifetimes
## Zakres
* Funkcje i typy generyczne (`<T: PartialOrd>`)
* Definiowanie i implementowanie traitów (`trait Summary`)
* Podstawowe adnotacje czasu życia (`'a`)
## Zadania (`src/lib.rs`)
1. `largest<T: PartialOrd>(items: &[T]) -> Option<&T>` — referencja do największego elementu lub `None`.
2. Zaimplementuj trait `Summary` dla `Article`.
3. `longest<'a>(x: &'a str, y: &'a str) -> &'a str` — dłuższy napis (przy równej długości zwróć `x`).
## Uruchomienie testów
```bash
make test PKG=core05-generics-traits
```
@@ -0,0 +1,51 @@
#![allow(unused_variables, dead_code)]
pub trait Summary {
fn summarize(&self) -> String;
}
pub struct Article {
pub title: String,
pub author: String,
}
impl Summary for Article {
fn summarize(&self) -> String {
todo!("Zwróć format: \"<title> by <author>\"")
}
}
pub fn largest<T: PartialOrd>(items: &[T]) -> Option<&T> {
todo!("Zwróć referencję do największego elementu w items lub None")
}
pub fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
todo!("Zwróć dłuższy wycinek (przy równej długości zwróć x)")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn summarizes_article() {
let article = Article {
title: String::from("Ownership in Rust"),
author: String::from("Ferris"),
};
assert_eq!(article.summarize(), "Ownership in Rust by Ferris");
}
#[test]
fn finds_largest_generic() {
assert_eq!(largest::<i32>(&[]), None);
assert_eq!(largest(&[3, 1, 9, 4]), Some(&9));
assert_eq!(largest(&['a', 'z', 'm']), Some(&'z'));
}
#[test]
fn picks_longest_slice() {
assert_eq!(longest("rust", "programming"), "programming");
assert_eq!(longest("same", "size"), "same");
}
}