oxsearch-core 0.2.0

The core of oxsearch: the transport and endpoint traits, errors, and the common types, query DSL, retrievers and kNN generated from the Elasticsearch specification
Documentation
// Generated by `cargo run -p xtask -- generate` from elastic/elasticsearch-specification 9.5 at
// 84bf510a907bae62ffe29af35f516af287a79eab. Don't edit it: change the generator.

#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
#[non_exhaustive]
pub struct UnassignedInformation {
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub at: ::core::option::Option<crate::DateTime>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub last_allocation_status: ::core::option::Option<::std::string::String>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub reason:
        ::core::option::Option<crate::cluster::allocation_explain::UnassignedInformationReason>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub details: ::core::option::Option<::std::string::String>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub failed_allocation_attempts: ::core::option::Option<i32>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub delayed: ::core::option::Option<bool>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub allocation_status: ::core::option::Option<::std::string::String>,
}

impl UnassignedInformation {
    /// A `UnassignedInformation` with its required properties set.
    pub fn new(
        at: impl ::core::convert::Into<crate::DateTime>,
        reason: impl ::core::convert::Into<
            crate::cluster::allocation_explain::UnassignedInformationReason,
        >,
    ) -> Self {
        Self {
            at: ::core::option::Option::Some(at.into()),
            last_allocation_status: ::core::option::Option::None,
            reason: ::core::option::Option::Some(reason.into()),
            details: ::core::option::Option::None,
            failed_allocation_attempts: ::core::option::Option::None,
            delayed: ::core::option::Option::None,
            allocation_status: ::core::option::Option::None,
        }
    }
}

impl UnassignedInformation {
    /// Sets `last_allocation_status`.
    pub fn last_allocation_status(
        mut self,
        value: impl ::core::convert::Into<::std::string::String>,
    ) -> Self {
        self.last_allocation_status = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `details`.
    pub fn details(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.details = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `failed_allocation_attempts`.
    pub fn failed_allocation_attempts(mut self, value: i32) -> Self {
        self.failed_allocation_attempts = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `delayed`.
    pub fn delayed(mut self, value: bool) -> Self {
        self.delayed = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `allocation_status`.
    pub fn allocation_status(
        mut self,
        value: impl ::core::convert::Into<::std::string::String>,
    ) -> Self {
        self.allocation_status = ::core::option::Option::Some(value.into());
        self
    }
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum UnassignedInformationReason {
    /// `INDEX_CREATED`
    IndexCreated,
    /// `CLUSTER_RECOVERED`
    ClusterRecovered,
    /// `INDEX_REOPENED`
    IndexReopened,
    /// `DANGLING_INDEX_IMPORTED`
    DanglingIndexImported,
    /// `NEW_INDEX_RESTORED`
    NewIndexRestored,
    /// `EXISTING_INDEX_RESTORED`
    ExistingIndexRestored,
    /// `REPLICA_ADDED`
    ReplicaAdded,
    /// `ALLOCATION_FAILED`
    AllocationFailed,
    /// `NODE_LEFT`
    NodeLeft,
    /// `REROUTE_CANCELLED`
    RerouteCancelled,
    /// `REINITIALIZED`
    Reinitialized,
    /// `REALLOCATED_REPLICA`
    ReallocatedReplica,
    /// `PRIMARY_FAILED`
    PrimaryFailed,
    /// `FORCED_EMPTY_PRIMARY`
    ForcedEmptyPrimary,
    /// `MANUAL_ALLOCATION`
    ManualAllocation,
    /// A value this version of the specification doesn't list.
    Raw(::std::string::String),
}

impl UnassignedInformationReason {
    /// The value as Elasticsearch writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::IndexCreated => "INDEX_CREATED",
            Self::ClusterRecovered => "CLUSTER_RECOVERED",
            Self::IndexReopened => "INDEX_REOPENED",
            Self::DanglingIndexImported => "DANGLING_INDEX_IMPORTED",
            Self::NewIndexRestored => "NEW_INDEX_RESTORED",
            Self::ExistingIndexRestored => "EXISTING_INDEX_RESTORED",
            Self::ReplicaAdded => "REPLICA_ADDED",
            Self::AllocationFailed => "ALLOCATION_FAILED",
            Self::NodeLeft => "NODE_LEFT",
            Self::RerouteCancelled => "REROUTE_CANCELLED",
            Self::Reinitialized => "REINITIALIZED",
            Self::ReallocatedReplica => "REALLOCATED_REPLICA",
            Self::PrimaryFailed => "PRIMARY_FAILED",
            Self::ForcedEmptyPrimary => "FORCED_EMPTY_PRIMARY",
            Self::ManualAllocation => "MANUAL_ALLOCATION",
            Self::Raw(value) => value,
        }
    }

    /// The listed value with this name, if there is one.
    pub fn from_known(value: &str) -> ::core::option::Option<Self> {
        match value {
            "INDEX_CREATED" => ::core::option::Option::Some(Self::IndexCreated),
            "CLUSTER_RECOVERED" => ::core::option::Option::Some(Self::ClusterRecovered),
            "INDEX_REOPENED" => ::core::option::Option::Some(Self::IndexReopened),
            "DANGLING_INDEX_IMPORTED" => ::core::option::Option::Some(Self::DanglingIndexImported),
            "NEW_INDEX_RESTORED" => ::core::option::Option::Some(Self::NewIndexRestored),
            "EXISTING_INDEX_RESTORED" => ::core::option::Option::Some(Self::ExistingIndexRestored),
            "REPLICA_ADDED" => ::core::option::Option::Some(Self::ReplicaAdded),
            "ALLOCATION_FAILED" => ::core::option::Option::Some(Self::AllocationFailed),
            "NODE_LEFT" => ::core::option::Option::Some(Self::NodeLeft),
            "REROUTE_CANCELLED" => ::core::option::Option::Some(Self::RerouteCancelled),
            "REINITIALIZED" => ::core::option::Option::Some(Self::Reinitialized),
            "REALLOCATED_REPLICA" => ::core::option::Option::Some(Self::ReallocatedReplica),
            "PRIMARY_FAILED" => ::core::option::Option::Some(Self::PrimaryFailed),
            "FORCED_EMPTY_PRIMARY" => ::core::option::Option::Some(Self::ForcedEmptyPrimary),
            "MANUAL_ALLOCATION" => ::core::option::Option::Some(Self::ManualAllocation),
            _ => ::core::option::Option::None,
        }
    }
}

impl ::serde::Serialize for UnassignedInformationReason {
    fn serialize<S__: ::serde::Serializer>(
        &self,
        serializer: S__,
    ) -> ::core::result::Result<S__::Ok, S__::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> ::serde::Deserialize<'de> for UnassignedInformationReason {
    fn deserialize<D__: ::serde::Deserializer<'de>>(
        deserializer: D__,
    ) -> ::core::result::Result<Self, D__::Error> {
        ::oxsearch_core::__private::deserialize_string_enum(
            deserializer,
            "UnassignedInformationReason",
            |value| Self::from_known(value).unwrap_or_else(|| Self::Raw(value.to_owned())),
        )
    }
}