extio 0.1.0

A unified asynchronous I/O abstraction layer for Rust. `extio` provides a single trait (`Extio`) that defines common interfaces for files, networking, databases, cloud storage, IPC, scheduling, logging, and cryptography. It is designed to enable backends and runtimes to implement consistent, pluggable I/O behaviors across different environments (local, cloud, embedded, or distributed). Features include: - File and directory operations - Cloud/object storage (put/get/delete) - HTTP, TCP, UDP, and WebSocket networking - Database queries and execution - Process execution - Message queues and pub-sub - Inter-process communication (IPC) - Time and scheduling utilities - Environment configuration - Logging and metrics collection - Cryptographic signing, verification, and secret management By default, all methods are unimplemented; users are expected to provide their own implementations depending on their runtime or backend.
Documentation
use std::path::Path;
use std::time::Duration;
use std::time::SystemTime;

use async_trait::async_trait;
use http::{Request, Response};

/// `Extio` is a generalized abstraction layer for I/O operations across
/// files, networking, databases, cloud storage, IPC, and more.
///
/// Each method has a default `unimplemented!()` body and must be
/// implemented by a backend or runtime.
#[allow(unused_variables)]
#[async_trait]
pub trait Extio {
    /// Common error type for all operations.
    type Error: std::fmt::Debug + Send + Sync + 'static;

    // --- File / Storage ---

    /// Reads the entire contents of a file from disk into memory.
    ///
    /// - `path`: Path to the file.
    /// - Returns: File contents as `Vec<u8>`.
    fn read_file(&self, path: &Path) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("read_file not implemented")
    }

    /// Writes binary data into a file, creating or truncating it.
    ///
    /// - `path`: Path where the file will be written.
    /// - `data`: Raw bytes to write.
    fn write_file(&self, path: &Path, data: &[u8]) -> Result<(), Self::Error> {
        unimplemented!("write_file not implemented")
    }

    /// Deletes a file from disk.
    ///
    /// - `path`: Path to the file.
    fn delete_file(&self, path: &Path) -> Result<(), Self::Error> {
        unimplemented!("delete_file not implemented")
    }

    /// Lists the contents of a directory.
    ///
    /// - `path`: Directory path.
    /// - Returns: A vector of file/directory names.
    fn list_dir(&self, path: &Path) -> Result<Vec<String>, Self::Error> {
        unimplemented!("list_dir not implemented")
    }

    // --- Cloud / Object Storage ---

    /// Uploads a blob of binary data to object storage.
    async fn storage_put(&self, key: &str, data: Vec<u8>) -> Result<(), Self::Error> {
        unimplemented!("storage_put not implemented")
    }

    /// Retrieves a blob of binary data from object storage.
    async fn storage_get(&self, key: &str) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("storage_get not implemented")
    }

    /// Deletes a blob from object storage.
    async fn storage_delete(&self, key: &str) -> Result<(), Self::Error> {
        unimplemented!("storage_delete not implemented")
    }

    // --- HTTP / Networking ---

    /// Sends an HTTP request and returns the response.
    async fn http_request(&self, req: Request<Vec<u8>>) -> Result<Response<Vec<u8>>, Self::Error> {
        unimplemented!("http_request not implemented")
    }

    /// Sends data over TCP and waits for a response.
    async fn tcp_send(&self, addr: &str, data: &[u8]) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("tcp_send not implemented")
    }

    /// Sends a UDP packet (fire-and-forget).
    async fn udp_send(&self, addr: &str, data: &[u8]) -> Result<(), Self::Error> {
        unimplemented!("udp_send not implemented")
    }

    // --- WebSockets ---

    /// Establishes a WebSocket connection.
    async fn ws_connect(&self, url: &str) -> Result<(), Self::Error> {
        unimplemented!("ws_connect not implemented")
    }

    /// Sends a WebSocket message.
    async fn ws_send(&self, msg: &[u8]) -> Result<(), Self::Error> {
        unimplemented!("ws_send not implemented")
    }

    /// Receives a WebSocket message.
    async fn ws_receive(&self) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("ws_receive not implemented")
    }

    // --- Database ---

    /// Executes a database query that returns rows.
    ///
    /// - `query`: SQL query string.
    /// - `params`: Serialized parameters.
    /// - Returns: Raw result set as bytes.
    async fn db_query(&self, query: &str, params: &[u8]) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("db_query not implemented")
    }

    /// Executes a database command (e.g., INSERT/UPDATE/DELETE).
    ///
    /// - `query`: SQL statement.
    /// - `params`: Serialized parameters.
    /// - Returns: Number of affected rows.
    async fn db_execute(&self, query: &str, params: &[u8]) -> Result<u64, Self::Error> {
        unimplemented!("db_execute not implemented")
    }

    // --- Process Execution ---

    /// Executes a system command with arguments.
    ///
    /// - `cmd`: Command name.
    /// - `args`: Command-line arguments.
    /// - Returns: (exit code, stdout/stderr output).
    async fn exec(&self, cmd: &str, args: &[&str]) -> Result<(i32, Vec<u8>), Self::Error> {
        unimplemented!("exec not implemented")
    }

    // --- Message Queue / Pub-Sub ---

    /// Publishes a message to a topic in a message queue.
    async fn mq_publish(&self, topic: &str, data: &[u8]) -> Result<(), Self::Error> {
        unimplemented!("mq_publish not implemented")
    }

    /// Consumes a message from a topic in a message queue.
    async fn mq_consume(&self, topic: &str) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("mq_consume not implemented")
    }

    // --- IPC (Inter-Process Communication) ---

    /// Sends a message to another process over a named channel.
    async fn ipc_send(&self, channel: &str, data: &[u8]) -> Result<(), Self::Error> {
        unimplemented!("ipc_send not implemented")
    }

    /// Receives a message from another process over a named channel.
    async fn ipc_receive(&self, channel: &str) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("ipc_receive not implemented")
    }

    // --- Time & Scheduling ---

    /// Returns the current system time.
    fn now(&self) -> SystemTime {
        SystemTime::now()
    }

    /// Suspends execution for the specified duration.
    async fn sleep(&self, dur: Duration) {
        unimplemented!("sleep not implemented")
    }

    // --- Environment / Config ---

    /// Retrieves the value of an environment variable.
    fn get_env(&self, key: &str) -> Option<String> {
        unimplemented!("get_env not implemented")
    }

    /// Sets an environment variable.
    fn set_env(&self, key: &str, value: &str) {
        unimplemented!("set_env not implemented")
    }

    // --- Logging & Metrics ---

    /// Writes a log entry with a given severity level.
    fn log(&self, level: &str, msg: &str) {
        unimplemented!("log not implemented")
    }

    /// Records a numeric metric (e.g., counter, gauge, histogram).
    fn record_metric(&self, name: &str, value: f64) {
        unimplemented!("record_metric not implemented")
    }

    // --- Cryptography / Secrets ---

    /// Retrieves a secret value (e.g., API key) from secure storage.
    fn get_secret(&self, key: &str) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("get_secret not implemented")
    }

    /// Signs data using the backend's cryptographic key.
    fn sign(&self, data: &[u8]) -> Result<Vec<u8>, Self::Error> {
        unimplemented!("sign not implemented")
    }

    /// Verifies a digital signature.
    fn verify(&self, data: &[u8], sig: &[u8]) -> Result<bool, Self::Error> {
        unimplemented!("verify not implemented")
    }
}