fleascope-rs 0.2.0

Library to interact with a Fleascope
Documentation
use fleascope_rs::{FleaScope, ProbeType};
use std::time::Duration;

/// Example showing synchronous usage (CLI, simple scripts)
fn sync_example() -> Result<(), Box<dyn std::error::Error>> {
    println!("=== Synchronous Usage ===");

    let mut fleascope = FleaScope::connect(None, None, true)?;

    // Direct, blocking read - perfect for CLI applications
    let lazy_frame = fleascope.read(ProbeType::X1, Duration::from_millis(50), None, None)?;

    let df = lazy_frame.collect()?;
    println!("Sync read: {} data points", df.height());

    Ok(())
}

/// Example showing how the same function would be used in async context
async fn async_example() -> Result<(), Box<dyn std::error::Error>> {
    println!("=== Async Usage (spawn_blocking) ===");

    // This is how you'd use it in an async application with tokio
    let result = tokio::task::spawn_blocking(
        || -> Result<usize, Box<dyn std::error::Error + Send + Sync>> {
            let mut fleascope = FleaScope::connect(None, None, true)?;

            // Use read (same as before - no need for _blocking suffix)
            let lazy_frame =
                fleascope.read(ProbeType::X1, Duration::from_millis(50), None, None)?;

            let df = lazy_frame.collect()?;
            Ok(df.height())
        },
    )
    .await??;

    println!("Async read: {} data points", result);

    Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Show synchronous usage
    sync_example()?;

    // Show async usage
    let rt = tokio::runtime::Runtime::new()?;
    rt.block_on(async_example())?;

    Ok(())
}