File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -260,6 +260,17 @@ impl<'a> RBSString<'a> {
260260 std:: slice:: from_raw_parts ( s. start as * const u8 , s. end . offset_from ( s. start ) as usize )
261261 }
262262 }
263+
264+ #[ must_use]
265+ pub fn as_str ( & self ) -> & str {
266+ unsafe { std:: str:: from_utf8_unchecked ( self . as_bytes ( ) ) }
267+ }
268+ }
269+
270+ impl std:: fmt:: Display for RBSString < ' _ > {
271+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
272+ f. write_str ( self . as_str ( ) )
273+ }
263274}
264275
265276impl SymbolNode < ' _ > {
@@ -314,10 +325,7 @@ mod tests {
314325 && let Node :: LiteralType ( literal) = node. type_ ( )
315326 && let Node :: Integer ( integer) = literal. literal ( )
316327 {
317- assert_eq ! (
318- "1" . to_string( ) ,
319- String :: from_utf8( integer. string_representation( ) . as_bytes( ) . to_vec( ) ) . unwrap( )
320- ) ;
328+ assert_eq ! ( integer. string_representation( ) . as_str( ) , "1" ) ;
321329 } else {
322330 panic ! ( "No literal type node found" ) ;
323331 }
You can’t perform that action at this time.
0 commit comments