11use super :: static_int_str;
2+ #[ cfg( feature = "unstable_static_encoding_str" ) ]
3+ use super :: Encode ;
24use super :: Encoding ;
35
46impl < ' a > Encoding < ' a > {
5- const fn end_str_len ( self ) -> usize {
7+ #[ doc( hidden) ]
8+ pub const fn end_str_len ( self ) -> usize {
69 use Encoding :: * ;
710
811 match self {
@@ -26,7 +29,8 @@ impl<'a> Encoding<'a> {
2629 }
2730 }
2831
29- const fn get_str_array < const LEN : usize > ( self ) -> [ u8 ; LEN ] {
32+ #[ doc( hidden) ]
33+ pub const fn get_str_array < const LEN : usize > ( self ) -> [ u8 ; LEN ] {
3034 use Encoding :: * ;
3135
3236 let mut res: [ u8 ; LEN ] = [ 0 ; LEN ] ;
@@ -156,16 +160,47 @@ impl<'a> Encoding<'a> {
156160 res
157161 }
158162
159- const fn end_cstr_len ( self ) -> usize {
163+ #[ doc( hidden) ]
164+ pub const fn end_cstr_len ( self ) -> usize {
160165 self . end_str_len ( ) + 1
161166 }
162167
163- const fn get_cstr_array < const RES : usize > ( self ) -> [ u8 ; RES ] {
168+ #[ doc( hidden) ]
169+ pub const fn get_cstr_array < const RES : usize > ( self ) -> [ u8 ; RES ] {
164170 // Contains nul byte at the end
165171 self . get_str_array ( )
166172 }
167173}
168174
175+ /// Workaround since we can't specify the correct `where` bound on `Encode`.
176+ #[ cfg( feature = "unstable_static_encoding_str" ) ]
177+ pub struct EncodingHelper < T > ( T ) ;
178+
179+ #[ cfg( feature = "unstable_static_encoding_str" ) ]
180+ impl < T : super :: Encode > EncodingHelper < T >
181+ where
182+ [ u8 ; T :: ENCODING . end_cstr_len ( ) ] : Sized ,
183+ {
184+ #[ doc( hidden) ]
185+ const __ENCODING_CSTR_BYTES: [ u8 ; T :: ENCODING . end_cstr_len ( ) ] = T :: ENCODING . get_cstr_array ( ) ;
186+
187+ /// TODO
188+ pub const ENCODING_CSTR : * const u8 = Self :: __ENCODING_CSTR_BYTES. as_ptr ( ) ;
189+ }
190+
191+ #[ cfg( feature = "unstable_static_encoding_str" ) ]
192+ impl < T : Encode > EncodingHelper < T >
193+ where
194+ [ u8 ; T :: ENCODING . end_str_len ( ) ] : Sized ,
195+ {
196+ #[ doc( hidden) ]
197+ const __ENCODING_STR_BYTES: [ u8 ; T :: ENCODING . end_str_len ( ) ] = T :: ENCODING . get_str_array ( ) ;
198+
199+ /// TODO
200+ pub const ENCODING_STR : & ' static str =
201+ unsafe { core:: mem:: transmute :: < & [ u8 ] , & str > ( & Self :: __ENCODING_STR_BYTES) } ;
202+ }
203+
169204#[ cfg( test) ]
170205mod tests {
171206 use super :: Encoding ;
0 commit comments