# drawable_string.rs - source
Source of the Rust file `arduboy-rust\src\library\arduboyfx\drawable_string.rs`.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53

    use core::ffi::{c_char, c_uchar, c_ulong};
    use crate::library::progmem::Pstring;

    pub trait DrawableString
    where
        Self: Sized,
    {
        fn draw(self);
    }
    impl DrawableString for &[u8] {
        fn draw(self) {
            unsafe {
                arduboyfx_draw_string(self as *const [u8] as *const i8);
            }
        }
    }
    impl DrawableString for &str {
        fn draw(self) {
            unsafe {
                arduboyfx_draw_string(self.as_bytes() as *const [u8] as *const i8);
            }
        }
    }
    impl<const N: usize> DrawableString for crate::heapless::String<N> {
        fn draw(self) {
            unsafe {
                arduboyfx_draw_string(self.as_bytes() as *const [u8] as *const i8);
            }
        }
    }
    impl DrawableString for Pstring {
        fn draw(self) {
            unsafe {
                arduboyfx_draw_string_buffer(self.pointer as *const u8);
            }
        }
    }
    impl DrawableString for u32 {
        fn draw(self) {
            unsafe {
                arduboyfx_draw_string_fx(self);
            }
        }
    }

    extern "C" {
        #[link_name = "arduboyfx_draw_string_fx"]
        fn arduboyfx_draw_string_fx(address: c_ulong);
        #[link_name = "arduboyfx_draw_string_buffer"]
        fn arduboyfx_draw_string_buffer(buffer: *const c_uchar);
        #[link_name = "arduboyfx_draw_string"]
        fn arduboyfx_draw_string(cstr: *const c_char);
    }