@@ -491,7 +491,35 @@ impl Display for SequenceExceedsBoundsError {
491491}
492492/// Implements the `std::error::Error` trait for the `SequenceExceedsBoundsError` struct.
493493impl std:: error:: Error for SequenceExceedsBoundsError { }
494-
494+ /// Macro to provide default implementations for the `SequenceAlloc` trait for primitive types.
495+ ///
496+ /// This macro generates an implementation of the `SequenceAlloc` trait for a given primitive type.
497+ /// It defines three extern "C" functions (`$init_func`, `$fini_func`, and `$copy_func`) that are
498+ /// linked from the "rosidl_runtime_c" library and used to initialize, finalize, and copy sequences
499+ /// of the specified type.
500+ ///
501+ /// The `sequence_init` function allocates space for the sequence and sets its size and capacity.
502+ /// If the sequence's data pointer is null, it calls `$init_func` to allocate memory. Otherwise,
503+ /// it writes zero bytes to the existing memory region.
504+ ///
505+ /// The `sequence_fini` function finalizes the sequence by calling `$fini_func`.
506+ ///
507+ /// The `sequence_copy` function copies the contents of one sequence to another by calling
508+ /// `$copy_func`.
509+ ///
510+ /// # Safety
511+ ///
512+ /// The implementations of `sequence_init`, `sequence_fini`, and `sequence_copy` are marked as
513+ /// `unsafe` because they call the corresponding extern "C" functions, which may have undefined
514+ /// behavior if their preconditions are not met. However, the macro assumes that there are no
515+ /// special preconditions for these functions.
516+ ///
517+ /// # Arguments
518+ ///
519+ /// * `$rust_type:ty` - The Rust type for which the `SequenceAlloc` trait should be implemented.
520+ /// * `$init_func:ident` - The name of the extern "C" function used to initialize a sequence.
521+ /// * `$fini_func:ident` - The name of the extern "C" function used to finalize a sequence.
522+ /// * `$copy_func:ident` - The name of the extern "C" function used to copy a sequence.
495523macro_rules! impl_sequence_alloc_for_primitive_type {
496524 ( $rust_type: ty, $init_func: ident, $fini_func: ident, $copy_func: ident) => {
497525 #[ link( name = "rosidl_runtime_c" ) ]
0 commit comments