11use anyhow:: { bail, Result } ;
2+ use proc_macro2:: Span ;
3+ use serde:: Deserialize ;
24use std:: {
35 collections:: HashMap ,
46 ops:: { Deref , DerefMut } ,
57 path:: { Path , PathBuf } ,
68} ;
9+ use syn:: { punctuated:: Punctuated , Ident } ;
10+
11+ use crate :: util:: path_segment;
712
813#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
914#[ derive( Clone , PartialEq , Eq , Debug , Default ) ]
@@ -323,6 +328,7 @@ pub enum IdentFormatsTheme {
323328pub struct Settings {
324329 /// Path to chip HTML generated by svdtools
325330 pub html_url : Option < url:: Url > ,
331+ pub crate_path : Option < CratePath > ,
326332 /// RISC-V specific settings
327333 pub riscv_config : Option < riscv:: RiscvConfig > ,
328334}
@@ -332,10 +338,37 @@ impl Settings {
332338 if source. html_url . is_some ( ) {
333339 self . html_url = source. html_url ;
334340 }
341+ if source. crate_path . is_some ( ) {
342+ self . crate_path = source. crate_path ;
343+ }
335344 if source. riscv_config . is_some ( ) {
336345 self . riscv_config = source. riscv_config ;
337346 }
338347 }
339348}
340349
350+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
351+ pub struct CratePath ( pub syn:: Path ) ;
352+
353+ impl Default for CratePath {
354+ fn default ( ) -> Self {
355+ let mut segments = Punctuated :: new ( ) ;
356+ segments. push ( path_segment ( Ident :: new ( "crate" , Span :: call_site ( ) ) ) ) ;
357+ Self ( syn:: Path {
358+ leading_colon : None ,
359+ segments,
360+ } )
361+ }
362+ }
363+
364+ impl < ' de > Deserialize < ' de > for CratePath {
365+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
366+ where
367+ D : serde:: Deserializer < ' de > ,
368+ {
369+ let string = String :: deserialize ( deserializer) ?;
370+ Ok ( Self ( syn:: parse_str ( & string) . unwrap ( ) ) )
371+ }
372+ }
373+
341374pub mod riscv;
0 commit comments