eldenring 0.14.0

Structures, bindings, and utilities for From Software's title Elden Ring
Documentation
use std::fmt::Debug;
use std::io;

#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
/// Determines the starting position for passed-in offsets.
pub enum DLFileSeekDirection {
    /// Seek from start of stream.
    Head = 0x0,
    /// Seek from current position.
    Current = 0x1,
    /// Seek from end of stream.
    Tail = 0x2,
}

#[repr(i32)]
pub enum DLIOResult {
    DirNotEmpty = -17,
    OutOfMemory = -13,
    DiskFull = -12,
    NotStreamed = -9,
    AlreadyOpen = -6,
    IsNotOpen = -5,
    NotFound = -4,
    AccessDenied = -3,
    OperationUnsupported = -2,
    Invalid = -1,
    Success = 0,
    NoMoreFiles = 1,
}

impl DLIOResult {
    /// Converts this into an equivalent [io::Result].
    pub fn to_io_result(&self) -> io::Result<()> {
        use io::ErrorKind::*;
        let kind = match self {
            DLIOResult::DirNotEmpty => DirectoryNotEmpty,
            DLIOResult::OutOfMemory => OutOfMemory,
            DLIOResult::DiskFull => StorageFull,
            DLIOResult::IsNotOpen => BrokenPipe,
            DLIOResult::NotFound => NotFound,
            DLIOResult::AccessDenied => PermissionDenied,
            DLIOResult::OperationUnsupported => Unsupported,
            DLIOResult::Invalid => InvalidInput,
            // The following mappings are guesses as to the intended semantics
            DLIOResult::AlreadyOpen => PermissionDenied,
            DLIOResult::NotStreamed => NotConnected,
            _ => return Ok(()),
        };
        Err(io::Error::from(kind))
    }
}

bitflags::bitflags! {
    /// A bit flag that indicates the mode with which to open a file.
    #[repr(C)]
    #[derive(Debug, Clone, Copy)]
    pub struct OpenFileMode: u32 {
        const ReadOnly       = 0b00000001;
        const Write          = 0b00000010;
        const Append         = 0b00000100;
        const DetailedErrors = 0b00001000;
        const AsyncIo        = 0b00010000;
        const Unk5           = 0b00100000;
        const NoSharing      = 0b01000000;
        const Unk7           = 0b10000000;
    }
}