11use anyhow:: { bail, Result } ;
2+ use proc_macro2:: Span ;
23use std:: {
34 collections:: HashMap ,
45 ops:: { Deref , DerefMut } ,
56 path:: { Path , PathBuf } ,
7+ str:: FromStr ,
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,45 @@ 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+ #[ cfg( feature = "serde" ) ]
365+ impl < ' de > serde:: Deserialize < ' de > for CratePath {
366+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
367+ where
368+ D : serde:: Deserializer < ' de > ,
369+ {
370+ let s = String :: deserialize ( deserializer) ?;
371+ Ok ( Self :: from_str ( & s) . unwrap ( ) )
372+ }
373+ }
374+
375+ impl FromStr for CratePath {
376+ type Err = syn:: Error ;
377+ fn from_str ( s : & str ) -> std:: result:: Result < Self , Self :: Err > {
378+ syn:: parse_str ( & s) . map ( Self )
379+ }
380+ }
381+
341382pub mod riscv;
0 commit comments