# Constraints Reference

## `latency = "< TIME"`

Bounds the estimated worst-case execution time.

```rust
#[redline(latency = "< 1ms")]     // under 1 millisecond
#[redline(latency = "< 100us")]   // under 100 microseconds
#[redline(latency = "< 500ns")]   // under 500 nanoseconds
#[redline(latency = "< 2s")]      // under 2 seconds
```

The analyzer sums operation costs, multiplies by loop iterations, takes worst-case branches.

**Units:** `ns`, `us`, `ms`, `s`

## `allocs = N` or `allocs = "< N"`

Bounds the number of heap allocations.

```rust
#[redline(allocs = 0)]        // zero allocations
#[redline(allocs = "< 5")]    // fewer than 5 allocations
```

**What counts as an allocation:**
- `Vec::new()`, `Vec::with_capacity()`
- `Box::new()`
- `String::new()`, `String::from()`, `String::with_capacity()`
- `HashMap::new()`, `BTreeMap::new()`, etc.
- `.to_string()`, `.to_owned()`, `.collect()`
- `format!()`
- `.clone()` on heap types (String, Vec, Box, HashMap)
- `Rc::new()`, `Arc::new()`

**What does NOT count:**
- `.clone()` on primitives and Copy types
- Stack allocations (local variables)
- `.get()` on slices

Allocations inside loops are multiplied by the iteration count.

## `syscalls = N`

Bounds the number of system calls.

```rust
#[redline(syscalls = 0)]    // zero syscalls
```

**What counts as a syscall:**
- `fs::read`, `fs::write`, `fs::read_to_string`, etc.
- `File::open`, `File::create`
- `TcpStream::connect`, `UdpSocket::bind`
- `println!`, `print!`, `eprintln!`
- `write!`, `writeln!`

## `max_stack = "< SIZE"`

Bounds the estimated stack frame size.

```rust
#[redline(max_stack = "< 4KB")]
#[redline(max_stack = "< 1MB")]
```

**Units:** `B`, `KB`, `MB`, `GB`

## `throughput = "> RATE"`

Planned for v0.2. Requires data size analysis not available at the AST level.

```rust
#[redline(throughput = "> 1GB/s")]  // parses but not checked in v0.1
```

## Combining Constraints

All constraints in a single annotation are checked independently:

```rust
#[redline(latency = "< 1ms", allocs = 0, syscalls = 0)]
fn fast_and_clean(x: u64) -> u64 {
    x * x
}
```

If any single constraint is violated, the function does not compile.
