1use std::fmt;
12use std::marker::PhantomData;
13use std::ptr;
14
15use crate::source::{
16 ByteOffset, Position, PositionEncoding, PositionError, SourceDocument, SourceId, SourceOrigin,
17 SourceRange,
18};
19use crate::types::{Access, BaseType, Kind, Language, Status};
20
21use super::capability::CapabilityData;
22use super::compliance::ComplianceData;
23use super::group::GroupData;
24use super::mib::Mib;
25use super::module::ModuleData;
26use super::node::NodeData;
27use super::notification::NotificationData;
28use super::object::ObjectData;
29use super::typedef::TypeData;
30use super::types::*;
31
32macro_rules! define_handle {
33 ($name:ident, $id:ident, $data:ident, $getter:ident) => {
34 #[derive(Clone, Copy)]
35 #[doc = concat!("Borrowed handle to a resolved [`", stringify!($data), "`].")]
36 pub struct $name<'a> {
41 pub(crate) mib: &'a Mib,
42 pub(crate) id: $id,
43 }
44
45 impl<'a> $name<'a> {
46 pub(crate) fn new(mib: &'a Mib, id: $id) -> Self {
47 Self { mib, id }
48 }
49
50 pub(crate) fn data(self) -> &'a $data {
51 self.mib.$getter(self.id)
52 }
53
54 pub fn id(self) -> $id {
59 self.id
60 }
61 }
62
63 impl PartialEq for $name<'_> {
64 fn eq(&self, other: &Self) -> bool {
65 self.id == other.id && ptr::eq(self.mib, other.mib)
66 }
67 }
68
69 impl Eq for $name<'_> {}
70
71 impl fmt::Debug for $name<'_> {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 f.debug_struct(stringify!($name))
74 .field("id", &self.id)
75 .field("name", &self.data().name())
76 .finish()
77 }
78 }
79 };
80}
81
82define_handle!(Module, ModuleId, ModuleData, module_data);
83define_handle!(Object, ObjectId, ObjectData, object_data);
84define_handle!(Type, TypeId, TypeData, type_data);
85define_handle!(
86 Notification,
87 NotificationId,
88 NotificationData,
89 notification_data
90);
91define_handle!(Group, GroupId, GroupData, group_data);
92define_handle!(Compliance, ComplianceId, ComplianceData, compliance_data);
93define_handle!(Capability, CapabilityId, CapabilityData, capability_data);
94
95#[derive(Clone, Copy)]
105pub struct Node<'a> {
106 pub(crate) mib: &'a Mib,
107 pub(crate) id: NodeId,
108}
109
110impl<'a> Node<'a> {
111 pub(crate) fn new(mib: &'a Mib, id: NodeId) -> Self {
112 Self { mib, id }
113 }
114
115 pub(crate) fn data(self) -> &'a NodeData {
116 self.mib.node_data(self.id)
117 }
118
119 pub fn id(self) -> NodeId {
121 self.id
122 }
123
124 pub fn arc(self) -> u32 {
126 self.data().arc()
127 }
128
129 pub fn name(self) -> &'a str {
131 self.data().name()
132 }
133
134 pub fn description(self) -> &'a str {
136 self.data().description()
137 }
138
139 pub fn reference(self) -> &'a str {
141 self.data().reference()
142 }
143
144 pub fn status(self) -> Option<Status> {
146 self.data().status()
147 }
148
149 pub fn kind(self) -> Kind {
151 self.data().kind()
152 }
153
154 pub fn range(self) -> Option<SourceRange> {
156 self.data().range()
157 }
158
159 pub fn oid(self) -> &'a super::oid::Oid {
161 self.mib.tree().oid_of(self.id)
162 }
163
164 pub fn parent(self) -> Option<Node<'a>> {
166 self.data().parent().map(|id| Node::new(self.mib, id))
167 }
168
169 pub fn module(self) -> Option<Module<'a>> {
174 self.mib
175 .effective_module(self.id)
176 .map(|id| Module::new(self.mib, id))
177 }
178
179 pub fn object(self) -> Option<Object<'a>> {
181 self.data().object().map(|id| Object::new(self.mib, id))
182 }
183
184 pub fn notification(self) -> Option<Notification<'a>> {
186 self.data()
187 .notification()
188 .map(|id| Notification::new(self.mib, id))
189 }
190
191 pub fn group(self) -> Option<Group<'a>> {
193 self.data().group().map(|id| Group::new(self.mib, id))
194 }
195
196 pub fn compliance(self) -> Option<Compliance<'a>> {
198 self.data()
199 .compliance()
200 .map(|id| Compliance::new(self.mib, id))
201 }
202
203 pub fn capability(self) -> Option<Capability<'a>> {
205 self.data()
206 .capability()
207 .map(|id| Capability::new(self.mib, id))
208 }
209
210 pub fn children(self) -> impl Iterator<Item = Node<'a>> + 'a {
212 self.data()
213 .children()
214 .values()
215 .copied()
216 .map(|id| Node::new(self.mib, id))
217 }
218
219 pub fn subtree(self) -> impl Iterator<Item = Node<'a>> + 'a {
221 self.mib.subtree(self.id).map(|id| Node::new(self.mib, id))
222 }
223}
224
225impl PartialEq for Node<'_> {
226 fn eq(&self, other: &Self) -> bool {
227 self.id == other.id && ptr::eq(self.mib, other.mib)
228 }
229}
230
231impl Eq for Node<'_> {}
232
233impl fmt::Debug for Node<'_> {
234 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
235 f.debug_struct("Node")
236 .field("id", &self.id)
237 .field("name", &self.data().name())
238 .field("kind", &self.data().kind())
239 .finish()
240 }
241}
242
243#[derive(Clone, Copy)]
250pub struct Index<'a> {
251 mib: &'a Mib,
252 row_id: ObjectId,
253 entry: &'a IndexEntry,
254}
255
256impl<'a> Index<'a> {
257 fn new(mib: &'a Mib, row_id: ObjectId, entry: &'a IndexEntry) -> Self {
258 Self { mib, row_id, entry }
259 }
260
261 pub fn row(self) -> Object<'a> {
263 Object::new(self.mib, self.row_id)
264 }
265
266 pub fn object(self) -> Option<Object<'a>> {
268 self.entry.object.map(|id| Object::new(self.mib, id))
269 }
270
271 pub fn name(self) -> &'a str {
276 &self.entry.name
277 }
278
279 pub fn ty(self) -> Option<Type<'a>> {
281 self.entry.type_id.map(|id| Type::new(self.mib, id))
282 }
283
284 pub fn implied(self) -> bool {
286 self.entry.implied
287 }
288
289 pub fn encoding(self) -> crate::types::IndexEncoding {
291 self.entry.encoding
292 }
293
294 pub fn fixed_size(self) -> (usize, bool) {
300 match self.entry.encoding {
301 crate::types::IndexEncoding::Integer => (1, true),
302 crate::types::IndexEncoding::IpAddress => (4, true),
303 crate::types::IndexEncoding::FixedString => {
304 if let Some(obj) = self.object() {
305 let sizes = obj.effective_sizes();
306 if super::types::is_fixed_size(sizes) {
307 return (sizes[0].min.as_u64().unwrap_or(0) as usize, true);
308 }
309 }
310 (0, false)
311 }
312 _ => (0, false),
313 }
314 }
315
316 pub fn range(self) -> SourceRange {
318 self.entry.range
319 }
320
321 pub fn entry(self) -> &'a IndexEntry {
325 self.entry
326 }
327}
328
329impl<'a> Module<'a> {
330 pub fn name(self) -> &'a str {
332 self.data().name()
333 }
334
335 pub fn language(self) -> Language {
340 self.data().language()
341 }
342
343 pub fn source_id(self) -> Option<SourceId> {
345 self.data().source_id()
346 }
347
348 pub fn source(self) -> Option<&'a SourceDocument> {
350 self.source_id().and_then(|id| self.mib.source(id))
351 }
352
353 pub fn source_label(self) -> Option<&'a str> {
355 self.source().map(SourceDocument::label)
356 }
357
358 pub fn source_origin(self) -> Option<&'a SourceOrigin> {
360 self.source().map(SourceDocument::origin)
361 }
362
363 pub fn semantic_at(self, offset: ByteOffset) -> Option<super::SemanticSpan<'a>> {
372 let source = self.source()?;
373 if offset >= source.len() {
374 return None;
375 }
376 self.data().semantic_spans.get(offset)
377 }
378
379 pub fn semantic_at_source(
385 self,
386 source_id: SourceId,
387 offset: ByteOffset,
388 ) -> Option<super::SemanticSpan<'a>> {
389 if self.data().semantic_spans.source_id() != Some(source_id) {
390 return None;
391 }
392 self.semantic_at(offset)
393 }
394
395 pub fn semantic_at_position(
401 self,
402 position: Position,
403 encoding: PositionEncoding,
404 ) -> Result<Option<super::SemanticSpan<'a>>, PositionError> {
405 super::navigation::at_position(
406 &self.data().semantic_spans,
407 self.source(),
408 position,
409 encoding,
410 )
411 }
412
413 pub fn semantic_at_source_position(
419 self,
420 source_id: SourceId,
421 position: Position,
422 encoding: PositionEncoding,
423 ) -> Result<Option<super::SemanticSpan<'a>>, PositionError> {
424 if self.data().semantic_spans.source_id() != Some(source_id) {
425 return Ok(None);
426 }
427 self.semantic_at_position(position, encoding)
428 }
429
430 pub fn organization(self) -> &'a str {
432 self.data().organization()
433 }
434
435 pub fn contact_info(self) -> &'a str {
437 self.data().contact_info()
438 }
439
440 pub fn description(self) -> &'a str {
442 self.data().description()
443 }
444
445 pub fn last_updated(self) -> &'a str {
447 self.data().last_updated()
448 }
449
450 pub fn revisions(self) -> &'a [super::types::Revision] {
452 self.data().revisions()
453 }
454
455 pub fn imports(self) -> &'a [super::types::Import] {
457 self.data().imports()
458 }
459
460 pub fn identities(self) -> &'a [super::module::ModuleIdentityData] {
465 self.data().identities()
466 }
467
468 pub fn is_base(self) -> bool {
474 self.data().is_base()
475 }
476
477 pub fn oid(self) -> Option<&'a super::oid::Oid> {
479 self.data().oid()
480 }
481
482 pub fn imports_symbol(self, name: &str) -> bool {
484 self.data().imports_symbol(name)
485 }
486
487 pub fn import_source(self, name: &str) -> Option<Module<'a>> {
489 self.data()
490 .import_source(name)
491 .map(|id| Module::new(self.mib, id))
492 }
493
494 pub fn import_resolution(self, name: &str) -> Option<&'a super::types::ImportResolution> {
496 self.data().import_resolution(name)
497 }
498
499 pub fn object(self, name: &str) -> Option<Object<'a>> {
501 self.data()
502 .object_by_name(name)
503 .map(|id| Object::new(self.mib, id))
504 }
505
506 pub fn r#type(self, name: &str) -> Option<Type<'a>> {
508 self.data()
509 .type_by_name(name)
510 .map(|id| Type::new(self.mib, id))
511 }
512
513 pub fn node(self, name: &str) -> Option<Node<'a>> {
515 self.data()
516 .node_by_name(name)
517 .map(|id| Node::new(self.mib, id))
518 }
519
520 pub fn notification(self, name: &str) -> Option<Notification<'a>> {
522 self.data()
523 .notification_by_name(name)
524 .map(|id| Notification::new(self.mib, id))
525 }
526
527 pub fn group(self, name: &str) -> Option<Group<'a>> {
529 self.data()
530 .group_by_name(name)
531 .map(|id| Group::new(self.mib, id))
532 }
533
534 pub fn compliance(self, name: &str) -> Option<Compliance<'a>> {
536 self.data()
537 .compliance_by_name(name)
538 .map(|id| Compliance::new(self.mib, id))
539 }
540
541 pub fn capability(self, name: &str) -> Option<Capability<'a>> {
543 self.data()
544 .capability_by_name(name)
545 .map(|id| Capability::new(self.mib, id))
546 }
547
548 pub fn objects(self) -> impl Iterator<Item = Object<'a>> + 'a {
550 self.data()
551 .objects()
552 .iter()
553 .copied()
554 .map(|id| Object::new(self.mib, id))
555 }
556
557 pub fn types(self) -> impl Iterator<Item = Type<'a>> + 'a {
559 self.data()
560 .types()
561 .iter()
562 .copied()
563 .map(|id| Type::new(self.mib, id))
564 }
565
566 pub fn nodes(self) -> impl Iterator<Item = Node<'a>> + 'a {
568 self.data()
569 .nodes()
570 .iter()
571 .copied()
572 .map(|id| Node::new(self.mib, id))
573 }
574}
575
576impl<'a> Object<'a> {
577 pub fn oid_refs(self) -> &'a [OidRef] {
579 self.data().oid_refs()
580 }
581
582 pub fn name(self) -> &'a str {
584 self.data().name()
585 }
586
587 pub fn range(self) -> Option<SourceRange> {
589 self.data().range()
590 }
591
592 pub fn module(self) -> Option<Module<'a>> {
594 self.data().module().map(|id| Module::new(self.mib, id))
595 }
596
597 pub fn node(self) -> Option<Node<'a>> {
599 self.data().node().map(|id| Node::new(self.mib, id))
600 }
601
602 pub fn status(self) -> Status {
604 self.data().status()
605 }
606
607 pub fn description(self) -> &'a str {
609 self.data().description()
610 }
611
612 pub fn reference(self) -> &'a str {
614 self.data().reference()
615 }
616
617 pub fn ty(self) -> Option<Type<'a>> {
619 self.data().type_id().map(|id| Type::new(self.mib, id))
620 }
621
622 pub fn access(self) -> Access {
624 self.data().access()
625 }
626
627 pub fn units(self) -> &'a str {
629 self.data().units()
630 }
631
632 pub fn default_value(self) -> Option<&'a DefVal> {
634 self.data().default_value()
635 }
636
637 pub fn kind(self) -> Kind {
639 self.data().kind(self.mib.tree())
640 }
641
642 pub fn declared_kind(self) -> Kind {
648 self.data().declared_kind()
649 }
650
651 pub fn effective_display_hint(self) -> &'a str {
653 self.data().effective_display_hint()
654 }
655
656 pub fn sizes(self) -> &'a [Range] {
658 self.data().sizes()
659 }
660
661 pub fn declared_sizes(self) -> &'a [Range] {
663 self.data().declared_sizes()
664 }
665
666 pub fn effective_sizes(self) -> &'a [Range] {
668 self.data().effective_sizes()
669 }
670
671 pub fn effective_sizes_constrained(self) -> bool {
673 self.data().effective_sizes_constrained()
674 }
675
676 pub fn ranges(self) -> &'a [Range] {
678 self.data().ranges()
679 }
680
681 pub fn declared_ranges(self) -> &'a [Range] {
683 self.data().declared_ranges()
684 }
685
686 pub fn effective_ranges(self) -> &'a [Range] {
688 self.data().effective_ranges()
689 }
690
691 pub fn effective_ranges_constrained(self) -> bool {
693 self.data().effective_ranges_constrained()
694 }
695
696 pub fn effective_enums(self) -> &'a [NamedValue] {
698 self.data().effective_enums()
699 }
700
701 pub fn effective_bits(self) -> &'a [NamedValue] {
703 self.data().effective_bits()
704 }
705
706 pub fn declared_enums(self) -> &'a [NamedValue] {
708 self.data().declared_enums()
709 }
710
711 pub fn declared_bits(self) -> &'a [NamedValue] {
713 self.data().declared_bits()
714 }
715
716 pub fn sequence_type_name(self) -> &'a str {
719 self.data().sequence_type_name()
720 }
721
722 pub fn declared_table_name(self) -> &'a str {
724 self.data().declared_table_name()
725 }
726
727 pub fn declared_row_name(self) -> &'a str {
729 self.data().declared_row_name()
730 }
731
732 pub fn declared_column_names(self) -> &'a [String] {
734 self.data().declared_column_names()
735 }
736
737 pub fn declared_oid_parent(self) -> Option<&'a OidRef> {
739 self.data().declared_oid_parent()
740 }
741
742 pub fn declared_oid_parent_name(self) -> &'a str {
745 self.data().declared_oid_parent_name()
746 }
747
748 pub fn parsed_display_hint(self) -> Option<super::display_hint::DisplayHint> {
754 let hint = self.data().effective_display_hint();
755 if hint.is_empty() {
756 return None;
757 }
758 super::display_hint::DisplayHint::parse(hint)
759 }
760
761 pub fn format_integer(
766 self,
767 value: i64,
768 hex_case: super::display_hint::HexCase,
769 ) -> Option<String> {
770 let hint = self.data().effective_display_hint();
771 if hint.is_empty() {
772 return None;
773 }
774 super::display_hint::format_integer(hint, value, hex_case)
775 }
776
777 pub fn scale_integer(self, value: i64) -> Option<f64> {
783 let hint = self.data().effective_display_hint();
784 if hint.is_empty() {
785 return None;
786 }
787 super::display_hint::scale_integer(hint, value)
788 }
789
790 pub fn format_octets(
798 self,
799 data: &[u8],
800 hex_case: super::display_hint::HexCase,
801 ) -> Option<String> {
802 let hint = self.data().effective_display_hint();
803 if hint.is_empty() {
804 return None;
805 }
806 super::display_hint::format_octets(hint, data, hex_case)
807 }
808
809 pub fn table(self) -> Option<Object<'a>> {
813 self.mib
814 .object_table(self.id)
815 .map(|id| Object::new(self.mib, id))
816 }
817
818 pub fn row(self) -> Option<Object<'a>> {
823 self.mib
824 .object_row(self.id)
825 .map(|id| Object::new(self.mib, id))
826 }
827
828 pub fn columns(self) -> impl Iterator<Item = Object<'a>> + 'a {
832 self.mib
833 .object_columns(self.id)
834 .into_iter()
835 .map(|id| Object::new(self.mib, id))
836 }
837
838 pub fn augments(self) -> Option<Object<'a>> {
840 self.data().augments().map(|id| Object::new(self.mib, id))
841 }
842
843 pub fn augmented_by(self) -> impl Iterator<Item = Object<'a>> + 'a {
845 self.data()
846 .augmented_by()
847 .iter()
848 .copied()
849 .map(|id| Object::new(self.mib, id))
850 }
851
852 pub fn index(self) -> impl Iterator<Item = Index<'a>> + 'a {
857 self.data()
858 .index()
859 .iter()
860 .map(move |entry| Index::new(self.mib, self.id, entry))
861 }
862
863 pub fn effective_indexes(self) -> impl Iterator<Item = Index<'a>> + 'a {
869 self.mib
870 .effective_indexes_source(self.id)
871 .into_iter()
872 .flat_map(move |id| {
873 self.mib
874 .object_data(id)
875 .index()
876 .iter()
877 .map(move |entry| Index::new(self.mib, self.id, entry))
878 })
879 }
880
881 pub fn is_table(self) -> bool {
883 self.mib.is_table(self.id)
884 }
885
886 pub fn is_row(self) -> bool {
888 self.mib.is_row(self.id)
889 }
890
891 pub fn is_column(self) -> bool {
893 self.mib.is_column(self.id)
894 }
895
896 pub fn is_scalar(self) -> bool {
898 self.mib.is_scalar(self.id)
899 }
900
901 pub fn is_index(self) -> bool {
903 self.mib.is_index(self.id)
904 }
905}
906
907impl<'a> Type<'a> {
908 pub fn name(self) -> &'a str {
910 self.data().name()
911 }
912
913 pub fn range(self) -> Option<SourceRange> {
915 self.data().range()
916 }
917
918 pub fn syntax_range(self) -> Option<SourceRange> {
920 self.data().syntax_range()
921 }
922
923 pub fn module(self) -> Option<Module<'a>> {
925 self.data().module().map(|id| Module::new(self.mib, id))
926 }
927
928 pub fn base(self) -> BaseType {
930 self.data().base()
931 }
932
933 pub fn parent(self) -> Option<Type<'a>> {
935 self.data().parent().map(|id| Type::new(self.mib, id))
936 }
937
938 pub fn status(self) -> Status {
940 self.data().status()
941 }
942
943 pub fn display_hint(self) -> &'a str {
945 self.data().display_hint()
946 }
947
948 pub fn description(self) -> &'a str {
950 self.data().description()
951 }
952
953 pub fn reference(self) -> &'a str {
955 self.data().reference()
956 }
957
958 pub fn sizes(self) -> &'a [Range] {
960 self.data().sizes()
961 }
962
963 pub fn ranges(self) -> &'a [Range] {
965 self.data().ranges()
966 }
967
968 pub fn enums(self) -> &'a [NamedValue] {
970 self.data().enums()
971 }
972
973 pub fn bits(self) -> &'a [NamedValue] {
975 self.data().bits()
976 }
977
978 pub fn is_textual_convention(self) -> bool {
980 self.data().is_textual_convention()
981 }
982
983 pub fn effective_tc(self) -> Option<Type<'a>> {
986 if self.data().is_textual_convention() {
987 return Some(self);
988 }
989 self.data()
990 .effective_tc_in_parents(self.mib.types_slice())
991 .map(|id| Type::new(self.mib, id))
992 }
993
994 pub fn effective_base(self) -> BaseType {
999 self.data().effective_base(self.mib.types_slice())
1000 }
1001
1002 pub fn effective_display_hint(self) -> &'a str {
1004 self.data().effective_display_hint(self.mib.types_slice())
1005 }
1006
1007 pub fn parsed_display_hint(self) -> Option<super::display_hint::DisplayHint> {
1013 let hint = self.data().effective_display_hint(self.mib.types_slice());
1014 if hint.is_empty() {
1015 return None;
1016 }
1017 super::display_hint::DisplayHint::parse(hint)
1018 }
1019
1020 pub fn effective_sizes(self) -> &'a [Range] {
1022 self.data().effective_sizes(self.mib.types_slice())
1023 }
1024
1025 pub fn effective_sizes_constrained(self) -> bool {
1027 self.data().effective_sizes_constrained()
1028 }
1029
1030 pub fn effective_ranges(self) -> &'a [Range] {
1032 self.data().effective_ranges(self.mib.types_slice())
1033 }
1034
1035 pub fn effective_ranges_constrained(self) -> bool {
1037 self.data().effective_ranges_constrained()
1038 }
1039
1040 pub fn effective_enums(self) -> &'a [NamedValue] {
1042 self.data().effective_enums(self.mib.types_slice())
1043 }
1044
1045 pub fn effective_bits(self) -> &'a [NamedValue] {
1047 self.data().effective_bits(self.mib.types_slice())
1048 }
1049
1050 pub fn is_counter(self) -> bool {
1052 self.data().is_counter(self.mib.types_slice())
1053 }
1054
1055 pub fn is_gauge(self) -> bool {
1057 self.data().is_gauge(self.mib.types_slice())
1058 }
1059
1060 pub fn is_string(self) -> bool {
1062 self.data().is_string(self.mib.types_slice())
1063 }
1064
1065 pub fn is_enumeration(self) -> bool {
1067 self.data().is_enumeration(self.mib.types_slice())
1068 }
1069
1070 pub fn is_bits(self) -> bool {
1072 self.data().is_bits(self.mib.types_slice())
1073 }
1074}
1075
1076macro_rules! entity_handle_impl {
1077 ($name:ident) => {
1078 impl<'a> $name<'a> {
1079 pub fn name(self) -> &'a str {
1081 self.data().name()
1082 }
1083
1084 pub fn range(self) -> Option<SourceRange> {
1086 self.data().range()
1087 }
1088
1089 pub fn module(self) -> Option<Module<'a>> {
1091 self.data().module().map(|id| Module::new(self.mib, id))
1092 }
1093
1094 pub fn node(self) -> Option<Node<'a>> {
1096 self.data().node().map(|id| Node::new(self.mib, id))
1097 }
1098
1099 pub fn status(self) -> Status {
1101 self.data().status()
1102 }
1103
1104 pub fn description(self) -> &'a str {
1106 self.data().description()
1107 }
1108
1109 pub fn reference(self) -> &'a str {
1111 self.data().reference()
1112 }
1113
1114 pub fn oid_refs(self) -> &'a [OidRef] {
1116 self.data().oid_refs()
1117 }
1118 }
1119 };
1120}
1121
1122entity_handle_impl!(Notification);
1123entity_handle_impl!(Group);
1124entity_handle_impl!(Compliance);
1125entity_handle_impl!(Capability);
1126
1127impl<'a> Notification<'a> {
1128 pub fn objects(self) -> impl Iterator<Item = Object<'a>> + 'a {
1130 self.data()
1131 .objects()
1132 .iter()
1133 .copied()
1134 .map(|id| Object::new(self.mib, id))
1135 }
1136
1137 pub fn trap_info(self) -> Option<&'a TrapInfo> {
1139 self.data().trap_info()
1140 }
1141}
1142
1143impl<'a> Group<'a> {
1144 pub fn members(self) -> impl Iterator<Item = Node<'a>> + 'a {
1146 self.data()
1147 .members()
1148 .iter()
1149 .copied()
1150 .map(|id| Node::new(self.mib, id))
1151 }
1152
1153 pub fn is_notification_group(self) -> bool {
1155 self.data().is_notification_group()
1156 }
1157}
1158
1159impl<'a> Compliance<'a> {
1160 pub fn modules(self) -> &'a [ComplianceModule] {
1162 self.data().modules()
1163 }
1164}
1165
1166impl<'a> Capability<'a> {
1167 pub fn product_release(self) -> &'a str {
1169 self.data().product_release()
1170 }
1171
1172 pub fn supports(self) -> &'a [CapabilitiesModule] {
1174 self.data().supports()
1175 }
1176}
1177
1178pub struct HandleIter<'a, H, I> {
1184 mib: &'a Mib,
1185 ids: I,
1186 _marker: PhantomData<H>,
1187}
1188
1189impl<'a, H, I> HandleIter<'a, H, I> {
1190 pub(crate) fn new(mib: &'a Mib, ids: I) -> Self {
1191 Self {
1192 mib,
1193 ids,
1194 _marker: PhantomData,
1195 }
1196 }
1197}
1198
1199impl<'a, I> Iterator for HandleIter<'a, Module<'a>, I>
1200where
1201 I: Iterator<Item = ModuleId>,
1202{
1203 type Item = Module<'a>;
1204
1205 fn next(&mut self) -> Option<Self::Item> {
1206 self.ids.next().map(|id| Module::new(self.mib, id))
1207 }
1208}
1209
1210impl<'a, I> Iterator for HandleIter<'a, Object<'a>, I>
1211where
1212 I: Iterator<Item = ObjectId>,
1213{
1214 type Item = Object<'a>;
1215
1216 fn next(&mut self) -> Option<Self::Item> {
1217 self.ids.next().map(|id| Object::new(self.mib, id))
1218 }
1219}
1220
1221impl<'a, I> Iterator for HandleIter<'a, Type<'a>, I>
1222where
1223 I: Iterator<Item = TypeId>,
1224{
1225 type Item = Type<'a>;
1226
1227 fn next(&mut self) -> Option<Self::Item> {
1228 self.ids.next().map(|id| Type::new(self.mib, id))
1229 }
1230}
1231
1232impl<'a, I> Iterator for HandleIter<'a, Node<'a>, I>
1233where
1234 I: Iterator<Item = NodeId>,
1235{
1236 type Item = Node<'a>;
1237
1238 fn next(&mut self) -> Option<Self::Item> {
1239 self.ids.next().map(|id| Node::new(self.mib, id))
1240 }
1241}
1242
1243impl<'a, I> Iterator for HandleIter<'a, Notification<'a>, I>
1244where
1245 I: Iterator<Item = NotificationId>,
1246{
1247 type Item = Notification<'a>;
1248
1249 fn next(&mut self) -> Option<Self::Item> {
1250 self.ids.next().map(|id| Notification::new(self.mib, id))
1251 }
1252}
1253
1254impl<'a, I> Iterator for HandleIter<'a, Group<'a>, I>
1255where
1256 I: Iterator<Item = GroupId>,
1257{
1258 type Item = Group<'a>;
1259
1260 fn next(&mut self) -> Option<Self::Item> {
1261 self.ids.next().map(|id| Group::new(self.mib, id))
1262 }
1263}
1264
1265impl<'a, I> Iterator for HandleIter<'a, Compliance<'a>, I>
1266where
1267 I: Iterator<Item = ComplianceId>,
1268{
1269 type Item = Compliance<'a>;
1270
1271 fn next(&mut self) -> Option<Self::Item> {
1272 self.ids.next().map(|id| Compliance::new(self.mib, id))
1273 }
1274}
1275
1276impl<'a, I> Iterator for HandleIter<'a, Capability<'a>, I>
1277where
1278 I: Iterator<Item = CapabilityId>,
1279{
1280 type Item = Capability<'a>;
1281
1282 fn next(&mut self) -> Option<Self::Item> {
1283 self.ids.next().map(|id| Capability::new(self.mib, id))
1284 }
1285}