rename function to ...try to indicate possible null return

This commit is contained in:
Vinzenz Schroeter 2025-06-22 12:59:13 +02:00
parent b4730ffdf3
commit 7a836783e1
9 changed files with 82 additions and 83 deletions

View file

@ -717,20 +717,6 @@ size_t sp_bitmap_height(struct Bitmap */*notnull*/ instance);
*/
BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
/**
* Creates a [BitmapCommand] and immediately turns that into a [Packet].
*
* The provided [Bitmap] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `bitmap` module.
*/
struct Packet *sp_bitmap_into_packet(struct Bitmap */*notnull*/ bitmap,
size_t x,
size_t y,
CompressionCode compression);
/**
* Loads a [Bitmap] with the specified dimensions from the provided data.
*
@ -806,6 +792,20 @@ void sp_bitmap_set(struct Bitmap */*notnull*/ instance,
size_t y,
bool value);
/**
* Creates a [BitmapCommand] and immediately turns that into a [Packet].
*
* The provided [Bitmap] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `bitmap` module.
*/
struct Packet *sp_bitmap_try_into_packet(struct Bitmap */*notnull*/ bitmap,
size_t x,
size_t y,
CompressionCode compression);
/**
* Calls method [`servicepoint::Bitmap::width`].
*
@ -1089,19 +1089,6 @@ Brightness sp_brightnessgrid_get(BrightnessGrid */*notnull*/ instance,
*/
size_t sp_brightnessgrid_height(BrightnessGrid */*notnull*/ instance);
/**
* Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
*
* The provided [BrightnessGrid] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `brightnessgrid` module.
*/
struct Packet *sp_brightnessgrid_into_packet(BrightnessGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [BrightnessGrid] with the specified dimensions from the provided data.
*
@ -1159,6 +1146,19 @@ void sp_brightnessgrid_set(BrightnessGrid */*notnull*/ instance,
size_t y,
Brightness value);
/**
* Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
*
* The provided [BrightnessGrid] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `brightnessgrid` module.
*/
struct Packet *sp_brightnessgrid_try_into_packet(BrightnessGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Calls method [`servicepoint::BrightnessGrid::width`].
*
@ -1303,19 +1303,6 @@ uint32_t sp_chargrid_get(CharGrid */*notnull*/ instance, size_t x, size_t y);
*/
size_t sp_chargrid_height(CharGrid */*notnull*/ instance);
/**
* Creates a [CharGridCommand] and immediately turns that into a [Packet].
*
* The provided [CharGrid] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `chargrid` module.
*/
struct Packet *sp_chargrid_into_packet(CharGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [CharGrid] with the specified dimensions from the provided data.
*
@ -1367,6 +1354,19 @@ void sp_chargrid_set(CharGrid */*notnull*/ instance,
size_t y,
uint32_t value);
/**
* Creates a [CharGridCommand] and immediately turns that into a [Packet].
*
* The provided [CharGrid] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `chargrid` module.
*/
struct Packet *sp_chargrid_try_into_packet(CharGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Calls method [`servicepoint::CharGrid::width`].
*
@ -1622,19 +1622,6 @@ uint8_t sp_cp437grid_get(Cp437Grid */*notnull*/ instance, size_t x, size_t y);
*/
size_t sp_cp437grid_height(Cp437Grid */*notnull*/ instance);
/**
* Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
*
* The provided [Cp437Grid] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `cp437grid` module.
*/
struct Packet *sp_cp437grid_into_packet(Cp437Grid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [Cp437Grid] with the specified dimensions from the provided data.
*
@ -1674,6 +1661,19 @@ void sp_cp437grid_set(Cp437Grid */*notnull*/ instance,
size_t y,
uint8_t value);
/**
* Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
*
* The provided [Cp437Grid] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `cp437grid` module.
*/
struct Packet *sp_cp437grid_try_into_packet(Cp437Grid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Calls method [`servicepoint::Cp437Grid::width`].
*
@ -1801,20 +1801,6 @@ void sp_displaybitvec_free(BitVec */*notnull*/ instance);
*/
bool sp_displaybitvec_get(BitVec */*notnull*/ instance, size_t index);
/**
* Creates a [BitVecCommand] and immediately turns that into a [Packet].
*
* The provided [DisplayBitVec] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `displaybitvec` module.
*/
struct Packet *sp_displaybitvec_into_packet(BitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
/**
* Calls method [`servicepoint::DisplayBitVec::is_empty`].
*
@ -1879,6 +1865,20 @@ void sp_displaybitvec_set(BitVec */*notnull*/ instance,
size_t index,
bool value);
/**
* Creates a [BitVecCommand] and immediately turns that into a [Packet].
*
* The provided [DisplayBitVec] gets consumed.
*
* Returns NULL in case of an error.
*
* This function is part of the `displaybitvec` module.
*/
struct Packet *sp_displaybitvec_try_into_packet(BitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
/**
* Call this function at the beginning of main to enable rust logging controlled by the
* `RUST_LOG` environment variable. See [env_logger](https://docs.rs/env_logger/latest/env_logger/).

View file

@ -2,7 +2,6 @@ use crate::{
commands::wrap_command, macros::wrap_functions, mem::heap_move_nonnull,
};
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
use std::ptr::NonNull;
macro_rules! wrap_cc_only {
($(#[$meta:meta])* $command:ident) => {
@ -13,7 +12,7 @@ macro_rules! wrap_cc_only {
$(#[$meta])*
///
#[doc = " Returns: a new [`" [< $command Command >] "`] instance."]
fn new() -> NonNull<[< $command Command >]> {
fn new() -> ::core::ptr::NonNull<[< $command Command >]> {
heap_move_nonnull([< $command Command >])
}
);

View file

@ -20,9 +20,9 @@ macro_rules! wrap_origin_accessors {
$crate::macros::wrap_functions!(associate $object_type;
#[doc = " Reads the origin field of the [`" $object_type "`]."]
fn get_origin(
command: NonNull<$object_type>,
origin_x: NonNull<usize>,
origin_y: NonNull<usize>,
command: ::core::ptr::NonNull<$object_type>,
origin_x: ::core::ptr::NonNull<usize>,
origin_y: ::core::ptr::NonNull<usize>,
) {
unsafe {
let origin = &command.as_ref().origin;
@ -33,7 +33,7 @@ macro_rules! wrap_origin_accessors {
#[doc = " Overwrites the origin field of the [`" $object_type "`]."]
fn set_origin(
command: NonNull<$object_type>,
command: ::core::ptr::NonNull<$object_type>,
origin_x: usize,
origin_y: usize,
) {
@ -72,7 +72,7 @@ macro_rules! derive_command_into_packet {
///
/// Returns: NULL or a [Packet] containing the command.
fn try_into_packet(
command: NonNull<$command_type>,
command: ::core::ptr::NonNull<$command_type>,
) -> *mut ::servicepoint::Packet {
$crate::mem::heap_move_ok(unsafe { $crate::mem::heap_remove(command) }.try_into())
}

View file

@ -89,7 +89,7 @@ wrap_functions!(bitmap;
/// The provided [Bitmap] gets consumed.
///
/// Returns NULL in case of an error.
fn into_packet(
fn try_into_packet(
bitmap: NonNull<Bitmap>,
x: usize,
y: usize,

View file

@ -40,7 +40,7 @@ wrap_functions!(associate DisplayBitVec;
/// The provided [DisplayBitVec] gets consumed.
///
/// Returns NULL in case of an error.
fn into_packet(
fn try_into_packet(
bitvec: NonNull<DisplayBitVec>,
offset: usize,
operation: BinaryOperation,

View file

@ -59,7 +59,7 @@ wrap_functions!(associate BrightnessGrid;
/// The provided [BrightnessGrid] gets consumed.
///
/// Returns NULL in case of an error.
fn into_packet(
fn try_into_packet(
grid: NonNull<BrightnessGrid>,
x: usize,
y: usize,

View file

@ -47,7 +47,7 @@ wrap_functions!(associate CharGrid;
/// The provided [CharGrid] gets consumed.
///
/// Returns NULL in case of an error.
fn into_packet(
fn try_into_packet(
grid: NonNull<CharGrid>,
x: usize,
y: usize,

View file

@ -37,7 +37,7 @@ wrap_functions!(cp437grid;
/// The provided [Cp437Grid] gets consumed.
///
/// Returns NULL in case of an error.
fn into_packet(
fn try_into_packet(
grid: NonNull<Cp437Grid>,
x: usize,
y: usize,

View file

@ -3,7 +3,7 @@ macro_rules! derive_free {
::paste::paste! {
$crate::macros::wrap_functions!([< $typ:lower >];
#[doc = "Deallocates a [`" $typ "`] instance."]
fn free(instance: NonNull<$typ>) {
fn free(instance: ::core::ptr::NonNull<$typ>) {
unsafe { $crate::mem::heap_drop(instance) }
}
);
@ -16,7 +16,7 @@ macro_rules! derive_clone {
::paste::paste! {
$crate::macros::wrap_functions!([< $typ:lower >];
#[doc = "Clones a [`" $typ "`] instance."]
fn clone(instance: NonNull<$typ>) -> NonNull<$typ> {
fn clone(instance: ::core::ptr::NonNull<$typ>) -> ::core::ptr::NonNull<$typ> {
unsafe { $crate::mem::heap_clone(instance) }
}
);
@ -58,7 +58,7 @@ macro_rules! wrap_methods {
#[doc = ""]
$(#[$meta])*
fn $function(
instance: NonNull<$object_type>,
instance: ::core::ptr::NonNull<$object_type>,
$($param_name: $param_type),*
) $(-> $return_type)? {
let instance = unsafe { $crate::macros:: [< nonnull_as_ $ref_or_mut >] !(instance) };
@ -192,7 +192,7 @@ macro_rules! wrap_fields {
)*)?
fn [<set _ $prop_name>](
instance: ::core::ptr::NonNull<$object_type>,
value: NonNull<$prop_type>,
value: ::core::ptr::NonNull<$prop_type>,
) {
let instance = unsafe { $crate::macros::nonnull_as_mut!(instance) };
let value = unsafe { $crate::mem::heap_remove(value) };