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 } ,
8+ str:: FromStr ,
69} ;
10+ use syn:: { punctuated:: Punctuated , Ident } ;
11+
12+ use crate :: util:: path_segment;
713
814#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
915#[ derive( Clone , PartialEq , Eq , Debug , Default ) ]
@@ -323,6 +329,7 @@ pub enum IdentFormatsTheme {
323329pub struct Settings {
324330 /// Path to chip HTML generated by svdtools
325331 pub html_url : Option < url:: Url > ,
332+ pub crate_path : Option < CratePath > ,
326333 /// RISC-V specific settings
327334 pub riscv_config : Option < riscv:: RiscvConfig > ,
328335}
@@ -332,10 +339,44 @@ impl Settings {
332339 if source. html_url . is_some ( ) {
333340 self . html_url = source. html_url ;
334341 }
342+ if source. crate_path . is_some ( ) {
343+ self . crate_path = source. crate_path ;
344+ }
335345 if source. riscv_config . is_some ( ) {
336346 self . riscv_config = source. riscv_config ;
337347 }
338348 }
339349}
340350
351+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
352+ pub struct CratePath ( pub syn:: Path ) ;
353+
354+ impl Default for CratePath {
355+ fn default ( ) -> Self {
356+ let mut segments = Punctuated :: new ( ) ;
357+ segments. push ( path_segment ( Ident :: new ( "crate" , Span :: call_site ( ) ) ) ) ;
358+ Self ( syn:: Path {
359+ leading_colon : None ,
360+ segments,
361+ } )
362+ }
363+ }
364+
365+ impl < ' de > 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