2025-06-27 15:55:37 -04:00
|
|
|
# Example
|
2025-06-27 08:48:57 -04:00
|
|
|
|
2025-06-27 15:55:37 -04:00
|
|
|
A lightweight collection of examples demonstrating essential Rust features,
|
|
|
|
without relying on external dependencies (except `tokio`).
|
2025-06-27 08:48:57 -04:00
|
|
|
|
|
|
|
|
2025-06-27 15:55:37 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
### Concepts Covered
|
|
|
|
|
|
|
|
- Arrays and Iteration
|
|
|
|
- Lifetimes and Borrowing
|
|
|
|
- Error Handling with `Result`, `?`, and custom messages
|
|
|
|
- Async Programming using `#[tokio::main]`
|
|
|
|
- File I/O with the standard library
|
|
|
|
- Unit and async testing
|
|
|
|
|
|
|
|
### Key Functions
|
|
|
|
|
|
|
|
| Function | Description |
|
|
|
|
|------------------|--------------------------------------------------------|
|
|
|
|
| `longest` | Returns the longest string in a slice without copying. |
|
|
|
|
| `read_and_parse` | Reads a file and parses its content into an integer. |
|
|
|
|
| `run_tasks` | Demonstrates spawning and awaiting async tasks. |
|
|
|
|
|
|
|
|
### Testing
|
|
|
|
|
|
|
|
Includes both synchronous and asynchronous unit tests under a
|
|
|
|
`#[cfg(test)]` module.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Testing & Extending
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
- Rust 1.76+ (for full language support)
|
|
|
|
- [Tokio 1.37+](https://docs.rs/tokio) (for async runtime)
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Project Structure
|
|
|
|
|
|
|
|
```text
|
|
|
|
src/
|
|
|
|
├── info.rs # Crate information from Cargo.
|
|
|
|
├── main.rs # Foundational examples.
|
|
|
|
```
|
|
|
|
|
2025-06-27 08:48:57 -04:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## Copyright & License
|
|
|
|
|
2025-06-27 15:55:37 -04:00
|
|
|
Copyright 2025 Jason Travis Smith
|
2025-06-27 08:48:57 -04:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this library except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS
|