diff --git a/iceoryx2-bb/derive-macros/src/lib.rs b/iceoryx2-bb/derive-macros/src/lib.rs index 1fd348dfd..b5e48fa5a 100644 --- a/iceoryx2-bb/derive-macros/src/lib.rs +++ b/iceoryx2-bb/derive-macros/src/lib.rs @@ -100,23 +100,22 @@ pub fn placement_default_derive(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } -#[proc_macro_derive(StaticStringRepresentation, attributes(StaticString))] -pub fn as_static_string_derive(input: TokenStream) -> TokenStream { +#[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, ty_generics, where_clause) = input.generics.split_for_impl(); - let static_string_impl = match input.data { + let string_literal_impl = match input.data { Data::Enum(ref data_enum) => { let match_arms = data_enum.variants.iter().map(|variant| { let variant_ident = &variant.ident; - // Get the StaticString attribute if it exists let static_string = variant .attrs .iter() .find_map(|attr| { - if !attr.path().is_ident("StaticString") { + if !attr.path().is_ident("CustomString") { return None; } @@ -152,40 +151,45 @@ pub fn as_static_string_derive(input: TokenStream) -> TokenStream { match &variant.fields { Fields::Unit => { quote! { - Self::#variant_ident => concat!(#static_string, "\0") + Self::#variant_ident => concat!(#static_string, "\0").as_ptr() } } Fields::Unnamed(_) => { quote! { - Self::#variant_ident(..) => concat!(#static_string, "\0") + Self::#variant_ident(..) => concat!(#static_string, "\0").as_ptr() } } Fields::Named(_) => { quote! { - Self::#variant_ident{..} => concat!(#static_string, "\0") + Self::#variant_ident{..} => concat!(#static_string, "\0").as_ptr() } } } }); quote! { - fn as_static_str(&self) -> &'static str { - match self { - #(#match_arms,)* + fn as_str_literal(&self) -> &'static str { + unsafe { + std::str::from_utf8_unchecked( + std::ffi::CStr::from_ptr(match self { + #(#match_arms,)* + } as *const i8) + .to_bytes() + ) } } } } _ => { let err = - syn::Error::new_spanned(&input, "AsStaticString can only be derived for enums"); + syn::Error::new_spanned(&input, "AsStringLiteral can only be derived for enums"); return err.to_compile_error().into(); } }; let expanded = quote! { - impl #impl_generics AsStaticString for #name #ty_generics #where_clause { - #static_string_impl + impl #impl_generics AsStringLiteral for #name #ty_generics #where_clause { + #string_literal_impl } }; diff --git a/iceoryx2-bb/elementary/src/as_static_string.rs b/iceoryx2-bb/elementary/src/as_string_literal.rs similarity index 87% rename from iceoryx2-bb/elementary/src/as_static_string.rs rename to iceoryx2-bb/elementary/src/as_string_literal.rs index 9e7cfd545..861882067 100644 --- a/iceoryx2-bb/elementary/src/as_static_string.rs +++ b/iceoryx2-bb/elementary/src/as_string_literal.rs @@ -10,6 +10,6 @@ // // SPDX-License-Identifier: Apache-2.0 OR MIT -pub trait AsStaticString { - fn as_static_str(&self) -> &'static str; +pub trait AsStringLiteral { + fn as_str_literal(&self) -> &'static str; } diff --git a/iceoryx2-bb/elementary/src/lib.rs b/iceoryx2-bb/elementary/src/lib.rs index 5d7d55c0a..84e058925 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_static_string; -pub use as_static_string::*; +mod as_string_literal; +pub use as_string_literal::*; pub mod alignment; pub mod allocator; diff --git a/iceoryx2-ffi/ffi/src/api/config.rs b/iceoryx2-ffi/ffi/src/api/config.rs index b6ff7e290..847fbc925 100644 --- a/iceoryx2-ffi/ffi/src/api/config.rs +++ b/iceoryx2-ffi/ffi/src/api/config.rs @@ -17,9 +17,9 @@ 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::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_bb_system_types::file_name::FileName; use iceoryx2_bb_system_types::file_path::FilePath; use iceoryx2_bb_system_types::path::Path; @@ -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, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_config_creation_error_e { /// The config file could not be opened. FAILED_TO_OPEN_CONFIG_FILE = IOX2_OK as isize + 1, @@ -140,7 +140,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 e184e78f9..21002f0fe 100644 --- a/iceoryx2-ffi/ffi/src/api/listener.rs +++ b/iceoryx2-ffi/ffi/src/api/listener.rs @@ -20,9 +20,9 @@ use crate::iox2_file_descriptor_ptr; use iceoryx2::port::listener::Listener; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_bb_posix::file_descriptor::{FileDescriptor, FileDescriptorBased}; use iceoryx2_cal::event::ListenerWaitError; use iceoryx2_ffi_macros::iceoryx2_ffi; @@ -34,7 +34,7 @@ use core::time::Duration; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_listener_wait_error_e { CONTRACT_VIOLATION = IOX2_OK as isize + 1, INTERNAL_FAILURE, @@ -144,7 +144,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 a2f49e99d..5c113dbcd 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::StaticStringRepresentation; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_derive_macros::StringLiteral; +use iceoryx2_bb_elementary::AsStringLiteral; use core::ffi::{c_char, c_int, c_void}; @@ -121,7 +121,7 @@ impl From for CallbackProgression { } #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_semantic_string_error_e { INVALID_CONTENT = IOX2_OK as isize + 1, EXCEEDS_MAXIMUM_LENGTH, @@ -193,5 +193,5 @@ trait AssertNonNullHandle { pub unsafe extern "C" fn iox2_semantic_string_error_string( error: iox2_semantic_string_error_e, ) -> *const c_char { - error.as_static_str().as_ptr() as *const c_char + error.as_str_literal().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 91eb72046..c1d0a5cca 100644 --- a/iceoryx2-ffi/ffi/src/api/node.rs +++ b/iceoryx2-ffi/ffi/src/api/node.rs @@ -20,9 +20,9 @@ use crate::api::{ use iceoryx2::node::{NodeId, NodeListFailure, NodeView, NodeWaitFailure}; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; use core::ffi::{c_char, c_int}; @@ -32,7 +32,7 @@ use std::time::Duration; // BEGIN type definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_node_list_failure_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERRUPT, @@ -52,7 +52,7 @@ impl IntoCInt for NodeListFailure { } #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_node_wait_failure_e { INTERRUPT = IOX2_OK as isize + 1, TERMINATION_REQUEST, @@ -191,14 +191,14 @@ 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_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } #[no_mangle] pub unsafe extern "C" fn iox2_node_wait_failure_string( error: iox2_node_wait_failure_e, ) -> *const c_char { - error.as_static_str().as_ptr() as *const c_char + error.as_str_literal().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 efdbdd9e5..b505e1215 100644 --- a/iceoryx2-ffi/ffi/src/api/node_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/node_builder.rs @@ -19,9 +19,9 @@ use crate::api::{ use iceoryx2::node::NodeCreationFailure; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_bb_log::fatal_panic; use iceoryx2_ffi_macros::iceoryx2_ffi; @@ -30,7 +30,7 @@ use core::ffi::{c_char, c_int}; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_node_creation_failure_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -105,7 +105,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 0e3e491d7..79c472e2c 100644 --- a/iceoryx2-ffi/ffi/src/api/notifier.rs +++ b/iceoryx2-ffi/ffi/src/api/notifier.rs @@ -19,9 +19,9 @@ use crate::api::{ use iceoryx2::port::notifier::{Notifier, NotifierNotifyError}; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; use core::ffi::{c_char, c_int}; @@ -30,7 +30,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_notifier_notify_error_e { EVENT_ID_OUT_OF_BOUNDS = IOX2_OK as isize + 1, } @@ -135,7 +135,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 a9ec63199..4a64218f7 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs @@ -20,9 +20,9 @@ use crate::api::{ use iceoryx2::port::listener::ListenerCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::listener::PortFactoryListener; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; use core::ffi::{c_char, c_int}; @@ -31,7 +31,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_listener_create_error_e { EXCEEDS_MAX_SUPPORTED_LISTENERS = IOX2_OK as isize + 1, RESOURCE_CREATION_FAILED, @@ -140,7 +140,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 18ae20acf..4ff73e1c6 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs @@ -20,9 +20,9 @@ use crate::api::{ use iceoryx2::port::notifier::NotifierCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::notifier::PortFactoryNotifier; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; use core::ffi::{c_char, c_int}; @@ -31,7 +31,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_notifier_create_error_e { EXCEEDS_MAX_SUPPORTED_NOTIFIERS = IOX2_OK as isize + 1, } @@ -136,7 +136,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 fcd7b2be7..1cd0c27f5 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs @@ -20,9 +20,9 @@ use crate::api::{ use iceoryx2::port::publisher::PublisherCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::publisher::PortFactoryPublisher; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; use core::ffi::{c_char, c_int}; @@ -31,7 +31,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_publisher_create_error_e { EXCEEDS_MAX_SUPPORTED_PUBLISHERS = IOX2_OK as isize + 1, UNABLE_TO_CREATE_DATA_SEGMENT, @@ -179,7 +179,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_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } /// Sets the max slice length 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 3bff0cc99..7764dea19 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs @@ -20,9 +20,9 @@ use crate::api::{ use iceoryx2::port::subscriber::SubscriberCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::subscriber::PortFactorySubscriber; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; use core::ffi::{c_char, c_int}; @@ -31,7 +31,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] 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, @@ -144,7 +144,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 657b045fe..c5481f5a7 100644 --- a/iceoryx2-ffi/ffi/src/api/publisher.rs +++ b/iceoryx2-ffi/ffi/src/api/publisher.rs @@ -21,9 +21,9 @@ use crate::api::{ use iceoryx2::port::publisher::{Publisher, PublisherLoanError, PublisherSendError}; use iceoryx2::port::update_connections::UpdateConnections; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; 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, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] 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, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_publisher_loan_error_e { OUT_OF_MEMORY = IOX2_OK as isize + 1, EXCEEDS_MAX_LOANED_SAMPLES, @@ -250,14 +250,14 @@ 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_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } #[no_mangle] pub unsafe extern "C" fn iox2_publisher_loan_error_string( error: iox2_publisher_loan_error_e, ) -> *const c_char { - error.as_static_str().as_ptr() as *const c_char + error.as_str_literal().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 1547f71e5..3ec4d6695 100644 --- a/iceoryx2-ffi/ffi/src/api/service.rs +++ b/iceoryx2-ffi/ffi/src/api/service.rs @@ -21,8 +21,8 @@ use iceoryx2::service::{ ipc, local, messaging_pattern::MessagingPattern, Service, ServiceDetails, ServiceDetailsError, ServiceListError, }; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_derive_macros::StringLiteral; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_bb_elementary::CallbackProgression; use crate::{ @@ -72,7 +72,7 @@ impl From<&iceoryx2::service::static_config::messaging_pattern::MessagingPattern } #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] 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, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_service_list_error_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -138,14 +138,14 @@ 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_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } #[no_mangle] pub unsafe extern "C" fn iox2_service_list_error_string( error: iox2_service_list_error_e, ) -> *const c_char { - error.as_static_str().as_ptr() as *const c_char + error.as_str_literal().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 cf3676641..cddf408e1 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::StaticStringRepresentation; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_derive_macros::StringLiteral; +use iceoryx2_bb_elementary::AsStringLiteral; use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; @@ -32,46 +32,48 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_event_open_or_create_error_e { - #[StaticString = "does not exist"] + #[CustomString = "does not exist"] O_DOES_NOT_EXIST = IOX2_OK as isize + 1, - #[StaticString = "insufficient permissions"] + #[CustomString = "insufficient permissions"] O_INSUFFICIENT_PERMISSIONS, - #[StaticString = "service in corrupted state"] + #[CustomString = "service in corrupted state"] O_SERVICE_IN_CORRUPTED_STATE, - #[StaticString = "incompatible messaging pattern"] + #[CustomString = "incompatible messaging pattern"] O_INCOMPATIBLE_MESSAGING_PATTERN, - #[StaticString = "incompatible attributes"] + #[CustomString = "incompatible attributes"] O_INCOMPATIBLE_ATTRIBUTES, - #[StaticString = "internal failure"] + #[CustomString = "internal failure"] O_INTERNAL_FAILURE, - #[StaticString = "hangs in creation"] + #[CustomString = "hangs in creation"] O_HANGS_IN_CREATION, - #[StaticString = "does not support requested amount of notifiers"] + #[CustomString = "does not support requested amount of notifiers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NOTIFIERS, - #[StaticString = "does not support requested amount of listeners"] + #[CustomString = "does not support requested amount of listeners"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_LISTENERS, - #[StaticString = "does not support requested max event id"] + #[CustomString = "does not support requested max event id"] O_DOES_NOT_SUPPORT_REQUESTED_MAX_EVENT_ID, - #[StaticString = "does not support requested amount of nodes"] + #[CustomString = "does not support requested amount of nodes"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES, - #[StaticString = "exceeds max number of nodes"] + #[CustomString = "exceeds max number of nodes"] O_EXCEEDS_MAX_NUMBER_OF_NODES, - #[StaticString = "is marked for destruction"] + #[CustomString = "is marked for destruction"] O_IS_MARKED_FOR_DESTRUCTION, - #[StaticString = "service in corrupted state"] + #[CustomString = "service in corrupted state"] C_SERVICE_IN_CORRUPTED_STATE, - #[StaticString = "internal failure"] + #[CustomString = "internal failure"] C_INTERNAL_FAILURE, - #[StaticString = "is being created by another instance"] + #[CustomString = "is being created by another instance"] C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE, - #[StaticString = "already exists"] + #[CustomString = "already exists"] C_ALREADY_EXISTS, - #[StaticString = "hangs in creation"] + #[CustomString = "hangs in creation"] C_HANGS_IN_CREATION, - #[StaticString = "insufficient permissions"] + #[CustomString = "insufficient permissions"] C_INSUFFICIENT_PERMISSIONS, + #[CustomString = "old connection still active"] + C_OLD_CONNECTION_STILL_ACTIVE, } impl IntoCInt for EventOpenError { @@ -159,7 +161,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_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } /// Sets the max notifiers for the builder 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 86ec52398..439050aa9 100644 --- a/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs +++ b/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs @@ -26,8 +26,8 @@ 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::StaticStringRepresentation; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_derive_macros::StringLiteral; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_bb_log::fatal_panic; use core::ffi::{c_char, c_int}; @@ -38,55 +38,57 @@ use std::alloc::Layout; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_pub_sub_open_or_create_error_e { - #[StaticString = "does not exist"] + #[CustomString = "does not exist"] O_DOES_NOT_EXIST = IOX2_OK as isize + 1, - #[StaticString = "internal failure"] + #[CustomString = "internal failure"] O_INTERNAL_FAILURE, - #[StaticString = "incompatible types"] + #[CustomString = "incompatible types"] O_INCOMPATIBLE_TYPES, - #[StaticString = "incompatible messaging pattern"] + #[CustomString = "incompatible messaging pattern"] O_INCOMPATIBLE_MESSAGING_PATTERN, - #[StaticString = "incompatible attributes"] + #[CustomString = "incompatible attributes"] O_INCOMPATIBLE_ATTRIBUTES, - #[StaticString = "does not support requested min buffer size"] + #[CustomString = "does not support requested min buffer size"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_BUFFER_SIZE, - #[StaticString = "does not support requested min history size"] + #[CustomString = "does not support requested min history size"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_HISTORY_SIZE, - #[StaticString = "does not support requested min subscriber borrowed samples"] + #[CustomString = "does not support requested min subscriber borrowed samples"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_SUBSCRIBER_BORROWED_SAMPLES, - #[StaticString = "does not support requested amount of publishers"] + #[CustomString = "does not support requested amount of publishers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_PUBLISHERS, - #[StaticString = "does not support requested amount of subscribers"] + #[CustomString = "does not support requested amount of subscribers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_SUBSCRIBERS, - #[StaticString = "does not support requested amount of nodes"] + #[CustomString = "does not support requested amount of nodes"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES, - #[StaticString = "incompatible overflow behavior"] + #[CustomString = "incompatible overflow behavior"] O_INCOMPATIBLE_OVERFLOW_BEHAVIOR, - #[StaticString = "insufficient permissions"] + #[CustomString = "insufficient permissions"] O_INSUFFICIENT_PERMISSIONS, - #[StaticString = "service in corrupted state"] + #[CustomString = "service in corrupted state"] O_SERVICE_IN_CORRUPTED_STATE, - #[StaticString = "hangs in creation"] + #[CustomString = "hangs in creation"] O_HANGS_IN_CREATION, - #[StaticString = "exceeds max number of nodes"] + #[CustomString = "exceeds max number of nodes"] O_EXCEEDS_MAX_NUMBER_OF_NODES, - #[StaticString = "is marked for destruction"] + #[CustomString = "is marked for destruction"] O_IS_MARKED_FOR_DESTRUCTION, - #[StaticString = "service in corrupted state"] + #[CustomString = "service in corrupted state"] C_SERVICE_IN_CORRUPTED_STATE, - #[StaticString = "subscriber buffer must be larger than history size"] + #[CustomString = "subscriber buffer must be larger than history size"] C_SUBSCRIBER_BUFFER_MUST_BE_LARGER_THAN_HISTORY_SIZE, - #[StaticString = "already exists"] + #[CustomString = "already exists"] C_ALREADY_EXISTS, - #[StaticString = "insufficient permissions"] + #[CustomString = "insufficient permissions"] C_INSUFFICIENT_PERMISSIONS, - #[StaticString = "internal failure"] + #[CustomString = "internal failure"] C_INTERNAL_FAILURE, - #[StaticString = "is being created by another instance"] + #[CustomString = "is being created by another instance"] C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE, - #[StaticString = "hangs in creation"] + #[CustomString = "old connection still active"] + C_OLD_CONNECTION_STILL_ACTIVE, + #[CustomString = "hangs in creation"] C_HANGS_IN_CREATION, } @@ -229,7 +231,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_static_str().as_ptr() as *const c_char + error.as_str_literal().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 62957d9ea..18a56a9d5 100644 --- a/iceoryx2-ffi/ffi/src/api/subscriber.rs +++ b/iceoryx2-ffi/ffi/src/api/subscriber.rs @@ -21,9 +21,9 @@ use crate::api::{ use iceoryx2::port::subscriber::{Subscriber, SubscriberReceiveError}; use iceoryx2::port::update_connections::{ConnectionFailure, UpdateConnections}; use iceoryx2::prelude::*; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; use core::ffi::{c_char, c_int}; @@ -32,7 +32,7 @@ use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] 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, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_connection_failure_e { FAILED_TO_ESTABLISH_CONNECTION, UNABLE_TO_MAP_PUBLISHERS_DATA_SEGMENT, @@ -167,14 +167,14 @@ 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_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } #[no_mangle] pub unsafe extern "C" fn iox2_connection_failure_string( error: iox2_connection_failure_e, ) -> *const c_char { - error.as_static_str().as_ptr() as *const c_char + error.as_str_literal().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 8674de625..d01b6e359 100644 --- a/iceoryx2-ffi/ffi/src/api/waitset.rs +++ b/iceoryx2-ffi/ffi/src/api/waitset.rs @@ -27,15 +27,15 @@ use iceoryx2::{ }, service::{ipc, local}, }; -use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_derive_macros::StringLiteral; use iceoryx2_bb_elementary::static_assert::*; -use iceoryx2_bb_elementary::AsStaticString; +use iceoryx2_bb_elementary::AsStringLiteral; use iceoryx2_ffi_macros::iceoryx2_ffi; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_waitset_run_error_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -83,7 +83,7 @@ impl From for iox2_waitset_run_result_e { } #[repr(C)] -#[derive(Copy, Clone, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] 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, StaticStringRepresentation)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_waitset_create_error_e { INTERNAL_ERROR = IOX2_OK as isize + 1, } @@ -215,21 +215,21 @@ 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_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } #[no_mangle] pub unsafe extern "C" fn iox2_waitset_attachment_error_string( error: iox2_waitset_attachment_error_e, ) -> *const c_char { - error.as_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } #[no_mangle] pub unsafe extern "C" fn iox2_waitset_run_error_string( error: iox2_waitset_run_error_e, ) -> *const c_char { - error.as_static_str().as_ptr() as *const c_char + error.as_str_literal().as_ptr() as *const c_char } /// Drops a [`iox2_waitset_h`] and calls all corresponding cleanup functions.