feat: add loading animation example
Add a busy-wait sleep on a monotonic clock and re-export String, format!, and Duration from the library. The example animates a progress bar with a spinner and logs each step in a Vec<String>. Co-Authored-By: qwen (lmstudio/qwen3.8-27b@q3_k_xl): wrote example
This commit is contained in:
@@ -6,16 +6,17 @@ This project is a small Rust common library and runtime built without Cargo.
|
||||
CMake invokes `rustc` directly. The library provides a low-footprint subset
|
||||
of standard-library-like functionality:
|
||||
|
||||
- `Result` and formatting from `core`
|
||||
- `Vec` and `vec![]` from `alloc`
|
||||
- `Result`, `Duration`, and formatting from `core`
|
||||
- `Vec`, `String`, `vec![]`, and `format!` from `alloc`
|
||||
- project-local `print!` and `println!` macros
|
||||
- direct platform stdout and heap calls
|
||||
- direct platform stdout, heap calls, and busy-wait sleep
|
||||
|
||||
The project contains:
|
||||
|
||||
- `src/lib.rs`: the `#![no_std]` common library API
|
||||
- `src/io.rs`: the `core::fmt::Write` stdout backend
|
||||
- `src/runtime.rs`: allocator, async polling, and platform entry helpers
|
||||
- `src/runtime.rs`: allocator, async polling, monotonic sleep, and platform
|
||||
entry helpers
|
||||
- `macros/src/lib.rs`: host-side `#[rslibc_macros::main]` attribute macro
|
||||
- `runtime/main.rs`: minimal example entry point
|
||||
- `CMakeLists.txt`: direct `rustc` library, macro, and executable commands
|
||||
@@ -36,8 +37,8 @@ The project contains:
|
||||
- Keep OS integration in small FFI modules. Do not pull in a general-purpose
|
||||
runtime or C I/O layer for basic output.
|
||||
- `rslibc_macros::main` can wrap `async fn main()` with the small `block_on`
|
||||
executor. It is only a polling loop and does not provide Tokio-style I/O,
|
||||
timers, or a reactor.
|
||||
executor. It is only a polling loop and does not provide Tokio-style I/O
|
||||
or a reactor; delays use the busy-wait `rslibc::runtime::sleep`.
|
||||
- Keep unsafe code inside small safe wrappers. Application code should be
|
||||
able to use calls such as:
|
||||
|
||||
@@ -52,6 +53,8 @@ The project contains:
|
||||
- Windows stdout calls `GetStdHandle` and `WriteFile` through `kernel32`.
|
||||
- Windows allocation calls `HeapAlloc` and `HeapFree` through the system
|
||||
heap.
|
||||
- Sleep uses a monotonic clock: `clock_gettime` on Unix and
|
||||
`QueryPerformanceCounter` on Windows.
|
||||
- The Windows runtime dynamically links only the platform support needed by
|
||||
`alloc` and the compiler runtime. Do not statically link the full C
|
||||
runtime.
|
||||
@@ -116,7 +119,8 @@ cmake --build build
|
||||
```
|
||||
|
||||
On Windows, use `Remove-Item -Recurse -Force build` and run
|
||||
`build\\rslibc_example.exe` instead. Confirm that stdout contains `Hello`.
|
||||
`build\\rslibc_example.exe` instead. Confirm that stdout contains
|
||||
`100% done`.
|
||||
|
||||
When size matters, inspect the Windows executable after a release build.
|
||||
Avoid adding formatting, allocation, or OS dependencies unless they are
|
||||
|
||||
Reference in New Issue
Block a user