cuprate_rpc_types/defaults.rs
1//! These functions define the default values
2//! of optional fields in request/response types.
3//!
4//! For example, [`crate::json::GetBlockRequest`]
5//! has a [`crate::json::GetBlockRequest::height`]
6//! field and a [`crate::json::GetBlockRequest::hash`]
7//! field, when the RPC interface reads JSON without
8//! `height`, it will use [`default`] to fill that in.
9
10//---------------------------------------------------------------------------------------------------- Import
11
12//---------------------------------------------------------------------------------------------------- TODO
13/// Default [`bool`] type used in _some_ request/response types, `true`.
14#[inline]
15pub(crate) const fn default_true() -> bool {
16 true
17}
18
19/// Default `1` value used in request/response types.
20#[inline]
21pub(crate) fn default_one<T: From<u8>>() -> T {
22 T::from(1)
23}
24
25/// Generate a default `T` to be used in request/response types.
26#[inline]
27pub(crate) fn default<T: Default>() -> T {
28 T::default()
29}
30
31//---------------------------------------------------------------------------------------------------- Tests
32#[cfg(test)]
33mod test {}