rscamper 0.2.2

Rust interface to scamper network measurement tool
Documentation
// rscamper - Rust wrapper for scamper tasks
//
// Copyright (C) 2026 Dimitrios Giakatos
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.

use crate::ffi::libscamperctrl::{self, ScamperTaskT};

/// A handle to a scheduled scamper measurement.
///
/// Obtained from `ScamperCtrl::do_trace`, `do_ping`, etc.
/// The task can be halted via `halt()`, and is automatically freed on drop.
pub struct ScamperTask {
    pub(crate) inner: *mut ScamperTaskT,
}

impl ScamperTask {
    pub(crate) unsafe fn from_ptr(ptr: *mut ScamperTaskT) -> Self {
        let ptr = unsafe { libscamperctrl::scamper_task_use(ptr) };
        ScamperTask { inner: ptr }
    }

    /// Halt a running measurement.
    pub fn halt(&self) {
        unsafe { libscamperctrl::scamper_task_halt(self.inner) };
    }
}

impl Drop for ScamperTask {
    fn drop(&mut self) {
        unsafe { libscamperctrl::scamper_task_free(self.inner) };
    }
}

impl PartialEq for ScamperTask {
    fn eq(&self, other: &Self) -> bool { self.inner == other.inner }
}

impl Eq for ScamperTask {}

impl std::hash::Hash for ScamperTask {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        (self.inner as usize).hash(state);
    }
}

unsafe impl Send for ScamperTask {}
unsafe impl Sync for ScamperTask {}