Translator

Trait Translator 

Source
pub trait Translator {
    // Required methods
    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>;

    // Provided methods
    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§

Source

fn spec(&self) -> &Map<String, Value>

Source

fn status(&self) -> &Map<String, Value>

Source

fn spec_mut(&mut self) -> &mut Map<String, Value>

Source

fn status_mut(&mut self) -> &mut Map<String, Value>

Provided Methods§

Source

fn section<D>(&self) -> Option<Result<D, Error>>
where D: for<'de> Deserialize<'de> + Dialect,

Source

fn set_section<D>(&mut self, d: D) -> Result<(), Error>
where D: Serialize + Dialect,

Source

fn update_section<D, F>(&mut self, f: F) -> Result<(), Error>
where D: Serialize + for<'de> Deserialize<'de> + Dialect + Default, F: FnOnce(D) -> D,

Source

fn clear_section<D>(&mut self)
where D: Serialize + Dialect,

Source

fn spec_for<T, S>(&self, key: S) -> Option<Result<T, Error>>
where T: for<'de> Deserialize<'de>, S: AsRef<str>,

Source

fn status_for<T, S>(&self, key: S) -> Option<Result<T, Error>>
where T: for<'de> Deserialize<'de>, S: AsRef<str>,

Source

fn attribute<A>(&self) -> A::Output
where A: Attribute,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§