nominal-api 0.1239.0

API bindings for the Nominal platform
Documentation
use conjure_object::serde::{ser, de};
use conjure_object::serde::ser::SerializeMap as SerializeMap_;
use conjure_object::private::{UnionField_, UnionTypeField_};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum CheckAlertAction {
    CloseWithIgnore(super::CloseWithIgnoreAlert),
    CloseWithFurtherAction(super::CloseWithFurtherAction),
    Reopen(super::Reopen),
    Reassign(super::Reassign),
    UpdateNotes(super::UpdateNotes),
    LinkNotebook(super::LinkNotebook),
    UnlinkNotebook(super::UnlinkNotebook),
    ArchiveDataReview(super::ArchiveDataReview),
    UnarchiveDataReview(super::UnarchiveDataReview),
    /// An unknown variant.
    Unknown(Unknown),
}
impl ser::Serialize for CheckAlertAction {
    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
    where
        S: ser::Serializer,
    {
        let mut map = s.serialize_map(Some(2))?;
        match self {
            CheckAlertAction::CloseWithIgnore(value) => {
                map.serialize_entry(&"type", &"closeWithIgnore")?;
                map.serialize_entry(&"closeWithIgnore", value)?;
            }
            CheckAlertAction::CloseWithFurtherAction(value) => {
                map.serialize_entry(&"type", &"closeWithFurtherAction")?;
                map.serialize_entry(&"closeWithFurtherAction", value)?;
            }
            CheckAlertAction::Reopen(value) => {
                map.serialize_entry(&"type", &"reopen")?;
                map.serialize_entry(&"reopen", value)?;
            }
            CheckAlertAction::Reassign(value) => {
                map.serialize_entry(&"type", &"reassign")?;
                map.serialize_entry(&"reassign", value)?;
            }
            CheckAlertAction::UpdateNotes(value) => {
                map.serialize_entry(&"type", &"updateNotes")?;
                map.serialize_entry(&"updateNotes", value)?;
            }
            CheckAlertAction::LinkNotebook(value) => {
                map.serialize_entry(&"type", &"linkNotebook")?;
                map.serialize_entry(&"linkNotebook", value)?;
            }
            CheckAlertAction::UnlinkNotebook(value) => {
                map.serialize_entry(&"type", &"unlinkNotebook")?;
                map.serialize_entry(&"unlinkNotebook", value)?;
            }
            CheckAlertAction::ArchiveDataReview(value) => {
                map.serialize_entry(&"type", &"archiveDataReview")?;
                map.serialize_entry(&"archiveDataReview", value)?;
            }
            CheckAlertAction::UnarchiveDataReview(value) => {
                map.serialize_entry(&"type", &"unarchiveDataReview")?;
                map.serialize_entry(&"unarchiveDataReview", value)?;
            }
            CheckAlertAction::Unknown(value) => {
                map.serialize_entry(&"type", &value.type_)?;
                map.serialize_entry(&value.type_, &value.value)?;
            }
        }
        map.end()
    }
}
impl<'de> de::Deserialize<'de> for CheckAlertAction {
    fn deserialize<D>(d: D) -> Result<CheckAlertAction, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        d.deserialize_map(Visitor_)
    }
}
struct Visitor_;
impl<'de> de::Visitor<'de> for Visitor_ {
    type Value = CheckAlertAction;
    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str("union CheckAlertAction")
    }
    fn visit_map<A>(self, mut map: A) -> Result<CheckAlertAction, A::Error>
    where
        A: de::MapAccess<'de>,
    {
        let v = match map.next_key::<UnionField_<Variant_>>()? {
            Some(UnionField_::Type) => {
                let variant = map.next_value()?;
                let key = map.next_key()?;
                match (variant, key) {
                    (Variant_::CloseWithIgnore, Some(Variant_::CloseWithIgnore)) => {
                        let value = map.next_value()?;
                        CheckAlertAction::CloseWithIgnore(value)
                    }
                    (
                        Variant_::CloseWithFurtherAction,
                        Some(Variant_::CloseWithFurtherAction),
                    ) => {
                        let value = map.next_value()?;
                        CheckAlertAction::CloseWithFurtherAction(value)
                    }
                    (Variant_::Reopen, Some(Variant_::Reopen)) => {
                        let value = map.next_value()?;
                        CheckAlertAction::Reopen(value)
                    }
                    (Variant_::Reassign, Some(Variant_::Reassign)) => {
                        let value = map.next_value()?;
                        CheckAlertAction::Reassign(value)
                    }
                    (Variant_::UpdateNotes, Some(Variant_::UpdateNotes)) => {
                        let value = map.next_value()?;
                        CheckAlertAction::UpdateNotes(value)
                    }
                    (Variant_::LinkNotebook, Some(Variant_::LinkNotebook)) => {
                        let value = map.next_value()?;
                        CheckAlertAction::LinkNotebook(value)
                    }
                    (Variant_::UnlinkNotebook, Some(Variant_::UnlinkNotebook)) => {
                        let value = map.next_value()?;
                        CheckAlertAction::UnlinkNotebook(value)
                    }
                    (Variant_::ArchiveDataReview, Some(Variant_::ArchiveDataReview)) => {
                        let value = map.next_value()?;
                        CheckAlertAction::ArchiveDataReview(value)
                    }
                    (
                        Variant_::UnarchiveDataReview,
                        Some(Variant_::UnarchiveDataReview),
                    ) => {
                        let value = map.next_value()?;
                        CheckAlertAction::UnarchiveDataReview(value)
                    }
                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
                        if type_ == b {
                            let value = map.next_value()?;
                            CheckAlertAction::Unknown(Unknown { type_, value })
                        } else {
                            return Err(
                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
                            )
                        }
                    }
                    (variant, Some(key)) => {
                        return Err(
                            de::Error::invalid_value(
                                de::Unexpected::Str(key.as_str()),
                                &variant.as_str(),
                            ),
                        );
                    }
                    (variant, None) => {
                        return Err(de::Error::missing_field(variant.as_str()));
                    }
                }
            }
            Some(UnionField_::Value(variant)) => {
                let value = match &variant {
                    Variant_::CloseWithIgnore => {
                        let value = map.next_value()?;
                        CheckAlertAction::CloseWithIgnore(value)
                    }
                    Variant_::CloseWithFurtherAction => {
                        let value = map.next_value()?;
                        CheckAlertAction::CloseWithFurtherAction(value)
                    }
                    Variant_::Reopen => {
                        let value = map.next_value()?;
                        CheckAlertAction::Reopen(value)
                    }
                    Variant_::Reassign => {
                        let value = map.next_value()?;
                        CheckAlertAction::Reassign(value)
                    }
                    Variant_::UpdateNotes => {
                        let value = map.next_value()?;
                        CheckAlertAction::UpdateNotes(value)
                    }
                    Variant_::LinkNotebook => {
                        let value = map.next_value()?;
                        CheckAlertAction::LinkNotebook(value)
                    }
                    Variant_::UnlinkNotebook => {
                        let value = map.next_value()?;
                        CheckAlertAction::UnlinkNotebook(value)
                    }
                    Variant_::ArchiveDataReview => {
                        let value = map.next_value()?;
                        CheckAlertAction::ArchiveDataReview(value)
                    }
                    Variant_::UnarchiveDataReview => {
                        let value = map.next_value()?;
                        CheckAlertAction::UnarchiveDataReview(value)
                    }
                    Variant_::Unknown(type_) => {
                        let value = map.next_value()?;
                        CheckAlertAction::Unknown(Unknown {
                            type_: type_.clone(),
                            value,
                        })
                    }
                };
                if map.next_key::<UnionTypeField_>()?.is_none() {
                    return Err(de::Error::missing_field("type"));
                }
                let type_variant = map.next_value::<Variant_>()?;
                if variant != type_variant {
                    return Err(
                        de::Error::invalid_value(
                            de::Unexpected::Str(type_variant.as_str()),
                            &variant.as_str(),
                        ),
                    );
                }
                value
            }
            None => return Err(de::Error::missing_field("type")),
        };
        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
            return Err(de::Error::invalid_length(3, &"type and value fields"));
        }
        Ok(v)
    }
}
#[derive(PartialEq)]
enum Variant_ {
    CloseWithIgnore,
    CloseWithFurtherAction,
    Reopen,
    Reassign,
    UpdateNotes,
    LinkNotebook,
    UnlinkNotebook,
    ArchiveDataReview,
    UnarchiveDataReview,
    Unknown(Box<str>),
}
impl Variant_ {
    fn as_str(&self) -> &'static str {
        match *self {
            Variant_::CloseWithIgnore => "closeWithIgnore",
            Variant_::CloseWithFurtherAction => "closeWithFurtherAction",
            Variant_::Reopen => "reopen",
            Variant_::Reassign => "reassign",
            Variant_::UpdateNotes => "updateNotes",
            Variant_::LinkNotebook => "linkNotebook",
            Variant_::UnlinkNotebook => "unlinkNotebook",
            Variant_::ArchiveDataReview => "archiveDataReview",
            Variant_::UnarchiveDataReview => "unarchiveDataReview",
            Variant_::Unknown(_) => "unknown variant",
        }
    }
}
impl<'de> de::Deserialize<'de> for Variant_ {
    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        d.deserialize_str(VariantVisitor_)
    }
}
struct VariantVisitor_;
impl<'de> de::Visitor<'de> for VariantVisitor_ {
    type Value = Variant_;
    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str("string")
    }
    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
    where
        E: de::Error,
    {
        let v = match value {
            "closeWithIgnore" => Variant_::CloseWithIgnore,
            "closeWithFurtherAction" => Variant_::CloseWithFurtherAction,
            "reopen" => Variant_::Reopen,
            "reassign" => Variant_::Reassign,
            "updateNotes" => Variant_::UpdateNotes,
            "linkNotebook" => Variant_::LinkNotebook,
            "unlinkNotebook" => Variant_::UnlinkNotebook,
            "archiveDataReview" => Variant_::ArchiveDataReview,
            "unarchiveDataReview" => Variant_::UnarchiveDataReview,
            value => Variant_::Unknown(value.to_string().into_boxed_str()),
        };
        Ok(v)
    }
}
///An unknown variant of the CheckAlertAction union.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Unknown {
    type_: Box<str>,
    value: conjure_object::Any,
}
impl Unknown {
    /// Returns the unknown variant's type name.
    #[inline]
    pub fn type_(&self) -> &str {
        &self.type_
    }
}