//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vtc/elections/list`. Version: `0.3`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "ElectionId",
/// "description": "An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.",
/// "type": "string",
/// "pattern": "^[A-Za-z0-9._-]{1,128}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ElectionId(::std::string::String);
impl ::std::ops::Deref for ElectionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ElectionId> for ::std::string::String {
fn from(value: ElectionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ElectionId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[A-Za-z0-9._-]{1,128}$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[A-Za-z0-9._-]{1,128}$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ElectionId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ElectionId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ElectionId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ElectionId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///One election as a list shows it. vtc/elections/show reads it whole.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "ElectionListItem",
/// "description": "One election as a list shows it. vtc/elections/show reads it whole.",
/// "type": "object",
/// "required": [
/// "binding",
/// "electionId",
/// "state",
/// "ticketHeld",
/// "votingClosesAt",
/// "votingOpensAt"
/// ],
/// "properties": {
/// "binding": {
/// "description": "The manifest's `binding`.",
/// "type": "boolean"
/// },
/// "electionId": {
/// "$ref": "#/definitions/ElectionId"
/// },
/// "state": {
/// "$ref": "#/definitions/RegistrarState"
/// },
/// "ticketHeld": {
/// "description": "Whether the community has issued a ticket for this election to the caller. About the caller only, never anyone else.",
/// "type": "boolean"
/// },
/// "title": {
/// "description": "The manifest's `title`, when it has one.",
/// "type": "string",
/// "maxLength": 512
/// },
/// "votingClosesAt": {
/// "type": "string",
/// "format": "date-time",
/// "maxLength": 64
/// },
/// "votingOpensAt": {
/// "type": "string",
/// "format": "date-time",
/// "maxLength": 64
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ElectionListItem {
///The manifest's `binding`.
pub binding: bool,
#[serde(rename = "electionId")]
pub election_id: ElectionId,
pub state: RegistrarState,
///Whether the community has issued a ticket for this election to the caller. About the caller only, never anyone else.
#[serde(rename = "ticketHeld")]
pub ticket_held: bool,
///The manifest's `title`, when it has one.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub title: ::std::option::Option<ElectionListItemTitle>,
#[serde(rename = "votingClosesAt")]
pub voting_closes_at: ::chrono::DateTime<::chrono::offset::Utc>,
#[serde(rename = "votingOpensAt")]
pub voting_opens_at: ::chrono::DateTime<::chrono::offset::Utc>,
}
impl ElectionListItem {
pub fn builder() -> builder::ElectionListItem {
Default::default()
}
}
///The manifest's `title`, when it has one.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The manifest's `title`, when it has one.",
/// "type": "string",
/// "maxLength": 512
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ElectionListItemTitle(::std::string::String);
impl ::std::ops::Deref for ElectionListItemTitle {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ElectionListItemTitle> for ::std::string::String {
fn from(value: ElectionListItemTitle) -> Self {
value.0
}
}
impl ::std::str::FromStr for ElectionListItemTitle {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ElectionListItemTitle {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ElectionListItemTitle {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ElectionListItemTitle {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ElectionListItemTitle {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A member or an administrator pages through the community's elections that the caller may see. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/vtc/elections/list/0.3",
/// "title": "Payload",
/// "description": "A member or an administrator pages through the community's elections that the caller may see. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "properties": {
/// "cursor": {
/// "description": "An opaque continuation token from a previous response's `nextCursor`, bound to the caller and to `state`; a responder MUST NOT accept a cursor it did not issue.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "limit": {
/// "description": "The most items to return; the responder chooses a default and MAY return fewer.",
/// "type": "integer",
/// "maximum": 100.0,
/// "minimum": 1.0
/// },
/// "state": {
/// "$ref": "#/definitions/RegistrarState"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///An opaque continuation token from a previous response's `nextCursor`, bound to the caller and to `state`; a responder MUST NOT accept a cursor it did not issue.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub cursor: ::std::option::Option<PayloadCursor>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The most items to return; the responder chooses a default and MAY return fewer.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub limit: ::std::option::Option<::std::num::NonZeroU64>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub state: ::std::option::Option<RegistrarState>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
cursor: Default::default(),
ext: Default::default(),
limit: Default::default(),
state: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///An opaque continuation token from a previous response's `nextCursor`, bound to the caller and to `state`; a responder MUST NOT accept a cursor it did not issue.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "An opaque continuation token from a previous response's `nextCursor`, bound to the caller and to `state`; a responder MUST NOT accept a cursor it did not issue.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadCursor(::std::string::String);
impl ::std::ops::Deref for PayloadCursor {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadCursor> for ::std::string::String {
fn from(value: PayloadCursor) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadCursor {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadCursor {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadCursor {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadCursor {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadCursor {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///An election's state as its registrar holds it: the ballot box's `ElectionState` once the ballot box has registered the election, or, before that, `pendingRegistration` (the community is still delivering the registration) or `registrationRefused` (the ballot box refused it on a later delivery, and only a cancellation clears it). The first six values are the ballot box's `ElectionState` (voting/_shared/0.1).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "RegistrarState",
/// "description": "An election's state as its registrar holds it: the ballot box's `ElectionState` once the ballot box has registered the election, or, before that, `pendingRegistration` (the community is still delivering the registration) or `registrationRefused` (the ballot box refused it on a later delivery, and only a cancellation clears it). The first six values are the ballot box's `ElectionState` (voting/_shared/0.1).",
/// "type": "string",
/// "enum": [
/// "registered",
/// "registration",
/// "voting",
/// "closed",
/// "tallied",
/// "cancelled",
/// "pendingRegistration",
/// "registrationRefused"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum RegistrarState {
#[serde(rename = "registered")]
Registered,
#[serde(rename = "registration")]
Registration,
#[serde(rename = "voting")]
Voting,
#[serde(rename = "closed")]
Closed,
#[serde(rename = "tallied")]
Tallied,
#[serde(rename = "cancelled")]
Cancelled,
#[serde(rename = "pendingRegistration")]
PendingRegistration,
#[serde(rename = "registrationRefused")]
RegistrationRefused,
}
impl ::std::fmt::Display for RegistrarState {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Registered => f.write_str("registered"),
Self::Registration => f.write_str("registration"),
Self::Voting => f.write_str("voting"),
Self::Closed => f.write_str("closed"),
Self::Tallied => f.write_str("tallied"),
Self::Cancelled => f.write_str("cancelled"),
Self::PendingRegistration => f.write_str("pendingRegistration"),
Self::RegistrationRefused => f.write_str("registrationRefused"),
}
}
}
impl ::std::str::FromStr for RegistrarState {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"registered" => Ok(Self::Registered),
"registration" => Ok(Self::Registration),
"voting" => Ok(Self::Voting),
"closed" => Ok(Self::Closed),
"tallied" => Ok(Self::Tallied),
"cancelled" => Ok(Self::Cancelled),
"pendingRegistration" => Ok(Self::PendingRegistration),
"registrationRefused" => Ok(Self::RegistrationRefused),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for RegistrarState {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for RegistrarState {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for RegistrarState {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///Success response to vtc/elections/list/0.2: one page of the elections the caller may see.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "Success response to vtc/elections/list/0.2: one page of the elections the caller may see.",
/// "type": "object",
/// "required": [
/// "elections"
/// ],
/// "properties": {
/// "elections": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/ElectionListItem"
/// },
/// "maxItems": 100
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "nextCursor": {
/// "description": "Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
pub elections: ::std::vec::Vec<ElectionListItem>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.
#[serde(
rename = "nextCursor",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub next_cursor: ::std::option::Option<ResponseNextCursor>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseNextCursor(::std::string::String);
impl ::std::ops::Deref for ResponseNextCursor {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseNextCursor> for ::std::string::String {
fn from(value: ResponseNextCursor) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseNextCursor {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseNextCursor {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ResponseNextCursor {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ResponseNextCursor {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ResponseNextCursor {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct ElectionListItem {
binding: ::std::result::Result<bool, ::std::string::String>,
election_id: ::std::result::Result<super::ElectionId, ::std::string::String>,
state: ::std::result::Result<super::RegistrarState, ::std::string::String>,
ticket_held: ::std::result::Result<bool, ::std::string::String>,
title: ::std::result::Result<
::std::option::Option<super::ElectionListItemTitle>,
::std::string::String,
>,
voting_closes_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
voting_opens_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
}
impl ::std::default::Default for ElectionListItem {
fn default() -> Self {
Self {
binding: Err("no value supplied for binding".to_string()),
election_id: Err("no value supplied for election_id".to_string()),
state: Err("no value supplied for state".to_string()),
ticket_held: Err("no value supplied for ticket_held".to_string()),
title: Ok(Default::default()),
voting_closes_at: Err("no value supplied for voting_closes_at".to_string()),
voting_opens_at: Err("no value supplied for voting_opens_at".to_string()),
}
}
}
impl ElectionListItem {
pub fn binding<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.binding = value
.try_into()
.map_err(|e| format!("error converting supplied value for binding: {e}"));
self
}
pub fn election_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ElectionId>,
T::Error: ::std::fmt::Display,
{
self.election_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for election_id: {e}"));
self
}
pub fn state<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::RegistrarState>,
T::Error: ::std::fmt::Display,
{
self.state = value
.try_into()
.map_err(|e| format!("error converting supplied value for state: {e}"));
self
}
pub fn ticket_held<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.ticket_held = value
.try_into()
.map_err(|e| format!("error converting supplied value for ticket_held: {e}"));
self
}
pub fn title<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::ElectionListItemTitle>>,
T::Error: ::std::fmt::Display,
{
self.title = value
.try_into()
.map_err(|e| format!("error converting supplied value for title: {e}"));
self
}
pub fn voting_closes_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.voting_closes_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for voting_closes_at: {e}"));
self
}
pub fn voting_opens_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.voting_opens_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for voting_opens_at: {e}"));
self
}
}
impl ::std::convert::TryFrom<ElectionListItem> for super::ElectionListItem {
type Error = super::error::ConversionError;
fn try_from(
value: ElectionListItem,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
binding: value.binding?,
election_id: value.election_id?,
state: value.state?,
ticket_held: value.ticket_held?,
title: value.title?,
voting_closes_at: value.voting_closes_at?,
voting_opens_at: value.voting_opens_at?,
})
}
}
impl ::std::convert::From<super::ElectionListItem> for ElectionListItem {
fn from(value: super::ElectionListItem) -> Self {
Self {
binding: Ok(value.binding),
election_id: Ok(value.election_id),
state: Ok(value.state),
ticket_held: Ok(value.ticket_held),
title: Ok(value.title),
voting_closes_at: Ok(value.voting_closes_at),
voting_opens_at: Ok(value.voting_opens_at),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
cursor: ::std::result::Result<
::std::option::Option<super::PayloadCursor>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
limit: ::std::result::Result<
::std::option::Option<::std::num::NonZeroU64>,
::std::string::String,
>,
state: ::std::result::Result<
::std::option::Option<super::RegistrarState>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
cursor: Ok(Default::default()),
ext: Ok(Default::default()),
limit: Ok(Default::default()),
state: Ok(Default::default()),
}
}
}
impl Payload {
pub fn cursor<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadCursor>>,
T::Error: ::std::fmt::Display,
{
self.cursor = value
.try_into()
.map_err(|e| format!("error converting supplied value for cursor: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn limit<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::num::NonZeroU64>>,
T::Error: ::std::fmt::Display,
{
self.limit = value
.try_into()
.map_err(|e| format!("error converting supplied value for limit: {e}"));
self
}
pub fn state<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::RegistrarState>>,
T::Error: ::std::fmt::Display,
{
self.state = value
.try_into()
.map_err(|e| format!("error converting supplied value for state: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
cursor: value.cursor?,
ext: value.ext?,
limit: value.limit?,
state: value.state?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
cursor: Ok(value.cursor),
ext: Ok(value.ext),
limit: Ok(value.limit),
state: Ok(value.state),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
elections:
::std::result::Result<::std::vec::Vec<super::ElectionListItem>, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
next_cursor: ::std::result::Result<
::std::option::Option<super::ResponseNextCursor>,
::std::string::String,
>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
elections: Err("no value supplied for elections".to_string()),
ext: Ok(Default::default()),
next_cursor: Ok(Default::default()),
}
}
}
impl Response {
pub fn elections<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::ElectionListItem>>,
T::Error: ::std::fmt::Display,
{
self.elections = value
.try_into()
.map_err(|e| format!("error converting supplied value for elections: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn next_cursor<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::ResponseNextCursor>>,
T::Error: ::std::fmt::Display,
{
self.next_cursor = value
.try_into()
.map_err(|e| format!("error converting supplied value for next_cursor: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
elections: value.elections?,
ext: value.ext?,
next_cursor: value.next_cursor?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
elections: Ok(value.elections),
ext: Ok(value.ext),
next_cursor: Ok(value.next_cursor),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vtc/elections/list/0.3";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"ElectionId\": {\n \"description\": \"An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.\",\n \"pattern\": \"^[A-Za-z0-9._-]{1,128}$\",\n \"title\": \"ElectionId\",\n \"type\": \"string\"\n },\n \"ElectionListItem\": {\n \"additionalProperties\": false,\n \"description\": \"One election as a list shows it. vtc/elections/show reads it whole.\",\n \"properties\": {\n \"binding\": {\n \"description\": \"The manifest's `binding`.\",\n \"type\": \"boolean\"\n },\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"state\": {\n \"$ref\": \"#/$defs/RegistrarState\"\n },\n \"ticketHeld\": {\n \"description\": \"Whether the community has issued a ticket for this election to the caller. About the caller only, never anyone else.\",\n \"type\": \"boolean\"\n },\n \"title\": {\n \"description\": \"The manifest's `title`, when it has one.\",\n \"maxLength\": 512,\n \"type\": \"string\"\n },\n \"votingClosesAt\": {\n \"format\": \"date-time\",\n \"maxLength\": 64,\n \"type\": \"string\"\n },\n \"votingOpensAt\": {\n \"format\": \"date-time\",\n \"maxLength\": 64,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"electionId\",\n \"state\",\n \"votingOpensAt\",\n \"votingClosesAt\",\n \"binding\",\n \"ticketHeld\"\n ],\n \"title\": \"ElectionListItem\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"RegistrarState\": {\n \"description\": \"An election's state as its registrar holds it: the ballot box's `ElectionState` once the ballot box has registered the election, or, before that, `pendingRegistration` (the community is still delivering the registration) or `registrationRefused` (the ballot box refused it on a later delivery, and only a cancellation clears it). The first six values are the ballot box's `ElectionState` (voting/_shared/0.1).\",\n \"enum\": [\n \"registered\",\n \"registration\",\n \"voting\",\n \"closed\",\n \"tallied\",\n \"cancelled\",\n \"pendingRegistration\",\n \"registrationRefused\"\n ],\n \"title\": \"RegistrarState\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"Success response to vtc/elections/list/0.2: one page of the elections the caller may see.\",\n \"properties\": {\n \"elections\": {\n \"items\": {\n \"$ref\": \"#/$defs/ElectionListItem\"\n },\n \"maxItems\": 100,\n \"type\": \"array\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"nextCursor\": {\n \"description\": \"Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.\",\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"elections\"\n ],\n \"title\": \"VTC Elections — List — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vtc/elections/list/0.3\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"A member or an administrator pages through the community's elections that the caller may see. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.\",\n \"properties\": {\n \"cursor\": {\n \"description\": \"An opaque continuation token from a previous response's `nextCursor`, bound to the caller and to `state`; a responder MUST NOT accept a cursor it did not issue.\",\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"limit\": {\n \"description\": \"The most items to return; the responder chooses a default and MAY return fewer.\",\n \"maximum\": 100,\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"state\": {\n \"$ref\": \"#/$defs/RegistrarState\"\n }\n },\n \"title\": \"VTC Elections — List — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vtc/elections/list/0.3#response";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"ElectionId\": {\n \"description\": \"An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.\",\n \"pattern\": \"^[A-Za-z0-9._-]{1,128}$\",\n \"title\": \"ElectionId\",\n \"type\": \"string\"\n },\n \"ElectionListItem\": {\n \"additionalProperties\": false,\n \"description\": \"One election as a list shows it. vtc/elections/show reads it whole.\",\n \"properties\": {\n \"binding\": {\n \"description\": \"The manifest's `binding`.\",\n \"type\": \"boolean\"\n },\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"state\": {\n \"$ref\": \"#/$defs/RegistrarState\"\n },\n \"ticketHeld\": {\n \"description\": \"Whether the community has issued a ticket for this election to the caller. About the caller only, never anyone else.\",\n \"type\": \"boolean\"\n },\n \"title\": {\n \"description\": \"The manifest's `title`, when it has one.\",\n \"maxLength\": 512,\n \"type\": \"string\"\n },\n \"votingClosesAt\": {\n \"format\": \"date-time\",\n \"maxLength\": 64,\n \"type\": \"string\"\n },\n \"votingOpensAt\": {\n \"format\": \"date-time\",\n \"maxLength\": 64,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"electionId\",\n \"state\",\n \"votingOpensAt\",\n \"votingClosesAt\",\n \"binding\",\n \"ticketHeld\"\n ],\n \"title\": \"ElectionListItem\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"RegistrarState\": {\n \"description\": \"An election's state as its registrar holds it: the ballot box's `ElectionState` once the ballot box has registered the election, or, before that, `pendingRegistration` (the community is still delivering the registration) or `registrationRefused` (the ballot box refused it on a later delivery, and only a cancellation clears it). The first six values are the ballot box's `ElectionState` (voting/_shared/0.1).\",\n \"enum\": [\n \"registered\",\n \"registration\",\n \"voting\",\n \"closed\",\n \"tallied\",\n \"cancelled\",\n \"pendingRegistration\",\n \"registrationRefused\"\n ],\n \"title\": \"RegistrarState\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"Success response to vtc/elections/list/0.2: one page of the elections the caller may see.\",\n \"properties\": {\n \"elections\": {\n \"items\": {\n \"$ref\": \"#/$defs/ElectionListItem\"\n },\n \"maxItems\": 100,\n \"type\": \"array\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"nextCursor\": {\n \"description\": \"Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.\",\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"elections\"\n ],\n \"title\": \"VTC Elections — List — response payload\",\n \"type\": \"object\"\n }\n },\n \"$ref\": \"#/$defs/Response\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[];