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,4 @@
|
||||
[package]
|
||||
name = "core02-ownership"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
@@ -0,0 +1,16 @@
|
||||
# 02 — Ownership, Borrowing i Slices
|
||||
|
||||
## Zakres
|
||||
* Semantyka przenoszenia (*move*) vs kopiowania (*Copy*)
|
||||
* Referencje niemutowalne (`&T`) i mutowalne (`&mut T`)
|
||||
* Wycinki (*slices*): `&str`, `&[T]`
|
||||
|
||||
## Zadania (`src/lib.rs`)
|
||||
1. `first_word(s: &str) -> &str` — zwróć pierwsze słowo (do pierwszej spacji) lub cały napis.
|
||||
2. `append_exclamation(s: &mut String)` — dopisz `'!'` na końcu przekazanego `String` bez przejmowania własności.
|
||||
3. `sum_slice(values: &[i32]) -> i32` — policz sumę elementów wycinka `&[i32]`.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test PKG=core02-ownership
|
||||
```
|
||||
@@ -0,0 +1,39 @@
|
||||
#![allow(unused_variables, dead_code, clippy::ptr_arg)]
|
||||
|
||||
pub fn first_word(s: &str) -> &str {
|
||||
todo!("Zwróć wycinek reprezentujący pierwsze słowo w s")
|
||||
}
|
||||
|
||||
pub fn append_exclamation(s: &mut String) {
|
||||
todo!("Dopisz '!' do s przez mutowalną referencję")
|
||||
}
|
||||
|
||||
pub fn sum_slice(values: &[i32]) -> i32 {
|
||||
todo!("Zwróć sumę elementów wycinka")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn extracts_first_word() {
|
||||
assert_eq!(first_word("hello world"), "hello");
|
||||
assert_eq!(first_word("rust"), "rust");
|
||||
assert_eq!(first_word(""), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mutates_string_in_place() {
|
||||
let mut msg = String::from("Rust");
|
||||
append_exclamation(&mut msg);
|
||||
assert_eq!(msg, "Rust!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sums_slice_elements() {
|
||||
assert_eq!(sum_slice(&[]), 0);
|
||||
assert_eq!(sum_slice(&[1, 2, 3, 4]), 10);
|
||||
assert_eq!(sum_slice(&[-5, 5, 10]), 10);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user