pub mod agent;
pub mod interface;
pub mod rpc;
pub mod util;

use std::any::Any;
use xpc_connection::Message;

/// Result of dispatching an XPC request: the message to send plus an optional
/// resource to keep alive until after the XPC payload is constructed.
pub struct DispatchResult {
    pub message: Message,
    pub cleanup: Option<Box<dyn Any + Send>>,
}

impl DispatchResult {
    pub fn new(message: Message) -> Self {
        Self { message, cleanup: None }
    }

    pub fn with_cleanup<T: Any + Send + 'static>(message: Message, cleanup: T) -> Self {
        Self { message, cleanup: Some(Box::new(cleanup)) }
    }
}
