heroforge-core 0.2.2

Pure Rust core library for reading and writing Fossil SCM repositories
Documentation
//! QUIC server builder.

use crate::error::{FossilError, Result};
use crate::repo::Repository;

/// Builder for QUIC sync server.
pub struct QuicServerBuilder {
    bind_addr: Option<String>,
}

impl QuicServerBuilder {
    pub(crate) fn new() -> Self {
        Self { bind_addr: None }
    }

    /// Set the address to bind to (e.g., "0.0.0.0:4443").
    pub fn bind(mut self, addr: &str) -> Self {
        self.bind_addr = Some(addr.to_string());
        self
    }

    /// Start the server and handle a single sync request (blocking).
    #[cfg(feature = "sync-quic")]
    pub fn start_blocking(self, repo: &Repository) -> Result<()> {
        use crate::sync::QuicServer;
        use std::path::PathBuf;

        let bind_addr = self
            .bind_addr
            .ok_or_else(|| FossilError::InvalidArtifact("bind address is required".to_string()))?;

        let rt =
            tokio::runtime::Runtime::new().map_err(|e| FossilError::SyncError(e.to_string()))?;

        rt.block_on(async {
            let server = QuicServer::bind(&bind_addr)?;
            println!("QUIC server listening on {}", server.local_addr()?);
            server.handle_sync(repo, &PathBuf::new()).await?;
            Ok(())
        })
    }

    /// Start the server (blocking) - stub when QUIC feature is disabled.
    #[cfg(not(feature = "sync-quic"))]
    pub fn start_blocking(self, _repo: &Repository) -> Result<()> {
        Err(FossilError::InvalidArtifact(
            "QUIC server requires 'sync-quic' feature".to_string(),
        ))
    }
}