abi_stable/
for_examples.rs

1//! Types used in documentation examples.
2
3use crate::{
4    library::RootModule,
5    sabi_types::VersionStrings,
6    std_types::{ROption, RStr, RString},
7    StableAbi,
8};
9
10/// This type is used in prefix type examples.
11#[repr(C)]
12#[derive(StableAbi)]
13#[sabi(kind(Prefix(prefix_ref = Module_Ref, prefix_fields = Module_Prefix)))]
14pub struct Module {
15    ///
16    pub first: ROption<usize>,
17    // The `#[sabi(last_prefix_field)]` attribute here means that this is
18    // the last field in this struct that was defined in the
19    // first compatible version of the library,
20    // requiring new fields to always be added after it.
21    // Moving this attribute is a breaking change, it can only be done in a
22    // major version bump..
23    ///
24    #[sabi(last_prefix_field)]
25    pub second: RStr<'static>,
26    ///
27    pub third: usize,
28}
29
30impl RootModule for Module_Ref {
31    crate::declare_root_module_statics! {Module_Ref}
32    const BASE_NAME: &'static str = "example_root_module";
33    const NAME: &'static str = "example_root_module";
34    const VERSION_STRINGS: VersionStrings = crate::package_version_strings!();
35}
36
37/// This type is used in prefix type examples.
38#[repr(C)]
39#[derive(StableAbi)]
40#[sabi(kind(Prefix(prefix_ref = PhantModule_Ref, prefix_fields = PhantModule_Prefix)))]
41pub struct PhantModule<T: Copy> {
42    ///
43    pub first: ROption<usize>,
44    ///
45    // The `#[sabi(last_prefix_field)]` attribute here means that this is
46    // the last field in this struct that was defined in the
47    // first compatible version of the library,
48    // requiring new fields to always be added after it.
49    // Moving this attribute is a breaking change, it can only be done in a
50    // major version bump..
51    #[sabi(last_prefix_field)]
52    pub second: RStr<'static>,
53    ///
54    pub third: usize,
55    ///
56    pub phantom: std::marker::PhantomData<T>,
57}
58
59/// For demonstrating ffi-safe non-exhaustive enums.
60#[repr(u8)]
61// #[derive(Debug,Clone,PartialEq)]
62// #[sabi(debug_print)]
63#[derive(StableAbi, Debug, Clone, PartialEq, Eq)]
64#[sabi(kind(WithNonExhaustive(size = [usize;10], traits(Debug, Clone, PartialEq),)))]
65#[sabi(with_constructor)]
66#[non_exhaustive]
67pub enum ValidTag {
68    #[allow(missing_docs)]
69    Foo,
70    #[allow(missing_docs)]
71    Bar,
72    #[allow(missing_docs)]
73    Tag { name: RString, tag: RString },
74}