scuffle_cedar_policy/
types.rs

1use serde::ser::SerializeMap;
2
3/// A type used by [crate::CedarEntity::TagType] to indicate that no tag is provided.
4// The reason this is an enum is because an enum with no variants is unconstructable.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum NoTag {}
7
8impl serde::Serialize for NoTag {
9    fn serialize<S>(&self, _: S) -> Result<S::Ok, S::Error>
10    where
11        S: serde::Serializer,
12    {
13        // Since this is an empty enum it can never be constructed.
14        match *self {}
15    }
16}
17
18/// A type used by [crate::CedarAction::Context] to indicate that no context is provided.
19// This is a struct because we need to be able to construct this.
20#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
21pub struct EmptyContext;
22
23impl serde::Serialize for EmptyContext {
24    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
25    where
26        S: serde::Serializer,
27    {
28        serializer.serialize_map(Some(0))?.end()
29    }
30}
31
32/// A type used by [crate::CedarEntity::Attrs] to indicate that the entity has no attributes.
33// This is a struct because we need to be able to construct this.
34#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
35pub struct NoAttributes;
36
37impl serde::Serialize for NoAttributes {
38    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
39    where
40        S: serde::Serializer,
41    {
42        serializer.serialize_map(Some(0))?.end()
43    }
44}