Skip to main content

irid_std/
lib.rs

1#![no_std]
2#![feature(pattern)]
3#![feature(negative_impls)]
4
5extern crate alloc;
6
7#[cfg(not(target_os = "none"))]
8extern crate std;
9
10#[cfg(target_os = "none")]
11pub mod fs;
12#[cfg(target_os = "none")]
13pub mod io;
14#[cfg(target_os = "none")]
15pub mod process;
16#[cfg(target_os = "none")]
17pub mod thread;
18#[cfg(target_os = "none")]
19pub mod os;
20#[cfg(target_os = "none")]
21pub mod sync;
22#[cfg(target_os = "none")]
23pub mod env;
24#[cfg(target_os = "none")]
25pub mod time;
26#[cfg(target_os = "none")]
27pub mod path;
28#[cfg(target_os = "none")]
29pub mod ffi;
30#[cfg(target_os = "none")]
31mod macros;
32#[cfg(target_os = "none")]
33mod panic;
34#[cfg(target_os = "none")]
35mod allocator;
36#[cfg(target_os = "none")]
37pub(crate) mod pagevec;
38pub mod start;
39
40use core::mem::MaybeUninit;
41use core::ptr::slice_from_raw_parts_mut;
42#[cfg(not(target_os = "none"))]
43pub use std::fs;
44#[cfg(not(target_os = "none"))]
45pub use std::io;
46#[cfg(not(target_os = "none"))]
47pub use std::process;
48#[cfg(not(target_os = "none"))]
49pub use std::thread;
50#[cfg(not(target_os = "none"))]
51pub use std::os;
52#[cfg(not(target_os = "none"))]
53pub use std::sync;
54#[cfg(not(target_os = "none"))]
55pub use std::env;
56#[cfg(not(target_os = "none"))]
57pub use std::time;
58#[cfg(not(target_os = "none"))]
59pub use std::path;
60#[cfg(not(target_os = "none"))]
61pub use std::ffi;
62#[cfg(not(target_os = "none"))]
63pub use std::{print, println, eprintln, eprint};
64
65
66use crate::fs::File;
67
68fn read_value<T>(file: &mut File) -> Result<T, io::Error> {
69    use alloc::vec;
70    use crate::io::Read;
71    
72    let mut bytes = vec![0; size_of::<T>()];
73    file.read_exact(&mut bytes)?;
74
75    unsafe {
76        let mut value: MaybeUninit<T> = MaybeUninit::uninit();
77
78        let slice = slice_from_raw_parts_mut(&mut value as *mut MaybeUninit<T> as *mut u8, size_of::<T>()).as_mut_unchecked();
79        slice.copy_from_slice(bytes.as_slice());
80
81        Ok(value.assume_init())
82    }
83}
84