Skip to main content

yapi_types/
lib.rs

1#![doc = env!("CARGO_PKG_DESCRIPTION")]
2//!
3//! A pi file is handled as a document: an order-preserving [`serde_json::Value`]
4//! that [`json`] writes back byte-identically. pi's key order depends on the code
5//! path that built an object, so the typed structs here are views: they read
6//! fields from a document and build new objects in pi's usual key order.
7#![forbid(unsafe_code)]
8
9pub mod auth;
10pub mod autocomplete;
11pub mod classify;
12pub mod collate;
13pub mod config;
14pub mod event;
15pub mod extension_event;
16pub mod js;
17pub mod json;
18pub mod message;
19pub mod model;
20pub mod models;
21pub mod rpc;
22pub mod session;
23pub mod settings;
24pub mod sync;
25pub mod system_prompt;
26pub mod time;
27
28use serde::{Deserialize, Deserializer};
29
30/// Deserializes a field that pi writes as a value, as `null`, or not at all: a
31/// present key becomes `Some`, even when `null`. Combine with `#[serde(default)]`
32/// for the absent case and `skip_serializing_if = "Option::is_none"` to omit it.
33pub(crate) fn present<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
34where
35    D: Deserializer<'de>,
36    T: Deserialize<'de>,
37{
38    T::deserialize(deserializer).map(Some)
39}