proxmox/proxmox-schema/src/lib.rs
Wolfgang Bumiller 5a64f3258a schema: serde based property string de- and serialization
This provides `proxmox_schema::property_string::PropertyString<T>` for
a typed property-string.

To facilitate this, this introduces
`proxmox_schema:🇩🇪:SchemaDeserializer` which is a serde deserializer
for property strings given a schema.

This basically maps to one of `de::SeqAccess` (for array schemas) or
`de::MapAccess` (for object schemas).

Additionally, a `de::NoSchemaDeserializer` is added, since properties
within the strings may have string schemas with no format to it, while
the type we serialize to may ask for an array (a simple "list") via
serde.

The deserializers support borrowing, for which a helper `Cow3` needed
to be added, since property strings support quoting with escape
sequences where an intermediate string would be allocated and with an
intermediate lifetime distinct from the `'de` lifetime.

A `de::verify` module is added which uses serde infrastructure to
validate schemas without first having to deserialize a complete
`serde_json::Value`.

For serialization, `proxmox_schema::ser::PropertyStringSerializer` is
added split into similar parts `ser::SerializeStruct` and
`ser::SerializeSeq` at the top level, and the same prefixed with
`Element` for inside the actual string. This should also properly
quote the contents if required.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:18:58 +02:00

41 lines
977 B
Rust

//! Proxmox schema module.
//!
//! This provides utilities to define APIs in a declarative way using
//! Schemas. Primary use case it to define REST/HTTP APIs. Another use case
//! is to define command line tools using Schemas. Finally, it is
//! possible to use schema definitions to derive configuration file
//! parsers.
#![deny(unsafe_op_in_unsafe_fn)]
#[cfg(feature = "api-macro")]
pub use proxmox_api_macro::api;
mod api_type_macros;
#[macro_use]
mod const_regex;
pub use const_regex::ConstRegexPattern;
pub mod de;
pub mod format;
pub mod ser;
pub mod property_string;
mod schema;
pub use schema::*;
pub mod upid;
// const_regex uses lazy_static, but we otherwise don't need it, and don't want to force users to
// have to write it out in their Cargo.toml as dependency, so we add a hidden re-export here which
// is semver-exempt!
#[doc(hidden)]
pub mod semver_exempt {
pub use lazy_static::lazy_static;
}
#[cfg(feature = "api-types")]
pub mod api_types;