pub trait Translator {
    fn spec(&self) -> &Map<String, Value>;
    fn status(&self) -> &Map<String, Value>;
    fn spec_mut(&mut self) -> &mut Map<String, Value>;
    fn status_mut(&mut self) -> &mut Map<String, Value>;

    fn section<D>(&self) -> Option<Result<D, Error>>
    where
        D: for<'de> Deserialize<'de> + Dialect
, { ... } fn set_section<D>(&mut self, d: D) -> Result<(), Error>
    where
        D: Serialize + Dialect
, { ... } fn update_section<D, F>(&mut self, f: F) -> Result<(), Error>
    where
        D: Serialize + for<'de> Deserialize<'de> + Dialect + Default,
        F: FnOnce(D) -> D
, { ... } fn clear_section<D>(&mut self)
    where
        D: Serialize + Dialect
, { ... } fn spec_for<T, S>(&self, key: S) -> Option<Result<T, Error>>
    where
        T: for<'de> Deserialize<'de>,
        S: AsRef<str>
, { ... } fn status_for<T, S>(&self, key: S) -> Option<Result<T, Error>>
    where
        T: for<'de> Deserialize<'de>,
        S: AsRef<str>
, { ... } fn attribute<A>(&self) -> A::Output
    where
        A: Attribute
, { ... } }
Expand description

A translator for the data sections of a resource.

The translator trait, in combination with the Dialect trait allows easy access to spec and status section in a strongly typed fashion:

use drogue_client::{dialect, Section, Translator};
use drogue_client::registry::v1::Application;
use serde::Deserialize;

#[derive(Deserialize)]
pub struct FooSpec {
}

dialect!(FooSpec[Section::Spec => "foo"]);

fn work_with(app: &Application) {
  match app.section::<FooSpec>() {
    Some(Ok(foo)) => {
        // foo section existed and could be parsed.
    },
    Some(Err(err)) => {
        // foo section existed, but could not be parsed.
    },
    None => {
        // foo section did not exist.
    },
  }
}

Required Methods

Provided Methods

Implementors