1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Type definitions that adapt to different platform capabilities.
//!
//! This module provides type aliases and utilities that adapt to the current
//! platform configuration.
//! The types change behavior based on available features, allowing the same code to work efficiently in both `std` and
//! `no_std` environments.
//!
//! # Platform Adaptation
//!
//! - **With `alloc`**: Uses `Cow<'_, str>` for strings and `Cow<'_, [T]>` for lists
//! - **Without `alloc`**: Uses `&str` for strings and `&[T]` for lists
//!
//! This design allows for efficient zero-copy operation in `no_std` environments
//! while providing flexibility for owned data when allocation is available.
//!
//! # Examples
//!
//! ```rust
//! use veecle_telemetry::types::{ListType, StringType, list_from_slice};
//!
//! // StringType adapts to the platform
//! let message: StringType = "Hello, world!".into();
//!
//! // ListType adapts to the platform
//! let data = [1, 2, 3, 4, 5];
//! let list: ListType<'_, i32> = list_from_slice(&data);
//! ```
use Cow;
/// A string type which changes depending on the platform.
///
/// When the `alloc` feature is enabled, this is `Cow<'a, str>` which can hold
/// either borrowed or owned string data.
/// When `alloc` is disabled, this is
/// `&'a str` which only holds borrowed string data.
pub type StringType<'a> = ;
/// A string type which changes depending on the platform.
///
/// When the `alloc` feature is enabled, this is `Cow<'a, str>` which can hold
/// either borrowed or owned string data.
/// When `alloc` is disabled, this is `&'a str` which only holds borrowed string data.
pub type StringType<'a> = &'a str;
/// A list type which changes depending on the platform.
///
/// When the `alloc` feature is enabled, this is `Cow<'a, [T]>` which can hold
/// either borrowed or owned slice data.
/// When `alloc` is disabled, this is `&'a [T]` which only holds borrowed slice data.
pub type ListType<'a, T> = ;
/// A list type which changes depending on the platform.
///
/// When the `alloc` feature is enabled, this is `Cow<'a, [T]>` which can hold
/// either borrowed or owned slice data. When `alloc` is disabled, this is
/// `&'a [T]` which only holds borrowed slice data.
pub type ListType<'a, T> = &'a ;
/// Converts a slice to the currently active [`ListType`].
///
/// This function adapts to the current platform configuration:
/// - With `alloc`: Creates a `Cow::Borrowed` from the slice
/// - Without `alloc`: Returns the slice directly
///
/// # Examples
///
/// ```rust
/// use veecle_telemetry::types::{ListType, list_from_slice};
///
/// let data = [1, 2, 3, 4, 5];
/// let list: ListType<'_, i32> = list_from_slice(&data);
/// assert_eq!(list.len(), 5);
/// ```