tail_core 0.1.1

Core library for the Tail operating system
Documentation
// Copyright 2025, TAIL OS. All Rights Reserved.
//
// You must obtain a written license from and pay applicable license fees to TAIL OS
// before you may reproduce, modify, or distribute this software, or any work that
// includes all or part of this software.
//
// Free development licenses are available for evaluation, research, and non-commercial
// purposes, which may include access to the source code under these terms. Redistribution
// or commercial use without a license is strictly prohibited.
//
// This file may contain contributions from others. Please review this entire file for
// other proprietary rights or license notices, as well as the TAIL OS License Guide at
// https://tail-os.com/license-guide/ for more information.
//
// For licensing inquiries, visit https://tail-os.com or email license@tail-os.com.


#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrorKind {
    NotFound,
    PermissionDenied,
    ConnectionRefused,
    ConnectionReset,
    HostUnreachable,
    NetworkUnreachable,
    ConnectionAborted,
    NotConnected,
    AddrInUse,
    AddrNotAvailable,
    BrokenPipe,
    AlreadyExists,
    WouldBlock,
    InvalidInput,
    InvalidData,
    TimedOut,
    WriteZero,
    Interrupted,
    UnexpectedEof,
    Unsupported,
    OutOfMemory,
    ArgumentListTooLong,
    ReadFailed,
    ProcessCreationFailed,
    Other,
}

impl core::fmt::Display for ErrorKind {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        let s = match self {
            ErrorKind::NotFound => "NotFound",
            ErrorKind::PermissionDenied => "PermissionDenied",
            ErrorKind::ConnectionRefused => "ConnectionRefused",
            ErrorKind::ConnectionReset => "ConnectionReset",
            ErrorKind::HostUnreachable => "HostUnreachable",
            ErrorKind::NetworkUnreachable => "NetworkUnreachable",
            ErrorKind::ConnectionAborted => "ConnectionAborted",
            ErrorKind::NotConnected => "NotConnected",
            ErrorKind::AddrInUse => "AddrInUse",
            ErrorKind::AddrNotAvailable => "AddrNotAvailable",
            ErrorKind::BrokenPipe => "BrokenPipe",
            ErrorKind::AlreadyExists => "AlreadyExists",
            ErrorKind::WouldBlock => "WouldBlock",
            ErrorKind::InvalidInput => "InvalidInput",
            ErrorKind::InvalidData => "InvalidData",
            ErrorKind::TimedOut => "TimedOut",
            ErrorKind::WriteZero => "WriteZero",
            ErrorKind::Interrupted => "Interrupted",
            ErrorKind::UnexpectedEof => "UnexpectedEof",
            ErrorKind::Unsupported => "Unsupported",
            ErrorKind::OutOfMemory => "OutOfMemory",
            ErrorKind::ArgumentListTooLong => "ArgumentListTooLong",
            ErrorKind::ReadFailed => "ReadFailed",
            ErrorKind::ProcessCreationFailed => "ProcessCreationFailed",
            ErrorKind::Other => "Other",
        };
        crate::_kprint!("{}", s);
        Ok(())
    }
}

impl From<ErrorKind> for i64 {
    fn from(kind: ErrorKind) -> i64 {
        match kind {
            ErrorKind::NotFound => -1,
            ErrorKind::PermissionDenied => -2,
            ErrorKind::ConnectionRefused => -3,
            ErrorKind::ConnectionReset => -4,
            ErrorKind::HostUnreachable => -5,
            ErrorKind::NetworkUnreachable => -6,
            ErrorKind::ConnectionAborted => -7,
            ErrorKind::NotConnected => -8,
            ErrorKind::AddrInUse => -9,
            ErrorKind::AddrNotAvailable => -10,
            ErrorKind::BrokenPipe => -11,
            ErrorKind::AlreadyExists => -12,
            ErrorKind::WouldBlock => -13,
            ErrorKind::InvalidInput => -14,
            ErrorKind::InvalidData => -15,
            ErrorKind::TimedOut => -16,
            ErrorKind::WriteZero => -17,
            ErrorKind::Interrupted => -18,
            ErrorKind::UnexpectedEof => -19,
            ErrorKind::Unsupported => -20,
            ErrorKind::OutOfMemory => -21,
            ErrorKind::ArgumentListTooLong => -22,
            ErrorKind::ReadFailed => -23,
            ErrorKind::ProcessCreationFailed => -24,
            ErrorKind::Other => -25,
        }
    }
}

impl From<i64> for ErrorKind {
    fn from(value: i64) -> Self {
        match value {
            -1 => ErrorKind::NotFound,
            -2 => ErrorKind::PermissionDenied,
            -3 => ErrorKind::ConnectionRefused,
            -4 => ErrorKind::ConnectionReset,
            -5 => ErrorKind::HostUnreachable,
            -6 => ErrorKind::NetworkUnreachable,
            -7 => ErrorKind::ConnectionAborted,
            -8 => ErrorKind::NotConnected,
            -9 => ErrorKind::AddrInUse,
            -10 => ErrorKind::AddrNotAvailable,
            -11 => ErrorKind::BrokenPipe,
            -12 => ErrorKind::AlreadyExists,
            -13 => ErrorKind::WouldBlock,
            -14 => ErrorKind::InvalidInput,
            -15 => ErrorKind::InvalidData,
            -16 => ErrorKind::TimedOut,
            -17 => ErrorKind::WriteZero,
            -18 => ErrorKind::Interrupted,
            -19 => ErrorKind::UnexpectedEof,
            -20 => ErrorKind::Unsupported,
            -21 => ErrorKind::OutOfMemory,
            -22 => ErrorKind::ArgumentListTooLong,
            -23 => ErrorKind::ReadFailed,
            -24 => ErrorKind::ProcessCreationFailed,
            -25 => ErrorKind::Other,
            i64::MIN..=-26_i64 | 0_i64..=i64::MAX => todo!(),
        }
    }
}