# Rust

### Installation

To add the Connect Framework Rust SDK to your project, include it in `Cargo.toml`:

```toml
[dependencies]
connect-framework = "0.8"
```

Then, import the crate in your code:

```rust
use connect_framework::ConnectFramework;
```

***

### Usage

#### Initializing the SDK

Before making any API calls, you must initialize the SDK with your API key.

```rust
// Initialize the SDK with an API key
ConnectFramework::initialize("your_api_key_here");
```

***

### User Authentication

#### Logging in with a Unique ID and Email

Logs in the user using a unique ID and an email. If `unique_id` is `None`, a new one will be generated automatically. The callback is executed when the login process completes.

```rust
ConnectFramework::login(None, "user@example.com");
```

#### Submitting an OTP Code

If the login process requires an OTP (One-Time Password), this function submits the OTP code for verification.

```rust
fn otp_callback(success: bool) {
    if success {
        println!("OTP verified successfully and logged in.");
    } else {
        println!("OTP verification failed.");
    }
}

ConnectFramework::submit_otp("user@example.com", "123456", otp_callback);
```

#### Logging Out

Logs out the user entirely.

```rust
ConnectFramework::logout();
```

#### Checking if User is Connected

Returns `true` if the user is logged in and running the Connect.ai desktop client.

```rust
let is_connected = ConnectFramework::is_connected();
println!("User is connected: {}", is_connected);
```

***

### Analytics Tracking

#### Logging an Event

Logs an analytics event with a category and action.

```rust
ConnectFramework::log_event("user_action", "button_click");
```

#### Logging an Event with Additional Data

Logs an analytics event with a category, action, label, and numerical value.

```rust
ConnectFramework::log_event_with_details("user_action", "purchase", "premium_upgrade", 29.99);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.connect.ai/sdk-integration-guides/rust.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
