File tree 3 files changed +43
-1
lines changed
3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -18,5 +18,9 @@ repository = "https://github.com/madsmtm/objc2"
18
18
documentation = " https://docs.rs/objc2-encode/"
19
19
license = " MIT"
20
20
21
+ [features ]
22
+ # Requires the `generic_const_exprs` feature
23
+ unstable-static-encoding-str = []
24
+
21
25
[package .metadata .docs .rs ]
22
26
default-target = " x86_64-apple-darwin"
Original file line number Diff line number Diff line change 92
92
#![ deny( unsafe_op_in_unsafe_fn) ]
93
93
// Update in Cargo.toml as well.
94
94
#![ doc( html_root_url = "https://docs.rs/objc2-encode/2.0.0-beta.2" ) ]
95
+ #![ cfg_attr( feature = "unstable-static-encoding-str" , allow( incomplete_features) ) ]
96
+ #![ cfg_attr( feature = "unstable-static-encoding-str" , feature( generic_const_exprs) ) ]
95
97
96
98
#[ cfg( doctest) ]
97
99
#[ doc = include_str ! ( "../README.md" ) ]
@@ -108,8 +110,10 @@ mod encoding;
108
110
mod parse;
109
111
110
112
// Will be used at some point when generic constants are available
111
- #[ allow( dead_code) ]
113
+ #[ cfg_attr ( not ( feature = "unstable-static-encoding-str" ) , allow( dead_code) ) ]
112
114
mod static_str;
113
115
114
116
pub use self :: encode:: { Encode , EncodeArguments , RefEncode } ;
115
117
pub use self :: encoding:: Encoding ;
118
+ #[ cfg( feature = "unstable-static-encoding-str" ) ]
119
+ pub use self :: static_str:: EncodingHelper ;
Original file line number Diff line number Diff line change
1
+ #[ cfg( feature = "unstable-static-encoding-str" ) ]
2
+ use super :: Encode ;
1
3
use super :: Encoding ;
2
4
3
5
pub ( crate ) const fn static_int_str_len ( mut n : u128 ) -> usize {
@@ -205,6 +207,38 @@ pub(crate) const fn static_encoding_str_array<const LEN: usize>(
205
207
res
206
208
}
207
209
210
+ /// Workaround since we can't specify the correct `where` bound on `Encode`.
211
+ #[ cfg( feature = "unstable-static-encoding-str" ) ]
212
+ pub struct EncodingHelper < T > ( T ) ;
213
+
214
+ #[ cfg( feature = "unstable-static-encoding-str" ) ]
215
+ impl < T : super :: Encode > EncodingHelper < T >
216
+ where
217
+ [ u8 ; static_encoding_str_len ( T :: ENCODING ) + 1 ] : Sized ,
218
+ {
219
+ #[ doc( hidden) ]
220
+ // Contains null byte at the end
221
+ const __ENCODING_CSTR_BYTES: [ u8 ; static_encoding_str_len ( T :: ENCODING ) + 1 ] =
222
+ static_encoding_str_array ( T :: ENCODING ) ;
223
+
224
+ /// TODO
225
+ pub const ENCODING_CSTR : * const u8 = Self :: __ENCODING_CSTR_BYTES. as_ptr ( ) ;
226
+ }
227
+
228
+ #[ cfg( feature = "unstable-static-encoding-str" ) ]
229
+ impl < T : Encode > EncodingHelper < T >
230
+ where
231
+ [ u8 ; static_encoding_str_len ( T :: ENCODING ) ] : Sized ,
232
+ {
233
+ #[ doc( hidden) ]
234
+ const __ENCODING_STR_BYTES: [ u8 ; static_encoding_str_len ( T :: ENCODING ) ] =
235
+ static_encoding_str_array ( T :: ENCODING ) ;
236
+
237
+ /// TODO
238
+ pub const ENCODING_STR : & ' static str =
239
+ unsafe { core:: mem:: transmute :: < & [ u8 ] , & str > ( & Self :: __ENCODING_STR_BYTES) } ;
240
+ }
241
+
208
242
#[ cfg( test) ]
209
243
mod tests {
210
244
use super :: * ;
You can’t perform that action at this time.
0 commit comments