diff --git a/Cargo.lock b/Cargo.lock index 67e927755..ae3d1bab5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -719,6 +719,7 @@ dependencies = [ name = "iceoryx2-ffi-macros" version = "0.5.0" dependencies = [ + "iceoryx2-bb-elementary", "proc-macro2", "quote", "syn 2.0.79", diff --git a/iceoryx2-bb/derive-macros/src/lib.rs b/iceoryx2-bb/derive-macros/src/lib.rs index c9b21a46f..fcf1b773e 100644 --- a/iceoryx2-bb/derive-macros/src/lib.rs +++ b/iceoryx2-bb/derive-macros/src/lib.rs @@ -15,9 +15,8 @@ extern crate proc_macro; use proc_macro::TokenStream; -use proc_macro2::Literal; use quote::quote; -use syn::{parse_macro_input, Data, DeriveInput, Expr, ExprLit, Fields, Lit}; +use syn::{parse_macro_input, Data, DeriveInput, Fields}; /// Implements the [`iceoryx2_bb_elementary::placement_default::PlacementDefault`] trait when all /// fields of the struct implement it. @@ -99,124 +98,3 @@ pub fn placement_default_derive(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } - -/// Implements the [`iceoryx2_bb_elementary::AsStringLiteral`] trait for enums to provide a string representation of each enum variant. -/// -/// The string representation can be customized using the `CustomString` attribute, otherwise it will -/// convert the variant name to lowercase and replace underscores with spaces. -/// -/// # Example -/// ``` -/// use iceoryx2_bb_derive_macros::StringLiteral; -/// use iceoryx2_bb_elementary::AsStringLiteral; -/// -/// #[derive(StringLiteral)] -/// enum MyEnum { -/// #[CustomString = "custom variant one"] -/// VariantOne, -/// VariantTwo, -/// } -/// -/// let v1 = MyEnum::VariantOne; -/// assert_eq!(v1.as_str_literal(), "custom variant one"); -/// -/// let v2 = MyEnum::VariantTwo; -/// assert_eq!(v2.as_str_literal(), "variant two"); -/// ``` -#[proc_macro_derive(StringLiteral, attributes(CustomString))] -pub fn string_literal_derive(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - let name = &input.ident; - let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl(); - - // Generate implementation converting enums to a string representation - let as_string_literal_impl = match input.data { - Data::Enum(ref data_enum) => { - let enum_to_string_mapping = data_enum.variants.iter().map(|variant| { - let enum_name = &variant.ident; - let enum_string_literal = variant - .attrs - .iter() - .find_map(|attr| { - if !attr.path().is_ident("CustomString") { - return None; - } - // Get the value of CustomString as a string literal - match attr.meta.require_name_value() { - Ok(meta) => match &meta.value { - Expr::Lit(ExprLit { - lit: Lit::Str(lit), .. - }) => Some(Literal::string(&lit.value())), - _ => None, - }, - _ => None, - } - }) - .unwrap_or_else(|| { - // If no CustomString, generates default string literal in the form - // MyEnum::MyVariantName => 'my variant name' - let enum_string_literal = enum_name - .to_string() - .chars() - .fold(String::new(), |mut acc, c| { - if c.is_uppercase() && !acc.is_empty() { - acc.push('_'); - } - acc.push(c); - acc - }) - .chars() - .map(|c| match c { - '_' => ' ', - c => c.to_ascii_lowercase(), - }) - .collect::(); - Literal::string(&enum_string_literal) - }); - - // Maps each enum variant to its string representation - match &variant.fields { - Fields::Unit => { - quote! { - Self::#enum_name => #enum_string_literal - } - } - Fields::Unnamed(_) => { - quote! { - Self::#enum_name(..) => #enum_string_literal - } - } - Fields::Named(_) => { - quote! { - Self::#enum_name{..} => #enum_string_literal - } - } - } - }); - - // Generate the mapping for the enum variant - quote! { - fn as_str_literal(&self) -> &'static str { - match self { - #(#enum_to_string_mapping,)* - } - } - } - } - _ => { - // Does not work for non-enum types - let err = - syn::Error::new_spanned(&input, "AsStringLiteral can only be derived for enums"); - return err.to_compile_error().into(); - } - }; - - // Implement the trait with the generated implementation - let expanded = quote! { - impl #impl_generics AsStringLiteral for #name #type_generics #where_clause { - #as_string_literal_impl - } - }; - - TokenStream::from(expanded) -} diff --git a/iceoryx2-bb/elementary/src/as_string_literal.rs b/iceoryx2-bb/elementary/src/as_cstr.rs similarity index 53% rename from iceoryx2-bb/elementary/src/as_string_literal.rs rename to iceoryx2-bb/elementary/src/as_cstr.rs index 861882067..5419022c6 100644 --- a/iceoryx2-bb/elementary/src/as_string_literal.rs +++ b/iceoryx2-bb/elementary/src/as_cstr.rs @@ -10,6 +10,17 @@ // // SPDX-License-Identifier: Apache-2.0 OR MIT -pub trait AsStringLiteral { - fn as_str_literal(&self) -> &'static str; +use std::ffi::CStr; + +/// Trait for types that can be represented as a C-style string. +/// +/// This trait provides a method to obtain a reference to a static C-style string +/// representation of the implementing type. +/// +/// # Safety +/// +/// Implementations of this trait must ensure that the returned `CStr` is valid +/// and remains valid for the entire lifetime of the program. +pub trait AsCStr { + fn as_const_cstr(&self) -> &'static CStr; } diff --git a/iceoryx2-bb/elementary/src/lib.rs b/iceoryx2-bb/elementary/src/lib.rs index 84e058925..05b0735d9 100644 --- a/iceoryx2-bb/elementary/src/lib.rs +++ b/iceoryx2-bb/elementary/src/lib.rs @@ -15,8 +15,8 @@ #[macro_use] pub mod enum_gen; -mod as_string_literal; -pub use as_string_literal::*; +mod as_cstr; +pub use as_cstr::*; pub mod alignment; pub mod allocator; diff --git a/iceoryx2-bb/testing/src/assert.rs b/iceoryx2-bb/testing/src/assert.rs index 8417178c4..184e1602e 100644 --- a/iceoryx2-bb/testing/src/assert.rs +++ b/iceoryx2-bb/testing/src/assert.rs @@ -197,7 +197,7 @@ macro_rules! assert_that { } } if does_contain { - assert_that!(message_contains_match $lhs, core::stringify!($predicate)); + assert_that!(message_not_contains_match $lhs, core::stringify!($predicate)); } } }; @@ -274,6 +274,15 @@ macro_rules! assert_that { assert_that![color_end] ); }; + [message_not_contains_match $lhs:expr, $predicate:expr] => { + core::panic!( + "assertion failed: {}expr: {} contains element matching predicate: {}{}", + assert_that![color_start], + core::stringify!($lhs), + $predicate, + assert_that![color_end] + ); + }; [message_property $lhs:expr, $lval:expr, $property:expr, $rhs:expr] => { core::panic!( "assertion failed: {}expr: {}.{} == {}; value: {} == {}{}", diff --git a/iceoryx2-ffi/ffi-macros/Cargo.toml b/iceoryx2-ffi/ffi-macros/Cargo.toml index a8fc18821..9c5baf6d0 100644 --- a/iceoryx2-ffi/ffi-macros/Cargo.toml +++ b/iceoryx2-ffi/ffi-macros/Cargo.toml @@ -18,3 +18,4 @@ proc-macro = true proc-macro2 = { workspace = true } quote = { workspace = true } syn = { workspace = true } +iceoryx2-bb-elementary = { workspace = true } diff --git a/iceoryx2-ffi/ffi-macros/src/lib.rs b/iceoryx2-ffi/ffi-macros/src/lib.rs index 899ebce5a..23d0e9911 100644 --- a/iceoryx2-ffi/ffi-macros/src/lib.rs +++ b/iceoryx2-ffi/ffi-macros/src/lib.rs @@ -13,7 +13,10 @@ use proc_macro::TokenStream; use proc_macro2::TokenTree; use quote::{format_ident, quote}; -use syn::{parse_macro_input, punctuated::Punctuated, DeriveInput, LitStr, Meta, Token}; +use syn::{ + parse_macro_input, punctuated::Punctuated, Data, DeriveInput, Expr, ExprLit, Fields, Lit, + LitStr, Meta, Token, +}; #[proc_macro_attribute] pub fn iceoryx2_ffi(args: TokenStream, input: TokenStream) -> TokenStream { @@ -217,3 +220,99 @@ fn parse_attribute_args(args: TokenStream) -> Args { Args { rust_type } } + +/// Implements the [`iceoryx2_bb_elementary::AsCStr`] trait for enums to provide a string representation of each enum variant. +/// +/// The string representation can be customized using the `CStr` attribute, otherwise it will +/// convert the variant name to lowercase and replace underscores with spaces. +/// +/// # Example +/// ``` +/// use iceoryx2_ffi_macros::CStrRepr; +/// use iceoryx2_bb_elementary::AsCStr; +/// +/// #[derive(CStrRepr)] +/// enum MyEnum { +/// #[CStr = "custom variant one"] +/// VariantOne, +/// VariantTwo, +/// } +/// +/// let v1 = MyEnum::VariantOne; +/// assert_eq!(v1.as_const_cstr(), c"custom variant one"); +/// +/// let v2 = MyEnum::VariantTwo; +/// assert_eq!(v2.as_const_cstr(), c"variant two"); +/// ``` +#[proc_macro_derive(CStrRepr, attributes(CStr))] +pub fn string_literal_derive(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let name = &input.ident; + let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl(); + + let as_cstr_impl = match input.data { + Data::Enum(ref data_enum) => { + let enum_to_string_mapping = data_enum.variants.iter().map(|variant| { + let null_terminated = |s: &str| { + quote! { + // This code appends the null termination which cannot be confirmed at compile time, + // thus the code is ensured safe. + unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(concat!(#s, "\0").as_bytes()) } + } + }; + + let enum_name = &variant.ident; + let cstr_literal = variant + .attrs + .iter() + .find(|attr| attr.path().is_ident("CStr")) + .and_then(|attr| match attr.meta.require_name_value() { + Ok(meta) => match &meta.value { + Expr::Lit(ExprLit { lit: Lit::Str(lit), .. }) => Some(null_terminated(&lit.value())), + _ => None, + }, + _ => None, + }) + .unwrap_or_else(|| { + // No explicity `CStr` is provided. + // Convert variant name from 'UpperCamelCase' to 'lowercase with spaces'. + let enum_string = enum_name.to_string() + .char_indices() + .fold(String::new(), |mut acc, (i, c)| { + if i > 0 && c.is_uppercase() { + acc.push(' '); + } + acc.push(c.to_ascii_lowercase()); + acc + }); + null_terminated(&enum_string) + }); + + let pattern = match &variant.fields { + Fields::Unit => quote!(Self::#enum_name), + Fields::Unnamed(_) => quote!(Self::#enum_name(..)), + Fields::Named(_) => quote!(Self::#enum_name{..}), + }; + quote! { #pattern => #cstr_literal } + }); + + quote! { + fn as_const_cstr(&self) -> &'static ::std::ffi::CStr { + match self { + #(#enum_to_string_mapping,)* + } + } + } + } + _ => { + let err = syn::Error::new_spanned(&input, "AsCStrRepr can only be derived for enums"); + return err.to_compile_error().into(); + } + }; + + TokenStream::from(quote! { + impl #impl_generics AsCStr for #name #type_generics #where_clause { + #as_cstr_impl + } + }) +} diff --git a/iceoryx2-ffi/ffi/src/api/config.rs b/iceoryx2-ffi/ffi/src/api/config.rs index b528833a2..930045137 100644 --- a/iceoryx2-ffi/ffi/src/api/config.rs +++ b/iceoryx2-ffi/ffi/src/api/config.rs @@ -17,13 +17,13 @@ use core::ffi::{c_char, c_int}; use core::time::Duration; use iceoryx2::config::{Config, ConfigCreationError}; use iceoryx2_bb_container::semantic_string::*; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_bb_system_types::file_name::FileName; use iceoryx2_bb_system_types::file_path::FilePath; use iceoryx2_bb_system_types::path::Path; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use std::mem::ManuallyDrop; use crate::IOX2_OK; @@ -34,7 +34,7 @@ use super::{HandleToType, IntoCInt}; /// Failures occurring while creating a new [`iox2_config_t`] object with [`iox2_config_from_file()`]. #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_config_creation_error_e { /// The config file could not be opened. FAILED_TO_OPEN_CONFIG_FILE = IOX2_OK as isize + 1, @@ -154,7 +154,7 @@ impl HandleToType for iox2_config_h_ref { pub unsafe extern "C" fn iox2_config_creation_error_string( error: iox2_config_creation_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// This function casts a [`iox2_config_h`] into a [`iox2_config_ptr`] diff --git a/iceoryx2-ffi/ffi/src/api/listener.rs b/iceoryx2-ffi/ffi/src/api/listener.rs index e45f04079..1cc8eb6fc 100644 --- a/iceoryx2-ffi/ffi/src/api/listener.rs +++ b/iceoryx2-ffi/ffi/src/api/listener.rs @@ -20,12 +20,12 @@ use crate::iox2_file_descriptor_ptr; use iceoryx2::port::listener::Listener; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_bb_posix::file_descriptor::{FileDescriptor, FileDescriptorBased}; use iceoryx2_cal::event::ListenerWaitError; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -34,7 +34,7 @@ use core::time::Duration; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_listener_wait_error_e { CONTRACT_VIOLATION = IOX2_OK as isize + 1, INTERNAL_FAILURE, @@ -158,7 +158,7 @@ pub type iox2_listener_wait_all_callback = pub unsafe extern "C" fn iox2_listener_wait_error_string( error: iox2_listener_wait_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// This function needs to be called to destroy the listener! diff --git a/iceoryx2-ffi/ffi/src/api/mod.rs b/iceoryx2-ffi/ffi/src/api/mod.rs index 84c11dfcd..9c260b542 100644 --- a/iceoryx2-ffi/ffi/src/api/mod.rs +++ b/iceoryx2-ffi/ffi/src/api/mod.rs @@ -14,8 +14,8 @@ use iceoryx2::prelude::*; use iceoryx2_bb_container::semantic_string::SemanticStringError; -use iceoryx2_bb_derive_macros::StringLiteral; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int, c_void}; @@ -133,7 +133,7 @@ impl From for CallbackProgression { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_semantic_string_error_e { INVALID_CONTENT = IOX2_OK as isize + 1, EXCEEDS_MAXIMUM_LENGTH, @@ -219,5 +219,5 @@ trait AssertNonNullHandle { pub unsafe extern "C" fn iox2_semantic_string_error_string( error: iox2_semantic_string_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } diff --git a/iceoryx2-ffi/ffi/src/api/node.rs b/iceoryx2-ffi/ffi/src/api/node.rs index 48264c391..8f5b85965 100644 --- a/iceoryx2-ffi/ffi/src/api/node.rs +++ b/iceoryx2-ffi/ffi/src/api/node.rs @@ -23,10 +23,10 @@ use iceoryx2::node::{ }; use iceoryx2::prelude::*; use iceoryx2_bb_container::semantic_string::SemanticString; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -39,7 +39,7 @@ use super::{iox2_config_h_ref, iox2_node_id_h_ref, iox2_node_id_ptr, iox2_signal /// The failures that can occur when a list of node states is created with [`iox2_node_list()`]. #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_node_list_failure_e { /// A list of all Nodes could not be created since the process does not have sufficient permissions. INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, @@ -62,7 +62,7 @@ impl IntoCInt for NodeListFailure { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_node_wait_failure_e { INTERRUPT = IOX2_OK as isize + 1, TERMINATION_REQUEST, @@ -80,7 +80,7 @@ impl IntoCInt for NodeWaitFailure { /// Failures of [`iox2_dead_node_remove_stale_resources()`] that occur when the stale resources of /// a dead node are removed. #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_node_cleanup_failure_e { /// The process received an interrupt signal while cleaning up all stale resources of a dead node. INTERRUPT = IOX2_OK as isize + 1, @@ -232,7 +232,7 @@ pub type iox2_node_list_callback = extern "C" fn( pub unsafe extern "C" fn iox2_node_list_failure_string( error: iox2_node_list_failure_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns a string representation of the [`iox2_node_wait_failure_e`] error code. @@ -253,7 +253,7 @@ pub unsafe extern "C" fn iox2_node_list_failure_string( pub unsafe extern "C" fn iox2_node_wait_failure_string( error: iox2_node_wait_failure_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns the [`iox2_node_name_ptr`](crate::iox2_node_name_ptr), an immutable pointer to the node name. diff --git a/iceoryx2-ffi/ffi/src/api/node_builder.rs b/iceoryx2-ffi/ffi/src/api/node_builder.rs index 4f95417af..0acddede8 100644 --- a/iceoryx2-ffi/ffi/src/api/node_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/node_builder.rs @@ -19,11 +19,11 @@ use crate::api::{ use iceoryx2::node::NodeCreationFailure; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_bb_log::fatal_panic; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; @@ -32,7 +32,7 @@ use super::iox2_signal_handling_mode_e; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_node_creation_failure_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -121,7 +121,7 @@ impl HandleToType for iox2_node_builder_h_ref { pub unsafe extern "C" fn iox2_node_creation_failure_string( error: iox2_node_creation_failure_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Creates a builder for nodes diff --git a/iceoryx2-ffi/ffi/src/api/notifier.rs b/iceoryx2-ffi/ffi/src/api/notifier.rs index 9b43cde9f..f7ec64276 100644 --- a/iceoryx2-ffi/ffi/src/api/notifier.rs +++ b/iceoryx2-ffi/ffi/src/api/notifier.rs @@ -19,10 +19,10 @@ use crate::api::{ use iceoryx2::port::notifier::{Notifier, NotifierNotifyError}; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -30,7 +30,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_notifier_notify_error_e { EVENT_ID_OUT_OF_BOUNDS = IOX2_OK as isize + 1, } @@ -149,7 +149,7 @@ impl HandleToType for iox2_notifier_h_ref { pub unsafe extern "C" fn iox2_notifier_notify_error_string( error: iox2_notifier_notify_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns the unique port id of the notifier. diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs index 5e6445883..fc606a39c 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs @@ -20,10 +20,10 @@ use crate::api::{ use iceoryx2::port::listener::ListenerCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::listener::PortFactoryListener; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -31,7 +31,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_listener_create_error_e { EXCEEDS_MAX_SUPPORTED_LISTENERS = IOX2_OK as isize + 1, RESOURCE_CREATION_FAILED, @@ -154,7 +154,7 @@ impl HandleToType for iox2_port_factory_listener_builder_h_ref { pub unsafe extern "C" fn iox2_listener_create_error_string( error: iox2_listener_create_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } // TODO [#210] add all the other setter methods diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs index ca4a8824f..f9d46a019 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs @@ -20,10 +20,10 @@ use crate::api::{ use iceoryx2::port::notifier::NotifierCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::notifier::PortFactoryNotifier; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -31,7 +31,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_notifier_create_error_e { EXCEEDS_MAX_SUPPORTED_NOTIFIERS = IOX2_OK as isize + 1, } @@ -150,7 +150,7 @@ impl HandleToType for iox2_port_factory_notifier_builder_h_ref { pub unsafe extern "C" fn iox2_notifier_create_error_string( error: iox2_notifier_create_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Sets the default event id for the builder diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs index e4c5215ce..057b5a204 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs @@ -20,10 +20,10 @@ use crate::api::{ use iceoryx2::port::publisher::PublisherCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::publisher::PortFactoryPublisher; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -33,7 +33,7 @@ use core::mem::ManuallyDrop; /// Describes generically an allocation strategy, meaning how the memory is increased when the /// available memory is insufficient. #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_allocation_strategy_e { /// Increases the memory so that it perfectly fits the new size requirements. This may lead /// to a lot of reallocations but has the benefit that no byte is wasted. @@ -56,7 +56,7 @@ impl From for AllocationStrategy { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_publisher_create_error_e { EXCEEDS_MAX_SUPPORTED_PUBLISHERS = IOX2_OK as isize + 1, UNABLE_TO_CREATE_DATA_SEGMENT, @@ -218,7 +218,7 @@ impl HandleToType for iox2_port_factory_publisher_builder_h_ref { pub unsafe extern "C" fn iox2_publisher_create_error_string( error: iox2_publisher_create_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Sets the [`iox2_allocation_strategy_e`] for the publisher diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs index 9f7e61874..22a4a970f 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs @@ -20,10 +20,10 @@ use crate::api::{ use iceoryx2::port::subscriber::SubscriberCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::subscriber::PortFactorySubscriber; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -31,7 +31,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_subscriber_create_error_e { EXCEEDS_MAX_SUPPORTED_SUBSCRIBERS = IOX2_OK as isize + 1, BUFFER_SIZE_EXCEEDS_MAX_SUPPORTED_BUFFER_SIZE_OF_SERVICE, @@ -158,7 +158,7 @@ impl HandleToType for iox2_port_factory_subscriber_builder_h_ref { pub unsafe extern "C" fn iox2_subscriber_create_error_string( error: iox2_subscriber_create_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Sets the buffer size for the subscriber diff --git a/iceoryx2-ffi/ffi/src/api/publisher.rs b/iceoryx2-ffi/ffi/src/api/publisher.rs index 1dac4e0dd..5385055f3 100644 --- a/iceoryx2-ffi/ffi/src/api/publisher.rs +++ b/iceoryx2-ffi/ffi/src/api/publisher.rs @@ -21,10 +21,10 @@ use crate::api::{ use iceoryx2::port::publisher::{Publisher, PublisherLoanError, PublisherSendError}; use iceoryx2::port::update_connections::UpdateConnections; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use super::{iox2_sample_mut_h, iox2_sample_mut_t, IntoCInt}; @@ -34,7 +34,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_publisher_send_error_e { CONNECTION_BROKEN_SINCE_PUBLISHER_NO_LONGER_EXISTS = IOX2_OK as isize + 1, CONNECTION_CORRUPTED, @@ -87,7 +87,7 @@ impl IntoCInt for PublisherLoanError { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_publisher_loan_error_e { OUT_OF_MEMORY = IOX2_OK as isize + 1, EXCEEDS_MAX_LOANED_SAMPLES, @@ -264,7 +264,7 @@ unsafe fn send_slice_copy( pub unsafe extern "C" fn iox2_publisher_send_error_string( error: iox2_publisher_send_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns a string literal describing the provided [`iox2_publisher_loan_error_e`]. @@ -285,7 +285,7 @@ pub unsafe extern "C" fn iox2_publisher_send_error_string( pub unsafe extern "C" fn iox2_publisher_loan_error_string( error: iox2_publisher_loan_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns the strategy the publisher follows when a sample cannot be delivered diff --git a/iceoryx2-ffi/ffi/src/api/service.rs b/iceoryx2-ffi/ffi/src/api/service.rs index 91d7e0c5c..e8d6212a7 100644 --- a/iceoryx2-ffi/ffi/src/api/service.rs +++ b/iceoryx2-ffi/ffi/src/api/service.rs @@ -21,9 +21,9 @@ use iceoryx2::service::{ ipc, local, messaging_pattern::MessagingPattern, Service, ServiceDetails, ServiceDetailsError, ServiceListError, }; -use iceoryx2_bb_derive_macros::StringLiteral; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_bb_elementary::CallbackProgression; +use iceoryx2_ffi_macros::CStrRepr; use crate::{ iox2_callback_context, iox2_callback_progression_e, iox2_config_ptr, iox2_service_name_ptr, @@ -72,7 +72,7 @@ impl From<&iceoryx2::service::static_config::messaging_pattern::MessagingPattern } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_service_details_error_e { FAILED_TO_OPEN_STATIC_SERVICE_INFO = IOX2_OK as isize + 1, FAILED_TO_READ_STATIC_SERVICE_INFO, @@ -108,7 +108,7 @@ impl IntoCInt for ServiceDetailsError { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_service_list_error_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -152,7 +152,7 @@ pub type iox2_service_list_callback = extern "C" fn( pub unsafe extern "C" fn iox2_service_details_error_string( error: iox2_service_details_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns a string literal describing the provided [`iox2_service_list_error_e`]. @@ -173,7 +173,7 @@ pub unsafe extern "C" fn iox2_service_details_error_string( pub unsafe extern "C" fn iox2_service_list_error_string( error: iox2_service_list_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Checks if a specified service exists. If the service exists `does_exist` will contain diff --git a/iceoryx2-ffi/ffi/src/api/service_builder_event.rs b/iceoryx2-ffi/ffi/src/api/service_builder_event.rs index d37d0ee21..d851454f2 100644 --- a/iceoryx2-ffi/ffi/src/api/service_builder_event.rs +++ b/iceoryx2-ffi/ffi/src/api/service_builder_event.rs @@ -23,8 +23,8 @@ use iceoryx2::service::builder::event::{ Builder, EventCreateError, EventOpenError, EventOpenOrCreateError, }; use iceoryx2::service::port_factory::event::PortFactory; -use iceoryx2_bb_derive_macros::StringLiteral; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -34,53 +34,53 @@ use super::{iox2_attribute_specifier_h_ref, iox2_attribute_verifier_h_ref}; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_event_open_or_create_error_e { - #[CustomString = "does not exist"] + #[CStr = "does not exist"] O_DOES_NOT_EXIST = IOX2_OK as isize + 1, - #[CustomString = "insufficient permissions"] + #[CStr = "insufficient permissions"] O_INSUFFICIENT_PERMISSIONS, - #[CustomString = "service in corrupted state"] + #[CStr = "service in corrupted state"] O_SERVICE_IN_CORRUPTED_STATE, - #[CustomString = "incompatible messaging pattern"] + #[CStr = "incompatible messaging pattern"] O_INCOMPATIBLE_MESSAGING_PATTERN, - #[CustomString = "incompatible attributes"] + #[CStr = "incompatible attributes"] O_INCOMPATIBLE_ATTRIBUTES, - #[CustomString = "incompatible notifier_created_event"] + #[CStr = "incompatible notifier_created event"] O_INCOMPATIBLE_NOTIFIER_CREATED_EVENT, - #[CustomString = "incompatible notifier_dropped_event"] + #[CStr = "incompatible notifier_dropped event"] O_INCOMPATIBLE_NOTIFIER_DROPPED_EVENT, - #[CustomString = "incompatible notifier_dead_event"] + #[CStr = "incompatible notifier_dead event"] O_INCOMPATIBLE_NOTIFIER_DEAD_EVENT, - #[CustomString = "internal failure"] + #[CStr = "internal failure"] O_INTERNAL_FAILURE, - #[CustomString = "hangs in creation"] + #[CStr = "hangs in creation"] O_HANGS_IN_CREATION, - #[CustomString = "does not support requested amount of notifiers"] + #[CStr = "does not support requested amount of notifiers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NOTIFIERS, - #[CustomString = "does not support requested amount of listeners"] + #[CStr = "does not support requested amount of listeners"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_LISTENERS, - #[CustomString = "does not support requested max event id"] + #[CStr = "does not support requested max event id"] O_DOES_NOT_SUPPORT_REQUESTED_MAX_EVENT_ID, - #[CustomString = "does not support requested amount of nodes"] + #[CStr = "does not support requested amount of nodes"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES, - #[CustomString = "exceeds max number of nodes"] + #[CStr = "exceeds max number of nodes"] O_EXCEEDS_MAX_NUMBER_OF_NODES, - #[CustomString = "is marked for destruction"] + #[CStr = "is marked for destruction"] O_IS_MARKED_FOR_DESTRUCTION, - #[CustomString = "service in corrupted state"] + #[CStr = "service in corrupted state"] C_SERVICE_IN_CORRUPTED_STATE, - #[CustomString = "internal failure"] + #[CStr = "internal failure"] C_INTERNAL_FAILURE, - #[CustomString = "is being created by another instance"] + #[CStr = "is being created by another instance"] C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE, - #[CustomString = "already exists"] + #[CStr = "already exists"] C_ALREADY_EXISTS, - #[CustomString = "hangs in creation"] + #[CStr = "hangs in creation"] C_HANGS_IN_CREATION, - #[CustomString = "insufficient permissions"] + #[CStr = "insufficient permissions"] C_INSUFFICIENT_PERMISSIONS, - #[CustomString = "old connection still active"] + #[CStr = "old connection still active"] C_OLD_CONNECTION_STILL_ACTIVE, } @@ -192,7 +192,7 @@ impl IntoCInt for EventOpenOrCreateError { pub unsafe extern "C" fn iox2_event_open_or_create_error_string( error: iox2_event_open_or_create_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Sets the event id value that shall be emitted if a notifier was identified as dead. diff --git a/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs b/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs index 23a04bb79..c1ec10280 100644 --- a/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs +++ b/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs @@ -26,9 +26,9 @@ use iceoryx2::service::builder::publish_subscribe::{ }; use iceoryx2::service::port_factory::publish_subscribe::PortFactory; use iceoryx2::service::static_config::message_type_details::{TypeDetail, TypeVariant}; -use iceoryx2_bb_derive_macros::StringLiteral; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_bb_log::fatal_panic; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -40,57 +40,57 @@ use super::{iox2_attribute_specifier_h_ref, iox2_attribute_verifier_h_ref}; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_pub_sub_open_or_create_error_e { - #[CustomString = "does not exist"] + #[CStr = "does not exist"] O_DOES_NOT_EXIST = IOX2_OK as isize + 1, - #[CustomString = "internal failure"] + #[CStr = "internal failure"] O_INTERNAL_FAILURE, - #[CustomString = "incompatible types"] + #[CStr = "incompatible types"] O_INCOMPATIBLE_TYPES, - #[CustomString = "incompatible messaging pattern"] + #[CStr = "incompatible messaging pattern"] O_INCOMPATIBLE_MESSAGING_PATTERN, - #[CustomString = "incompatible attributes"] + #[CStr = "incompatible attributes"] O_INCOMPATIBLE_ATTRIBUTES, - #[CustomString = "does not support requested min buffer size"] + #[CStr = "does not support requested min buffer size"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_BUFFER_SIZE, - #[CustomString = "does not support requested min history size"] + #[CStr = "does not support requested min history size"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_HISTORY_SIZE, - #[CustomString = "does not support requested min subscriber borrowed samples"] + #[CStr = "does not support requested min subscriber borrowed samples"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_SUBSCRIBER_BORROWED_SAMPLES, - #[CustomString = "does not support requested amount of publishers"] + #[CStr = "does not support requested amount of publishers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_PUBLISHERS, - #[CustomString = "does not support requested amount of subscribers"] + #[CStr = "does not support requested amount of subscribers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_SUBSCRIBERS, - #[CustomString = "does not support requested amount of nodes"] + #[CStr = "does not support requested amount of nodes"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES, - #[CustomString = "incompatible overflow behavior"] + #[CStr = "incompatible overflow behavior"] O_INCOMPATIBLE_OVERFLOW_BEHAVIOR, - #[CustomString = "insufficient permissions"] + #[CStr = "insufficient permissions"] O_INSUFFICIENT_PERMISSIONS, - #[CustomString = "service in corrupted state"] + #[CStr = "service in corrupted state"] O_SERVICE_IN_CORRUPTED_STATE, - #[CustomString = "hangs in creation"] + #[CStr = "hangs in creation"] O_HANGS_IN_CREATION, - #[CustomString = "exceeds max number of nodes"] + #[CStr = "exceeds max number of nodes"] O_EXCEEDS_MAX_NUMBER_OF_NODES, - #[CustomString = "is marked for destruction"] + #[CStr = "is marked for destruction"] O_IS_MARKED_FOR_DESTRUCTION, - #[CustomString = "service in corrupted state"] + #[CStr = "service in corrupted state"] C_SERVICE_IN_CORRUPTED_STATE, - #[CustomString = "subscriber buffer must be larger than history size"] + #[CStr = "subscriber buffer must be larger than history size"] C_SUBSCRIBER_BUFFER_MUST_BE_LARGER_THAN_HISTORY_SIZE, - #[CustomString = "already exists"] + #[CStr = "already exists"] C_ALREADY_EXISTS, - #[CustomString = "insufficient permissions"] + #[CStr = "insufficient permissions"] C_INSUFFICIENT_PERMISSIONS, - #[CustomString = "internal failure"] + #[CStr = "internal failure"] C_INTERNAL_FAILURE, - #[CustomString = "is being created by another instance"] + #[CStr = "is being created by another instance"] C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE, - #[CustomString = "old connection still active"] + #[CStr = "old connection still active"] C_OLD_CONNECTION_STILL_ACTIVE, - #[CustomString = "hangs in creation"] + #[CStr = "hangs in creation"] C_HANGS_IN_CREATION, } @@ -247,7 +247,7 @@ pub enum iox2_type_detail_error_e { pub unsafe extern "C" fn iox2_pub_sub_open_or_create_error_string( error: iox2_pub_sub_open_or_create_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Sets the user header type details for the builder diff --git a/iceoryx2-ffi/ffi/src/api/subscriber.rs b/iceoryx2-ffi/ffi/src/api/subscriber.rs index 1fbbad121..872533388 100644 --- a/iceoryx2-ffi/ffi/src/api/subscriber.rs +++ b/iceoryx2-ffi/ffi/src/api/subscriber.rs @@ -21,10 +21,10 @@ use crate::api::{ use iceoryx2::port::subscriber::{Subscriber, SubscriberReceiveError}; use iceoryx2::port::update_connections::{ConnectionFailure, UpdateConnections}; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -32,7 +32,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_subscriber_receive_error_e { EXCEEDS_MAX_BORROWED_SAMPLES = IOX2_OK as isize + 1, FAILED_TO_ESTABLISH_CONNECTION, @@ -56,7 +56,7 @@ impl IntoCInt for SubscriberReceiveError { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_connection_failure_e { FAILED_TO_ESTABLISH_CONNECTION, UNABLE_TO_MAP_PUBLISHERS_DATA_SEGMENT, @@ -181,7 +181,7 @@ impl HandleToType for iox2_subscriber_h_ref { pub unsafe extern "C" fn iox2_subscriber_receive_error_string( error: iox2_subscriber_receive_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns a string literal describing the provided [`iox2_connection_failure_e`]. @@ -202,7 +202,7 @@ pub unsafe extern "C" fn iox2_subscriber_receive_error_string( pub unsafe extern "C" fn iox2_connection_failure_string( error: iox2_connection_failure_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns the buffer size of the subscriber diff --git a/iceoryx2-ffi/ffi/src/api/waitset.rs b/iceoryx2-ffi/ffi/src/api/waitset.rs index 044558773..ad6a680e8 100644 --- a/iceoryx2-ffi/ffi/src/api/waitset.rs +++ b/iceoryx2-ffi/ffi/src/api/waitset.rs @@ -27,15 +27,15 @@ use iceoryx2::{ WaitSet, WaitSetAttachmentError, WaitSetCreateError, WaitSetRunError, WaitSetRunResult, }, }; -use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStringLiteral; +use iceoryx2_bb_elementary::AsCStr; use iceoryx2_ffi_macros::iceoryx2_ffi; +use iceoryx2_ffi_macros::CStrRepr; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_waitset_run_error_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -57,7 +57,7 @@ impl IntoCInt for WaitSetRunError { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_waitset_run_result_e { TERMINATION_REQUEST = IOX2_OK as isize + 1, INTERRUPT, @@ -83,7 +83,7 @@ impl From for iox2_waitset_run_result_e { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_waitset_attachment_error_e { INSUFFICIENT_CAPACITY = IOX2_OK as isize + 1, ALREADY_ATTACHED, @@ -107,7 +107,7 @@ impl IntoCInt for WaitSetAttachmentError { } #[repr(C)] -#[derive(Copy, Clone, StringLiteral)] +#[derive(Copy, Clone, CStrRepr)] pub enum iox2_waitset_create_error_e { INTERNAL_ERROR = IOX2_OK as isize + 1, } @@ -229,7 +229,7 @@ pub type iox2_waitset_run_callback = extern "C" fn( pub unsafe extern "C" fn iox2_waitset_create_error_string( error: iox2_waitset_create_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns a string literal describing the provided [`iox2_waitset_attachment_error_e`]. @@ -250,7 +250,7 @@ pub unsafe extern "C" fn iox2_waitset_create_error_string( pub unsafe extern "C" fn iox2_waitset_attachment_error_string( error: iox2_waitset_attachment_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Returns a string literal describing the provided [`iox2_waitset_run_error_e`]. @@ -271,7 +271,7 @@ pub unsafe extern "C" fn iox2_waitset_attachment_error_string( pub unsafe extern "C" fn iox2_waitset_run_error_string( error: iox2_waitset_run_error_e, ) -> *const c_char { - error.as_str_literal().as_ptr() as *const c_char + error.as_const_cstr().as_ptr() as *const c_char } /// Drops a [`iox2_waitset_h`] and calls all corresponding cleanup functions.