# deployramp

[![crates.io](https://img.shields.io/crates/v/deployramp)](https://crates.io/crates/deployramp)
[![docs.rs](https://docs.rs/deployramp/badge.svg)](https://docs.rs/deployramp)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Rust SDK for [DeployRamp](https://deployramp.com) — AI-native feature flag management with gradual rollouts, real-time updates, and automatic error-monitored rollbacks.

## Installation

```bash
cargo add deployramp
```

Or add to `Cargo.toml` manually:

```toml
[dependencies]
deployramp = "0.1"
```

## Quick Start

```rust
use deployramp::{init, flag, report, close, Config};

fn main() {
    init(Config {
        public_token: "drp_pub_your_token".to_string(),
        ..Default::default()
    }).expect("failed to initialize DeployRamp");

    // Evaluate a feature flag
    if flag("new-checkout-flow", None) {
        process_new_checkout();
    } else {
        process_old_checkout();
    }

    // Report errors — DeployRamp uses these to auto-roll back bad deploys
    if let Err(e) = process_checkout() {
        report(&e.to_string(), None, Some("new-checkout-flow"), None);
    }

    close();
}
```

## Trait-Based Targeting

```rust
use deployramp::{init, flag, set_traits, Config};
use std::collections::HashMap;

init(Config {
    public_token: "drp_pub_your_token".to_string(),
    ..Default::default()
}).unwrap();

// Update traits after login
let mut traits = HashMap::new();
traits.insert("plan".to_string(), "enterprise".to_string());
traits.insert("cohort".to_string(), "beta".to_string());
set_traits(traits);

// Evaluate with per-call trait overrides
let mut overrides = HashMap::new();
overrides.insert("cohort".to_string(), "alpha".to_string());
let enabled = flag("beta-feature", Some(&overrides));
```

## Measure Performance

```rust
use deployramp::measure;

let result = measure(
    "fast-algorithm",
    || new_algorithm(&data),
    || old_algorithm(&data),
    None,
);
```

## API Reference

| Function | Description |
|---|---|
| `init(config) -> Result<(), String>` | Initialize the SDK, fetch flags, open WebSocket |
| `flag(name, trait_overrides?) -> bool` | Evaluate a feature flag |
| `set_traits(traits)` | Update user traits for all subsequent evaluations |
| `measure(name, enabled_fn, disabled_fn, trait_overrides?)` | Run branch and record timing |
| `report(message, stack?, flag_name?, trait_overrides?)` | Report an error for rollback monitoring |
| `close()` | Flush pending events and disconnect |

## Links

- [deployramp.com](https://deployramp.com)
- [GitHub](https://github.com/deployramp/deployramp)
- [crates.io](https://crates.io/crates/deployramp)
- [docs.rs](https://docs.rs/deployramp)

## License

MIT
