#![forbid(unsafe_code, missing_debug_implementations, missing_docs)]
#![cfg_attr(test, deny(warnings))]
extern crate failure;
extern crate mime_guess;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
use failure::Error;
mod orientation;
mod related;
mod display_mode;
mod direction;
mod icon;
pub use orientation::Orientation;
pub use direction::Direction;
pub use display_mode::DisplayMode;
pub use related::Related;
pub use icon::Icon;
pub const MIME_TYPE_STR: &'static str = "application/manifest+json";
#[derive(Debug, Clone, Serialize)]
pub struct Manifest<'s, 'i, 'r> {
name: &'s str,
#[serde(skip_serializing_if = "Option::is_none")]
short_name: Option<&'s str>,
#[serde(skip_serializing_if = "Option::is_none")]
start_url: Option<&'s str>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "display")]
display_mode: Option<DisplayMode>,
#[serde(skip_serializing_if = "Option::is_none")]
background_color: Option<&'s str>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<&'s str>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "dir")]
direction: Option<Direction>,
#[serde(skip_serializing_if = "Option::is_none")]
orientation: Option<Orientation>,
#[serde(skip_serializing_if = "Option::is_none")]
lang: Option<&'s str>,
#[serde(skip_serializing_if = "Option::is_none")]
scope: Option<&'s str>,
#[serde(skip_serializing_if = "Option::is_none")]
theme_color: Option<&'s str>,
#[serde(skip_serializing_if = "Option::is_none")]
prefer_related_applications: Option<bool>,
icons: Vec<&'i Icon<'i>>,
related_applications: Vec<&'r Related<'r>>,
}
impl<'s, 'i, 'r> Manifest<'s, 'i, 'r> {
#[must_use]
#[inline]
pub fn builder(name: &'s str) -> Self {
Self {
name,
short_name: None,
description: None,
start_url: None,
display_mode: None,
orientation: None,
direction: None,
lang: None,
background_color: None,
theme_color: None,
scope: None,
prefer_related_applications: None,
icons: vec![],
related_applications: vec![],
}
}
#[must_use]
#[inline]
pub fn build(self) -> Result<String, Error> {
let manifest = serde_json::to_string(&self)?;
Ok(manifest)
}
#[must_use]
#[inline]
pub fn pretty(self) -> Result<String, Error> {
let manifest = serde_json::to_string_pretty(&self)?;
Ok(manifest)
}
#[must_use]
#[inline]
pub fn short_name(mut self, val: &'s str) -> Self {
debug_assert!(val.len() <= 12);
self.short_name = Some(val);
self
}
#[must_use]
#[inline]
pub fn start_url(mut self, val: &'s str) -> Self {
self.start_url = Some(val);
self
}
#[must_use]
#[inline]
pub fn display_mode(mut self, val: DisplayMode) -> Self {
self.display_mode = Some(val);
self
}
#[must_use]
#[inline]
pub fn bg_color(mut self, val: &'s str) -> Self {
self.background_color = Some(val);
self
}
#[must_use]
#[inline]
pub fn theme_color(mut self, val: &'s str) -> Self {
self.theme_color = Some(val);
self
}
#[must_use]
#[inline]
pub fn description(mut self, val: &'s str) -> Self {
self.description = Some(val);
self
}
#[must_use]
#[inline]
pub fn lang(mut self, val: &'s str) -> Self {
self.lang = Some(val);
self
}
#[must_use]
#[inline]
pub fn orientation(mut self, val: Orientation) -> Self {
self.orientation = Some(val);
self
}
#[must_use]
#[inline]
pub fn direction(mut self, val: Direction) -> Self {
self.direction = Some(val);
self
}
#[must_use]
#[inline]
pub fn prefer_related_applications(mut self, val: bool) -> Self {
self.prefer_related_applications = Some(val);
self
}
#[must_use]
#[inline]
pub fn scope(mut self, val: &'s str) -> Self {
self.scope = Some(val);
self
}
#[must_use]
#[inline]
pub fn icon(mut self, val: &'i Icon) -> Self {
self.icons.push(val);
self
}
#[must_use]
#[inline]
pub fn related(mut self, val: &'r Related) -> Self {
self.related_applications.push(val);
self
}
}