forked from ROMEO/obsw
rust lib
This commit is contained in:
43
mission_rust/src/lib.rs
Normal file
43
mission_rust/src/lib.rs
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user