@@ -447,7 +447,7 @@ impl StructElement<'_> {
447447 /// dictionary. You can create this dictionary by using [`Chunk::namespace`]
448448 /// and then calling [`Namespace::pdf_2_ns`] on the returned writer.
449449 pub fn kind_2 ( & mut self , role : StructRole2 , pdf_2_ns : Ref ) -> & mut Self {
450- self . dict . pair ( Name ( b"S" ) , Name ( role. to_name_bytes ( & mut [ 0 ; 6 ] ) ) ) ;
450+ self . dict . pair ( Name ( b"S" ) , role. to_name ( & mut [ 0 ; 6 ] ) ) ;
451451 self . namespace ( pdf_2_ns)
452452 }
453453
@@ -1178,8 +1178,12 @@ pub enum StructRole2 {
11781178}
11791179
11801180impl StructRole2 {
1181- pub ( crate ) fn to_name_bytes ( self , buf : & mut [ u8 ; 6 ] ) -> & [ u8 ] {
1182- match self {
1181+ /// Convert the role into its [`Name`] serialization.
1182+ ///
1183+ /// The `buf` parameter is a mutable buffer of 6 bytes that will be used to
1184+ /// store the name in the event that the role is a heading with a level.
1185+ pub fn to_name ( self , buf : & mut [ u8 ; 6 ] ) -> Name < ' _ > {
1186+ Name ( match self {
11831187 Self :: Document => b"Document" ,
11841188 Self :: DocumentFragment => b"DocumentFragment" ,
11851189 Self :: Part => b"Part" ,
@@ -1226,7 +1230,7 @@ impl StructRole2 {
12261230 Self :: Figure => b"Figure" ,
12271231 Self :: Formula => b"Formula" ,
12281232 Self :: Artifact => b"Artifact" ,
1229- }
1233+ } )
12301234 }
12311235
12321236 /// How the type should be represented in PDF 1.7.
@@ -1601,7 +1605,7 @@ impl NamespaceRoleMap<'_> {
16011605 pdf_2_ns : Ref ,
16021606 ) -> & mut Self {
16031607 let mut dict = self . dict . insert ( name) . dict ( ) ;
1604- dict. pair ( Name ( b"Role" ) , Name ( role. to_name_bytes ( & mut [ 0 ; 6 ] ) ) ) ;
1608+ dict. pair ( Name ( b"Role" ) , role. to_name ( & mut [ 0 ; 6 ] ) ) ;
16051609 dict. pair ( Name ( b"NS" ) , pdf_2_ns) ;
16061610 dict. finish ( ) ;
16071611 self
@@ -2393,7 +2397,7 @@ mod tests {
23932397 #[ test]
23942398 fn test_max_heading_name ( ) {
23952399 let mut buf = [ 0 ; 6 ] ;
2396- let name = Name ( StructRole2 :: Heading ( NonZeroU16 :: MAX ) . to_name_bytes ( & mut buf) ) ;
2400+ let name = StructRole2 :: Heading ( NonZeroU16 :: MAX ) . to_name ( & mut buf) ;
23972401 assert_eq ! ( Name ( b"H65535" ) , name) ;
23982402 }
23992403}
0 commit comments