//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vtc/elections/list`. Version: `0.3`.
/// Why this specification version is deprecated (SPEC "Superseded and
/// Withdrawn Versions"), or `None` while it is current.
pub const DEPRECATION: Option<&str> = None;
#[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.
///
#[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.
///
#[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.
///
#[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.
///
#[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`
///
#[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.
///
#[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.
///
#[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).
///
#[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.
///
#[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`.
///
#[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(
"{\"$defs\":{\"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.\",\"pattern\":\"^[A-Za-z0-9._-]{1,128}$\",\"title\":\"ElectionId\",\"type\":\"string\"},\"ElectionListItem\":{\"additionalProperties\":false,\"description\":\"One election as a list shows it. vtc/elections/show reads it whole.\",\"properties\":{\"binding\":{\"description\":\"The manifest's `binding`.\",\"type\":\"boolean\"},\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"state\":{\"$ref\":\"#/$defs/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.\",\"maxLength\":512,\"type\":\"string\"},\"votingClosesAt\":{\"format\":\"date-time\",\"maxLength\":64,\"type\":\"string\"},\"votingOpensAt\":{\"format\":\"date-time\",\"maxLength\":64,\"type\":\"string\"}},\"required\":[\"electionId\",\"state\",\"votingOpensAt\",\"votingClosesAt\",\"binding\",\"ticketHeld\"],\"title\":\"ElectionListItem\",\"type\":\"object\"},\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"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).\",\"enum\":[\"registered\",\"registration\",\"voting\",\"closed\",\"tallied\",\"cancelled\",\"pendingRegistration\",\"registrationRefused\"],\"title\":\"RegistrarState\",\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"description\":\"Success response to vtc/elections/list/0.2: one page of the elections the caller may see.\",\"properties\":{\"elections\":{\"items\":{\"$ref\":\"#/$defs/ElectionListItem\"},\"maxItems\":100,\"type\":\"array\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"nextCursor\":{\"description\":\"Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.\",\"maxLength\":512,\"minLength\":1,\"type\":\"string\"}},\"required\":[\"elections\"],\"title\":\"VTC Elections — List — response payload\",\"type\":\"object\"}},\"$id\":\"https://trusttasks.org/spec/vtc/elections/list/0.3\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"additionalProperties\":false,\"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.\",\"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.\",\"maxLength\":512,\"minLength\":1,\"type\":\"string\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"limit\":{\"description\":\"The most items to return; the responder chooses a default and MAY return fewer.\",\"maximum\":100,\"minimum\":1,\"type\":\"integer\"},\"state\":{\"$ref\":\"#/$defs/RegistrarState\"}},\"title\":\"VTC Elections — List — payload\",\"type\":\"object\"}\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(
"{\"$defs\":{\"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.\",\"pattern\":\"^[A-Za-z0-9._-]{1,128}$\",\"title\":\"ElectionId\",\"type\":\"string\"},\"ElectionListItem\":{\"additionalProperties\":false,\"description\":\"One election as a list shows it. vtc/elections/show reads it whole.\",\"properties\":{\"binding\":{\"description\":\"The manifest's `binding`.\",\"type\":\"boolean\"},\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"state\":{\"$ref\":\"#/$defs/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.\",\"maxLength\":512,\"type\":\"string\"},\"votingClosesAt\":{\"format\":\"date-time\",\"maxLength\":64,\"type\":\"string\"},\"votingOpensAt\":{\"format\":\"date-time\",\"maxLength\":64,\"type\":\"string\"}},\"required\":[\"electionId\",\"state\",\"votingOpensAt\",\"votingClosesAt\",\"binding\",\"ticketHeld\"],\"title\":\"ElectionListItem\",\"type\":\"object\"},\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"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).\",\"enum\":[\"registered\",\"registration\",\"voting\",\"closed\",\"tallied\",\"cancelled\",\"pendingRegistration\",\"registrationRefused\"],\"title\":\"RegistrarState\",\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"description\":\"Success response to vtc/elections/list/0.2: one page of the elections the caller may see.\",\"properties\":{\"elections\":{\"items\":{\"$ref\":\"#/$defs/ElectionListItem\"},\"maxItems\":100,\"type\":\"array\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"nextCursor\":{\"description\":\"Continuation token for the next page; pass it as `cursor`. Absent on the last page — never `null`.\",\"maxLength\":512,\"minLength\":1,\"type\":\"string\"}},\"required\":[\"elections\"],\"title\":\"VTC Elections — List — response payload\",\"type\":\"object\"}},\"$ref\":\"#/$defs/Response\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The earlier `MAJOR.MINOR` of this slug that this version declares it
/// extends (front matter `extends`, SPEC §5.2 "Declared extension"), or
/// `None`. Only the direct declaration; walk a chain with
/// [`crate::extension::extends_for`].
pub const EXTENDS: Option<&str> = None;
/// 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] = &[];