> ## Documentation Index
> Fetch the complete documentation index at: https://hayate.shiina.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Embed Hayate as a Rust Library for Encrypted File Transfers

> Add the hayate crate to your Rust project to embed encrypted QUIC file transfers using the HayateSender and HayateReceiver builders.

The `hayate` crate is the core transfer engine behind the Hayate CLI, and it is designed from the ground up to be embedded directly into your own Rust applications. If you need encrypted, high-performance LAN file transfers inside a desktop tool, background service, or custom workflow — without shelling out to an external process — adding `hayate` as a library dependency gives you full programmatic control over every stage of the transfer: connection establishment, consent, progress reporting, and error recovery.

## Add the Dependency

Add `hayate` and the `compio` async runtime to your `Cargo.toml`:

```toml Cargo.toml theme={null}
[dependencies]
hayate = "6"
compio = { version = "0.19", features = ["macros", "runtime", "fs", "net", "time"] }
```

## Quick Example

The following sends a single file to a known receiver address using Direct Mode:

```rust theme={null}
use std::net::SocketAddr;
use hayate::HayateSender;

#[compio::main]
async fn main() -> Result<(), hayate::EngineError> {
    let target: SocketAddr = "192.168.1.50:50001".parse().unwrap();

    let sender = HayateSender::new()
        .target(target)
        .compress(true);

    let checksum = sender.send("./file.txt", |bytes_sent| {
        println!("Sent {bytes_sent} bytes");
        Ok(())
    }).await?;

    println!("Transfer complete. Checksum: {checksum}");
    Ok(())
}
```

## Workspace Crates

| Crate        | Purpose                                         |
| ------------ | ----------------------------------------------- |
| `hayate`     | Core engine: QUIC, crypto, streaming, discovery |
| `hayate-cli` | CLI binary wrapping the engine                  |

## Runtime Requirement

Hayate's async APIs run inside a `compio` runtime. Annotate your async `main` with `#[compio::main]`, or use `compio::runtime::Runtime::new().unwrap().block_on(...)` to drive async code from a synchronous context:

```rust theme={null}
compio::runtime::Runtime::new()
    .unwrap()
    .block_on(async {
        // your hayate code here
    });
```

## Crate Root Exports

The following types are re-exported at the crate root for convenience:

| Symbol             | Description                                                |
| ------------------ | ---------------------------------------------------------- |
| `HayateSender`     | Builder for sending files or directories                   |
| `HayateReceiver`   | Builder for receiving files or directories                 |
| `EngineError`      | Top-level error enum returned by all async functions       |
| `Metadata`         | Transfer metadata struct (filename, size, hash algorithm)  |
| `DiscoveredPeer`   | Peer info returned by the discovery subsystem              |
| `BroadcasterGuard` | RAII handle that stops discovery broadcasting when dropped |

Full generated API documentation is available at [docs.rs/hayate](https://docs.rs/hayate).

## Next Steps

<CardGroup cols={2}>
  <Card title="HayateSender" href="/library/hayatesender">
    Build and configure a sender, set target or pairing code, and stream files or directories.
  </Card>

  <Card title="HayateReceiver" href="/library/hayatereceiver">
    Bind a QUIC listener, handle consent callbacks, and save incoming transfers.
  </Card>

  <Card title="Error Handling" href="/library/error-handling">
    Match EngineError variants, cancel transfers mid-stream, and recover from failures.
  </Card>

  <Card title="Low-Level Modules" href="/library/modules">
    Access crypto, discovery, buffer pooling, and protocol internals directly.
  </Card>
</CardGroup>
