33// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44use std:: fmt;
55
6+ // To ensure we don't use stdlib allocating types by accident
7+ #[ allow( dead_code) ]
8+ struct Vec ;
9+ #[ allow( dead_code) ]
10+ struct Box ;
11+ #[ allow( dead_code) ]
12+ struct HashMap ;
13+ #[ allow( dead_code) ]
14+ struct String ;
15+
616macro_rules! box_database {
717 ( $( $boxenum: ident $boxtype: expr) ,* , ) => {
818 #[ derive( Clone , Copy , PartialEq ) ]
@@ -42,24 +52,14 @@ macro_rules! box_database {
4252
4353#[ derive( Default , PartialEq , Clone ) ]
4454pub struct FourCC {
45- pub value : String ,
55+ pub value : [ u8 ; 4 ] ,
4656}
4757
4858impl From < u32 > for FourCC {
4959 fn from ( number : u32 ) -> FourCC {
50- let mut box_chars = Vec :: new ( ) ;
51- for x in 0 ..4 {
52- let c = ( number >> ( x * 8 ) & 0x0000_00FF ) as u8 ;
53- box_chars. push ( c) ;
60+ FourCC {
61+ value : number. to_be_bytes ( ) ,
5462 }
55- box_chars. reverse ( ) ;
56-
57- let box_string = match String :: from_utf8 ( box_chars) {
58- Ok ( t) => t,
59- _ => String :: from ( "null" ) , // error to retrieve fourcc
60- } ;
61-
62- FourCC { value : box_string }
6363 }
6464}
6565
@@ -70,23 +70,27 @@ impl From<BoxType> for FourCC {
7070 }
7171}
7272
73- impl < ' a > From < & ' a str > for FourCC {
74- fn from ( v : & ' a str ) -> FourCC {
75- FourCC {
76- value : v. to_owned ( ) ,
77- }
73+ impl From < [ u8 ; 4 ] > for FourCC {
74+ fn from ( v : [ u8 ; 4 ] ) -> FourCC {
75+ FourCC { value : v }
7876 }
7977}
8078
8179impl fmt:: Debug for FourCC {
8280 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
83- write ! ( f, "{}" , self . value)
81+ match std:: str:: from_utf8 ( & self . value ) {
82+ Ok ( s) => write ! ( f, "{}" , s) ,
83+ Err ( _) => self . value . fmt ( f) ,
84+ }
8485 }
8586}
8687
8788impl fmt:: Display for FourCC {
8889 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
89- write ! ( f, "{}" , self . value)
90+ match std:: str:: from_utf8 ( & self . value ) {
91+ Ok ( s) => write ! ( f, "{}" , s) ,
92+ Err ( _) => write ! ( f, "null" ) ,
93+ }
9094 }
9195}
9296
0 commit comments