This commit is contained in:
2023-10-27 17:02:48 +02:00
parent a4bcbf64cc
commit e0527bf91b
8 changed files with 96 additions and 1 deletions

43
mission_rust/src/lib.rs Normal file
View File

@ -0,0 +1,43 @@
#![no_std]
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
extern "C" {
pub fn outbyte(c: cty::c_char);
}
#[no_mangle]
pub extern "C" fn rust_main(i: cty::c_double) {
mission(i);
}
struct Outbytes {}
use core::fmt::{Error, Write};
impl Write for Outbytes {
fn write_str(&mut self, s: &str) -> Result<(), Error> {
for c in s.as_bytes() {
unsafe {
outbyte(*c);
}
}
Ok(())
}
}
fn mission(i: f64) {
for byte in "abcd\n".bytes() {
unsafe {
outbyte(byte);
}
}
let mut stdout = Outbytes {};
let _ok = writeln!(&mut stdout, "I got {}!", i);
}