Skip to main content

irid_std/
lib.rs

1#![no_std]
2#![cfg_attr(target_os = "none", feature(pattern))]
3#![cfg_attr(target_os = "none", 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;
38#[cfg(target_os = "none")]
39pub mod start;
40#[cfg(not(target_os = "none"))]
41mod start;
42
43use core::mem::MaybeUninit;
44use core::ptr::slice_from_raw_parts_mut;
45#[cfg(not(target_os = "none"))]
46pub use std::fs;
47#[cfg(not(target_os = "none"))]
48pub use std::io;
49#[cfg(not(target_os = "none"))]
50pub use std::process;
51#[cfg(not(target_os = "none"))]
52pub use std::thread;
53#[cfg(not(target_os = "none"))]
54pub use std::os;
55#[cfg(not(target_os = "none"))]
56pub use std::sync;
57#[cfg(not(target_os = "none"))]
58pub use std::env;
59#[cfg(not(target_os = "none"))]
60pub use std::time;
61#[cfg(not(target_os = "none"))]
62pub use std::path;
63#[cfg(not(target_os = "none"))]
64pub use std::ffi;
65#[cfg(not(target_os = "none"))]
66pub use std::{print, println, eprintln, eprint};
67
68use crate::fs::File;
69
70fn read_value<T>(file: &mut File) -> Result<T, io::Error> {
71    use alloc::vec;
72    use crate::io::Read;
73    
74    let mut bytes = vec![0; size_of::<T>()];
75    file.read_exact(&mut bytes)?;
76
77    unsafe {
78        let mut value: MaybeUninit<T> = MaybeUninit::uninit();
79
80        let slice = slice_from_raw_parts_mut(&mut value as *mut MaybeUninit<T> as *mut u8, size_of::<T>()).as_mut_unchecked();
81        slice.copy_from_slice(bytes.as_slice());
82
83        Ok(value.assume_init())
84    }
85}
86