ocpi_kit/types/mod.rs
1//! The scalar and leaf types the whole specification is built from.
2//!
3//! These are version-neutral: OCPI 2.1.1, 2.2.1 and 2.3.0 agree on what a `CiString`, a
4//! `DateTime`, a `number` and a `DisplayText` are. Types that *changed* between versions —
5//! `Price`, `Role`, `Tariff` — live in the per-version modules instead.
6//!
7//! Nothing here needs an async runtime or an HTTP stack, so this layer compiles for
8//! `wasm32-unknown-unknown` and can back browser tooling and edge workers.
9//!
10//! # The three rules
11//!
12//! 1. **Parse permissively.** `Deserialize` never fails because a peer overran a length limit.
13//! 2. **Validate explicitly.** [`Validate::validate`] reports every deviation, with a JSON
14//! Pointer to it.
15//! 3. **Construct strictly.** `new` and `FromStr` refuse to build a non-conformant value, so
16//! what this crate emits is conformant.
17//!
18//! See [`validate`] for why.
19
20pub mod cistring;
21pub mod datetime;
22pub mod display_text;
23pub mod extensions;
24pub mod ids;
25pub mod local;
26pub mod number;
27pub mod open_enum;
28pub mod string;
29pub mod url;
30pub mod validate;
31
32mod text;
33
34pub use cistring::CiString;
35pub use datetime::{DateTime, InvalidDateTime};
36pub use display_text::DisplayText;
37pub use extensions::Extensions;
38pub use ids::{
39 ContractId, ContractIdParts, CountryCode, CountryCodeExt, Currency, EvseId, EvseIdParts, InvalidPartyRef,
40 PartyId, PartyRef,
41};
42pub use local::{InvalidLocalDate, InvalidLocalTime, LocalDate, LocalParts, LocalTime};
43pub use number::{InvalidNumber, Number};
44pub use open_enum::UnknownVariant;
45pub use string::OcpiString;
46pub use text::{InvalidString, StringKind};
47pub use url::{InvalidUrl, URL_MAX_LEN, Url, UrlPolicy, UrlRefused};
48pub use validate::{Validate, Validator, Violation, ViolationCode, Violations};
49
50#[doc(hidden)]
51pub use open_enum::{validate_closed_enum_value, validate_open_enum_value};
52
53pub(crate) use validate::validate_fields;
54
55/// The length limit for a `string` whose property table gives no maximum.
56///
57/// A handful of OCPI properties are typed `string` with no `(N)`: `TaxAmount.name` and
58/// `TaxAmount.account_number`, for example. [`OcpiText`] is the type for those: it enforces the
59/// character set and nothing else.
60pub const UNBOUNDED: usize = usize::MAX;
61
62/// A `string` with no length limit in the specification.
63///
64/// See [`UNBOUNDED`].
65pub type OcpiText = OcpiString<UNBOUNDED>;
66
67/// A `CiString` with no length limit in the specification.
68///
69/// Used by `Parking.apds_reference`, the one `CiString` in OCPI 2.3.0 written without a maximum.
70///
71/// See [`UNBOUNDED`].
72pub type CiText = CiString<UNBOUNDED>;