# Use Cases

## 1. Zero-Allocation Hot Paths

You have a function called millions of times per second. It must never allocate.

```rust
#[redline(allocs = 0)]
fn process_tick(price: f64, volume: u64) -> f64 {
    price * volume as f64
}
```

If someone adds a `format!()` or `.to_string()` during refactoring, the build breaks. The invariant is enforced permanently.

## 2. Latency-Bounded Request Handlers

Your SLA says P99 latency must be under 1ms. Put that in the code.

```rust
#[redline(latency = "< 1ms")]
fn handle_request(data: &[u8]) -> Response {
    let parsed = parse_header(data);
    let result = compute(parsed);
    Response::new(result)
}
```

If someone adds a loop or an allocation that pushes the estimate over 1ms, they find out at compile time, not in production at 3am.

## 3. No-I/O Pure Functions

Functions in your core library must never touch the filesystem or network.

```rust
#[redline(syscalls = 0)]
fn compute_hash(data: &[u8]) -> u64 {
    let mut h: u64 = 0;
    for i in 0..data.len().min(256) {
        h = h.wrapping_mul(31).wrapping_add(data[i] as u64);
    }
    h
}
```

## 4. Embedded / Real-Time

In embedded systems, you need hard guarantees on stack usage and timing.

```rust
#[redline(latency = "< 100us", allocs = 0, max_stack = "< 1KB")]
fn isr_handler(status: u32) -> u32 {
    if status & 0x01 != 0 {
        status | 0x80
    } else {
        status & 0x7F
    }
}
```

## 5. Protecting Against Accidental Regression

Your team wrote a fast path. A new hire adds a `println!()` for debugging and forgets to remove it.

```rust
#[redline(syscalls = 0)]
fn fast_path(x: u64) -> u64 {
    // println!("debug: {}", x);  // uncommenting this = compile error
    x * x + 1
}
```

The annotation is documentation and enforcement in one line.

## 6. Library API Contracts

You publish a crate. You want users to know a function is allocation-free.

```rust
/// Computes the checksum. Guaranteed zero allocations.
#[redline(allocs = 0)]
pub fn checksum(data: &[u8]) -> u32 {
    let mut sum: u32 = 0;
    for i in 0..data.len().min(1024) {
        sum = sum.wrapping_add(data[i] as u32);
    }
    sum
}
```

The `#[redline]` is a machine-checked version of the doc comment.
