|
19 | 19 | //! ## `rkyv_0_8` |
20 | 20 | //! |
21 | 21 | //! We expose a `rkyv_0_8` feature, disabled by default. When enabled, it derives `rkyv`'s |
22 | | -//! [`Archive`](rkyv::Archive), [`Serialize`](rkyv::Serialize) and [`Deserialize`](rkyv::Deserialize) |
23 | | -//! traits for all types in this crate. Furthermore, it exposes the corresponding `Archived*` types |
24 | | -//! (e.g. [`ArchivedId`] for [`Id`]). |
| 22 | +//! [`Archive`][3], [`Serialize`][4] and [`Deserialize`][5] traits for all types in this crate. |
| 23 | +//! Furthermore, it exposes the corresponding `Archived*` types (e.g. `ArchivedId` for [`Id`]). |
25 | 24 | //! |
26 | 25 | //! `rkyv` lets you works with JSON output without paying the deserialization cost _upfront_, |
27 | | -//! thanks to [zero-copy deserialization][3]. |
| 26 | +//! thanks to [zero-copy deserialization][6]. |
28 | 27 | //! You can perform various types of analyses on the `Archived*` version of the relevant types, |
29 | 28 | //! incurring the full deserialization cost only for the subset of items you actually need. |
30 | 29 | //! |
31 | 30 | //! [1]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/rustc-hash.20and.20performance.20of.20rustdoc-types/near/474855731 |
32 | 31 | //! [2]: https://crates.io/crates/rustc-hash |
33 | | -//! [3]: https://rkyv.org/zero-copy-deserialization.html |
| 32 | +//! [3]: https://docs.rs/rkyv/0.8.15/rkyv/trait.Archive.html |
| 33 | +//! [4]: https://docs.rs/rkyv/0.8.15/rkyv/trait.Serialize.html |
| 34 | +//! [5]: https://docs.rs/rkyv/0.8.15/rkyv/trait.Deserialize.html |
| 35 | +//! [6]: https://rkyv.org/zero-copy-deserialization.html |
34 | 36 |
|
35 | 37 | // # On `rkyv` Derives |
36 | 38 | // |
@@ -827,6 +829,45 @@ pub enum ItemEnum { |
827 | 829 | }, |
828 | 830 | } |
829 | 831 |
|
| 832 | +impl ItemEnum { |
| 833 | + /// Get just the kind of this item, but with no further data. |
| 834 | + /// |
| 835 | + /// ```rust |
| 836 | + /// # use rustdoc_json_types::{ItemKind, ItemEnum}; |
| 837 | + /// let item = ItemEnum::ExternCrate { name: "libc".to_owned(), rename: None }; |
| 838 | + /// assert_eq!(item.item_kind(), ItemKind::ExternCrate); |
| 839 | + /// ``` |
| 840 | + pub fn item_kind(&self) -> ItemKind { |
| 841 | + match self { |
| 842 | + ItemEnum::Module(_) => ItemKind::Module, |
| 843 | + ItemEnum::ExternCrate { .. } => ItemKind::ExternCrate, |
| 844 | + ItemEnum::Use(_) => ItemKind::Use, |
| 845 | + ItemEnum::Union(_) => ItemKind::Union, |
| 846 | + ItemEnum::Struct(_) => ItemKind::Struct, |
| 847 | + ItemEnum::StructField(_) => ItemKind::StructField, |
| 848 | + ItemEnum::Enum(_) => ItemKind::Enum, |
| 849 | + ItemEnum::Variant(_) => ItemKind::Variant, |
| 850 | + ItemEnum::Function(_) => ItemKind::Function, |
| 851 | + ItemEnum::Trait(_) => ItemKind::Trait, |
| 852 | + ItemEnum::TraitAlias(_) => ItemKind::TraitAlias, |
| 853 | + ItemEnum::Impl(_) => ItemKind::Impl, |
| 854 | + ItemEnum::TypeAlias(_) => ItemKind::TypeAlias, |
| 855 | + ItemEnum::Constant { .. } => ItemKind::Constant, |
| 856 | + ItemEnum::Static(_) => ItemKind::Static, |
| 857 | + ItemEnum::ExternType => ItemKind::ExternType, |
| 858 | + ItemEnum::Macro(_) => ItemKind::Macro, |
| 859 | + ItemEnum::ProcMacro(pm) => match pm.kind { |
| 860 | + MacroKind::Bang => ItemKind::Macro, |
| 861 | + MacroKind::Attr => ItemKind::ProcAttribute, |
| 862 | + MacroKind::Derive => ItemKind::ProcDerive, |
| 863 | + }, |
| 864 | + ItemEnum::Primitive(_) => ItemKind::Primitive, |
| 865 | + ItemEnum::AssocConst { .. } => ItemKind::AssocConst, |
| 866 | + ItemEnum::AssocType { .. } => ItemKind::AssocType, |
| 867 | + } |
| 868 | + } |
| 869 | +} |
| 870 | + |
830 | 871 | /// A module declaration, e.g. `mod foo;` or `mod foo {}`. |
831 | 872 | #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] |
832 | 873 | #[cfg_attr(feature = "rkyv_0_8", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] |
@@ -982,10 +1023,10 @@ pub enum VariantKind { |
982 | 1023 | /// } |
983 | 1024 | /// ``` |
984 | 1025 | Struct { |
985 | | - /// The list of variants in the enum. |
986 | | - /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Variant`]. |
| 1026 | + /// The list of named fields in the variant. |
| 1027 | + /// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`]. |
987 | 1028 | fields: Vec<Id>, |
988 | | - /// Whether any variants have been removed from the result, due to being private or hidden. |
| 1029 | + /// Whether any fields have been removed from the result, due to being private or hidden. |
989 | 1030 | has_stripped_fields: bool, |
990 | 1031 | }, |
991 | 1032 | } |
|
0 commit comments