floria_plugin_sdk/data/expression/
custom.rs1use super::super::super::{dispatch_bindings::*, utils::*, *};
2
3use std::{cmp::*, fmt, hash::*};
4
5impl CustomResource {
6 pub fn into_custom(self) -> Custom {
8 self.into_inner()
9 }
10
11 pub fn custom(&self) -> &Custom {
13 self.get()
14 }
15
16 pub fn custom_mut(&mut self) -> &mut Custom {
18 self.get_mut()
19 }
20}
21
22#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
28pub struct Custom {
29 pub kind: String,
31
32 pub inner: Expression,
34}
35
36impl Custom {
37 pub fn new(kind: String, inner: Expression) -> Self {
39 Self { kind, inner }
40 }
41
42 pub fn assert_kind(&self, kind: &str, type_name: &str) -> Result<(), DispatchError> {
44 if self.kind == kind {
45 Ok(())
46 } else {
47 Err(format!(
48 "{} custom kind not |name|{}|: |error|{}|",
49 escape_depiction_markup(type_name),
50 escape_depiction_markup(kind),
51 escape_depiction_markup(&self.kind)
52 ))
53 }
54 }
55}
56
57impl GuestCustomResource for Custom {
58 fn new(kind: String, inner: Expression) -> Self {
59 Self { kind, inner }
60 }
61
62 fn inner(&self) -> (String, Expression) {
63 (self.kind.clone(), self.inner.clone())
64 }
65}
66
67impl fmt::Display for Custom {
68 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
69 write!(formatter, "kind: {}, inner: {}", self.kind, self.inner)
70 }
71}