@@ -38,6 +38,13 @@ pub struct SchemaSubmodule<'a> {
3838 pub ( crate ) raw : * mut ffi:: lysp_submodule ,
3939}
4040
41+ /// Available YANG schema tree structures representing YANG import.
42+ #[ derive( Clone , Debug ) ]
43+ pub struct SchemaImport < ' a > {
44+ pub ( crate ) context : & ' a Context ,
45+ pub ( crate ) raw : * mut ffi:: lysp_import ,
46+ }
47+
4148/// Schema input formats accepted by libyang.
4249#[ allow( clippy:: upper_case_acronyms) ]
4350#[ repr( u32 ) ]
@@ -443,6 +450,17 @@ impl<'a> SchemaModule<'a> {
443450 self . notifications ( ) . flat_map ( |snode| snode. traverse ( ) ) ;
444451 data. chain ( rpcs) . chain ( notifications)
445452 }
453+
454+ /// Returns an iterator over the list of imports.
455+ pub fn imports ( & self ) -> impl Iterator < Item = SchemaImport < ' a > > {
456+ let parsed = unsafe { ( * self . raw ) . parsed } ;
457+ if parsed. is_null ( ) {
458+ return Array :: new ( self . context , std:: ptr:: null_mut ( ) , 0 ) ;
459+ }
460+ let array = unsafe { ( * parsed) . imports } ;
461+ let ptr_size = mem:: size_of :: < ffi:: lysp_import > ( ) ;
462+ Array :: new ( self . context , array as * mut _ , ptr_size)
463+ }
446464}
447465
448466unsafe impl < ' a > Binding < ' a > for SchemaModule < ' a > {
@@ -529,6 +547,51 @@ impl PartialEq for SchemaSubmodule<'_> {
529547unsafe impl Send for SchemaSubmodule < ' _ > { }
530548unsafe impl Sync for SchemaSubmodule < ' _ > { }
531549
550+ // ===== impl SchemaImport =====
551+
552+ impl < ' a > SchemaImport < ' a > {
553+ /// Import Module.
554+ pub fn module ( & self ) -> SchemaModule < ' _ > {
555+ let module = unsafe { ( * self . raw ) . module } ;
556+ unsafe { SchemaModule :: from_raw ( self . context , module) }
557+ }
558+
559+ /// Import module name.
560+ pub fn name ( & self ) -> & str {
561+ char_ptr_to_str ( unsafe { ( * self . raw ) . name } )
562+ }
563+
564+ /// Prefix used to reference definitions from the import module.
565+ pub fn prefix ( & self ) -> & str {
566+ char_ptr_to_str ( unsafe { ( * self . raw ) . prefix } )
567+ }
568+
569+ /// Description of the import.
570+ pub fn description ( & self ) -> Option < & str > {
571+ char_ptr_to_opt_str ( unsafe { ( * self . raw ) . dsc } )
572+ }
573+
574+ /// Cross-reference for the import.
575+ pub fn reference ( & self ) -> Option < & str > {
576+ char_ptr_to_opt_str ( unsafe { ( * self . raw ) . ref_ } )
577+ }
578+ }
579+
580+ unsafe impl < ' a > Binding < ' a > for SchemaImport < ' a > {
581+ type CType = ffi:: lysp_import ;
582+ type Container = Context ;
583+
584+ unsafe fn from_raw (
585+ context : & ' a Context ,
586+ raw : * mut ffi:: lysp_import ,
587+ ) -> SchemaImport < ' a > {
588+ SchemaImport { context, raw }
589+ }
590+ }
591+
592+ unsafe impl Send for SchemaImport < ' _ > { }
593+ unsafe impl Sync for SchemaImport < ' _ > { }
594+
532595// ===== impl SchemaNode =====
533596
534597impl < ' a > SchemaNode < ' a > {
0 commit comments