servicepoint_binding_c 0.15.0

C bindings for the servicepoint crate.
Documentation
use crate::{containers::ByteSlice, macros::wrap};
use servicepoint::{
    Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
};
use std::ptr::NonNull;

wrap! {
    Cp437Grid {
    derives: crate::containers::derive_container, crate::containers::derive_grid[u8];
    functions:
        /// Creates a new [Cp437Grid] with the specified dimensions.
        ///
        /// returns: [Cp437Grid] initialized to 0.
        fn new(width: val usize, height: val usize) -> move NonNull<Cp437Grid> {
            Cp437Grid::new(width, height)
        };

        /// Loads a [Cp437Grid] with the specified dimensions from the provided data.
        fn load(width: val usize, height: val usize, data: slice ByteSlice) -> move_some *mut Cp437Grid {
            Cp437Grid::load(width, height, data)
        };

    methods:
        /// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
        ///
        /// The provided [Cp437Grid] gets consumed.
        ///
        /// Returns NULL in case of an error.
        fn try_into_packet(move grid, x: val usize, y: val usize) -> move_ok *mut Packet {
            Packet::try_from(Cp437GridCommand {
                grid,
                origin: Origin::new(x, y),
            })
        };

        /// Gets an unsafe reference to the data of the grid.
        ///
        /// The returned memory is valid for the lifetime of the instance.
        fn data_ref_mut(mut instance) -> slice ByteSlice;
    }
}