doc changes
This commit is contained in:
parent
a4bacd53a2
commit
e7cad5b5a3
6 changed files with 87 additions and 31 deletions
|
@ -7,13 +7,13 @@ use servicepoint::{
|
|||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// Creates a new [SPBitVec] instance.
|
||||
/// Creates a new [DisplayBitVec] instance.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `size`: size in bits.
|
||||
///
|
||||
/// returns: [SPBitVec] with all bits set to false.
|
||||
/// returns: [DisplayBitVec] with all bits set to false.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
@ -23,9 +23,9 @@ pub unsafe extern "C" fn sp_bitvec_new(size: usize) -> NonNull<DisplayBitVec> {
|
|||
heap_move_nonnull(DisplayBitVec::repeat(false, size))
|
||||
}
|
||||
|
||||
/// Interpret the data as a series of bits and load then into a new [SPBitVec] instance.
|
||||
/// Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
|
||||
///
|
||||
/// returns: [SPBitVec] instance containing data.
|
||||
/// returns: [DisplayBitVec] instance containing data.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_load(
|
||||
data: ByteSlice,
|
||||
|
@ -34,7 +34,7 @@ pub unsafe extern "C" fn sp_bitvec_load(
|
|||
heap_move_nonnull(DisplayBitVec::from_slice(data))
|
||||
}
|
||||
|
||||
/// Clones a [SPBitVec].
|
||||
/// Clones a [DisplayBitVec].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_clone(
|
||||
bit_vec: NonNull<DisplayBitVec>,
|
||||
|
@ -42,13 +42,13 @@ pub unsafe extern "C" fn sp_bitvec_clone(
|
|||
unsafe { heap_clone(bit_vec) }
|
||||
}
|
||||
|
||||
/// Deallocates a [SPBitVec].
|
||||
/// Deallocates a [DisplayBitVec].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_bitvec_free(bit_vec: NonNull<DisplayBitVec>) {
|
||||
unsafe { heap_drop(bit_vec) }
|
||||
}
|
||||
|
||||
/// Gets the value of a bit from the [SPBitVec].
|
||||
/// Gets the value of a bit from the [DisplayBitVec].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -68,7 +68,7 @@ pub unsafe extern "C" fn sp_bitvec_get(
|
|||
unsafe { *bit_vec.as_ref().get(index).unwrap() }
|
||||
}
|
||||
|
||||
/// Sets the value of a bit in the [SPBitVec].
|
||||
/// Sets the value of a bit in the [DisplayBitVec].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -88,7 +88,7 @@ pub unsafe extern "C" fn sp_bitvec_set(
|
|||
unsafe { (*bit_vec.as_ptr()).set(index, value) }
|
||||
}
|
||||
|
||||
/// Sets the value of all bits in the [SPBitVec].
|
||||
/// Sets the value of all bits in the [DisplayBitVec].
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -102,7 +102,7 @@ pub unsafe extern "C" fn sp_bitvec_fill(
|
|||
unsafe { (*bit_vec.as_ptr()).fill(value) }
|
||||
}
|
||||
|
||||
/// Gets the length of the [SPBitVec] in bits.
|
||||
/// Gets the length of the [DisplayBitVec] in bits.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
|
@ -126,7 +126,7 @@ pub unsafe extern "C" fn sp_bitvec_is_empty(
|
|||
unsafe { bit_vec.as_ref().is_empty() }
|
||||
}
|
||||
|
||||
/// Gets an unsafe reference to the data of the [SPBitVec] instance.
|
||||
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
||||
///
|
||||
/// The returned memory is valid for the lifetime of the bitvec.
|
||||
///
|
||||
|
@ -142,7 +142,7 @@ pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
|
|||
|
||||
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
||||
///
|
||||
/// The provided [SPBitVec] gets consumed.
|
||||
/// The provided [DisplayBitVec] gets consumed.
|
||||
///
|
||||
/// Returns NULL in case of an error.
|
||||
#[no_mangle]
|
||||
|
|
|
@ -26,7 +26,7 @@ pub unsafe extern "C" fn sp_cmd_bitmap_new(
|
|||
/// Move the provided [Bitmap] into a new [BitmapCommand],
|
||||
/// leaving other fields as their default values.
|
||||
///
|
||||
/// Rust equivalent: [`<BitmapCommand as From<Bitmap>>::from`]
|
||||
/// Rust equivalent: `BitmapCommand::from(bitmap)`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_bitmap_from_bitmap(
|
||||
bitmap: NonNull<Bitmap>,
|
||||
|
|
|
@ -46,7 +46,9 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_free(
|
|||
unsafe { heap_drop(command) }
|
||||
}
|
||||
|
||||
/// Moves the provided bitmap to be contained in the command.
|
||||
/// Moves the provided bitmap into the provided command.
|
||||
///
|
||||
/// This drops the previously contained [Cp437Grid].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_set(
|
||||
mut command: NonNull<Cp437GridCommand>,
|
||||
|
@ -64,6 +66,9 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_get(
|
|||
&mut unsafe { command.as_mut() }.grid
|
||||
}
|
||||
|
||||
/// Gets the origin field of the [Cp437GridCommand].
|
||||
///
|
||||
/// Rust equivalent: `cp437_command.origin`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_get_origin(
|
||||
command: NonNull<Cp437GridCommand>,
|
||||
|
@ -77,6 +82,10 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_get_origin(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Sets the origin field of the [Cp437GridCommand].
|
||||
///
|
||||
/// Rust equivalent: `cp437_command.origin = Origin::new(origin_x, origin_y)`
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_set_origin(
|
||||
mut command: NonNull<Cp437GridCommand>,
|
||||
|
|
|
@ -8,7 +8,9 @@ use servicepoint::{
|
|||
};
|
||||
use std::ptr::{null_mut, NonNull};
|
||||
|
||||
/// Pointer to one of the available command structs.
|
||||
#[repr(C)]
|
||||
#[allow(missing_docs)]
|
||||
pub union CommandUnion {
|
||||
pub null: *mut u8,
|
||||
pub bitmap: NonNull<BitmapCommand>,
|
||||
|
@ -24,7 +26,11 @@ pub union CommandUnion {
|
|||
pub fade_out: NonNull<FadeOutCommand>,
|
||||
}
|
||||
|
||||
/// Specifies the kind of command struct.
|
||||
///
|
||||
/// This is _not_ equivalent to the [servicepoint::CommandCode]s.
|
||||
#[repr(u8)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum CommandTag {
|
||||
Invalid = 0,
|
||||
Bitmap,
|
||||
|
@ -39,6 +45,11 @@ pub enum CommandTag {
|
|||
BitmapLegacy,
|
||||
}
|
||||
|
||||
/// This struct represents a pointer to one of the possible command structs.
|
||||
///
|
||||
/// Only ever access `data` with the correct data type as specified by `tag`!
|
||||
///
|
||||
/// Rust equivalent: [TypedCommand].
|
||||
#[repr(C)]
|
||||
pub struct SPCommand {
|
||||
/// Specifies which kind of command struct is contained in `data`
|
||||
|
@ -59,7 +70,7 @@ impl SPCommand {
|
|||
/// The packet is deallocated in the process.
|
||||
///
|
||||
/// Returns: pointer to new [TypedCommand] instance or NULL if parsing failed.
|
||||
/// #[no_mangle]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_generic_try_from_packet(
|
||||
packet: NonNull<Packet>,
|
||||
) -> *mut SPCommand {
|
||||
|
|
|
@ -62,7 +62,7 @@ pub unsafe extern "C" fn sp_udp_send_packet(
|
|||
unsafe { connection.as_ref().send(&Vec::from(packet)) }.is_ok()
|
||||
}
|
||||
|
||||
/// Sends a [TypedCommand] to the display using the [UdpSocket].
|
||||
/// Sends a [SPCommand] to the display using the [UdpSocket].
|
||||
///
|
||||
/// The passed `command` gets consumed.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue