1//! Types used in documentation examples.
23use crate::{
4 library::RootModule,
5 sabi_types::VersionStrings,
6 std_types::{ROption, RStr, RString},
7 StableAbi,
8};
910/// 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///
16pub 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)]
25pub second: RStr<'static>,
26///
27pub third: usize,
28}
2930impl RootModule for Module_Ref {
31crate::declare_root_module_statics! {Module_Ref}
32const BASE_NAME: &'static str = "example_root_module";
33const NAME: &'static str = "example_root_module";
34const VERSION_STRINGS: VersionStrings = crate::package_version_strings!();
35}
3637/// 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///
43pub 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)]
52pub second: RStr<'static>,
53///
54pub third: usize,
55///
56pub phantom: std::marker::PhantomData<T>,
57}
5859/// 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)]
69Foo,
70#[allow(missing_docs)]
71Bar,
72#[allow(missing_docs)]
73Tag { name: RString, tag: RString },
74}