ostrya 0.19.0

Pure-Rust async reimplementation of the ostree repository library
Documentation
//! The examples of the traits of a group and of a key, of the macro
//! `config_group!`, and of `Section`.
//!
//! The traits, the macro, and `Section` are in `ostrya-core`. These examples
//! use `RepoConfig` and the groups of this crate, so rustdoc runs them from
//! this module.

/// The examples of `Group`.
///
/// ```
/// use ostrya::config::{Group, repo};
///
/// assert_eq!(<repo::Group as Group>::NAME, "core");
/// assert!(!<repo::Group as Group>::NAMED);
/// assert!(<repo::Group as Group>::KEYS.contains(&"fsync"));
/// ```
struct GroupExamples;

/// The examples of `UserGroup`.
///
/// A group with the name `ex-debles` compiles:
///
/// ```
/// ostrya::config_group! {
///     pub group debles = "ex-debles" {
///         Target: Option<String> = "target";
///     }
/// }
/// ```
///
/// The port reserves `ex-ostrya` and each name that starts with `ex-ostrya`
/// and a space:
///
/// ```compile_fail,E0080
/// ostrya::config_group! {
///     pub group server = "ex-ostrya server" {
///         Target: Option<String> = "target";
///     }
/// }
/// ```
///
/// A user group name starts with `ex-`:
///
/// ```compile_fail,E0080
/// ostrya::config_group! {
///     pub group debles = "debles" {
///         Target: Option<String> = "target";
///     }
/// }
/// ```
struct UserGroupExamples;

/// The examples of `Key`.
///
/// A read of a section takes a key of the group of the section alone:
///
/// ```
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
///     pub group a = named "ex-a" {
///         X: Option<String> = "x";
///     }
/// }
/// ostrya::config_group! {
///     pub group b = named "ex-b" {
///         X: Option<String> = "x";
///     }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n[ex-a \"s\"]\nx=1\n")?;
/// let section = cfg.section::<a::Group>("s").unwrap();
/// assert_eq!(section.get::<a::X>()?.as_deref(), Some("1"));
/// # Ok::<(), ostrya::Error>(())
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
///     pub group a = named "ex-a" {
///         X: Option<String> = "x";
///     }
/// }
/// ostrya::config_group! {
///     pub group b = named "ex-b" {
///         X: Option<String> = "x";
///     }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n[ex-a \"s\"]\nx=1\n")?;
/// let section = cfg.section::<a::Group>("s").unwrap();
/// let _ = section.get::<b::X>()?;
/// # Ok::<(), ostrya::Error>(())
/// ```
struct KeyExamples;

/// The examples of `SingleKey`.
///
/// ```
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
///     pub group tool = "ex-tool" {
///         Jobs: u32 = "jobs", default 4;
///     }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n")?;
/// assert_eq!(cfg.get::<tool::Jobs>()?, 4);
/// # Ok::<(), ostrya::Error>(())
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
///     pub group tool = named "ex-tool" {
///         Jobs: u32 = "jobs", default 4;
///     }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n")?;
/// let _ = cfg.get::<tool::Jobs>()?;
/// # Ok::<(), ostrya::Error>(())
/// ```
struct SingleKeyExamples;

/// The examples of `Overridable`.
///
/// ```
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::Fsync>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::Mode>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::Locking>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::DisableXattrs>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::CollectionId>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, ex_ostrya};
///
/// fn takes<K: Overridable>() {}
/// takes::<ex_ostrya::RemotesConfigDir>();
/// ```
struct OverridableExamples;

/// The examples of `Settable`.
///
///
/// ```
/// use ostrya::config::{Settable, repo};
///
/// fn takes<K: Settable>() {}
/// takes::<repo::Locking>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Settable, repo};
///
/// fn takes<K: Settable>() {}
/// takes::<repo::Mode>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Settable, repo};
///
/// fn takes<K: Settable>() {}
/// takes::<repo::RepoVersion>();
/// ```
///
/// A key of a library user without the word `fixed` implements the trait:
///
/// ```
/// use ostrya::config::Settable;
///
/// ostrya::config_group! {
///     pub group tool = "ex-tool" {
///         Strict: bool = "strict", default false;
///     }
/// }
///
/// fn takes<K: Settable>() {}
/// takes::<tool::Strict>();
/// ```
///
/// The word `fixed` removes the trait:
///
/// ```compile_fail,E0277
/// use ostrya::config::Settable;
///
/// ostrya::config_group! {
///     pub group tool = "ex-tool" {
///         Strict: bool = "strict", default false, fixed;
///     }
/// }
///
/// fn takes<K: Settable>() {}
/// takes::<tool::Strict>();
/// ```
struct SettableExamples;

/// The examples of `config_group!`.
///
/// ```
/// use ostrya::config::{Group, RepoConfig};
///
/// ostrya::config_group! {
///     /// The keys of the `debles` tool.
///     pub group debles = "ex-debles" {
///         /// The target of a build.
///         Target: Option<String> = "target";
///         /// The number of parallel jobs.
///         Parallel: u32 = "parallel", default 4, overridable;
///     }
/// }
///
/// ostrya::config_group! {
///     /// The images of the `debles` tool.
///     pub group image = named "ex-debles image", closed {
///         /// The architecture of an image.
///         Arch: String = "arch", required;
///     }
/// }
///
/// let cfg = RepoConfig::parse(
///     "[core]\nrepo_version=1\nmode=bare\n\
///      [ex-debles]\ntarget=x86\n\
///      [ex-debles image \"base\"]\narch=amd64\n",
/// )?;
/// assert_eq!(cfg.get::<debles::Target>()?.as_deref(), Some("x86"));
/// assert_eq!(cfg.get::<debles::Parallel>()?, 4);
/// for image in cfg.sections::<image::Group>() {
///     assert_eq!(image.name(), "base");
///     assert_eq!(image.get::<image::Arch>()?, "amd64");
/// }
/// assert!(<image::Group as Group>::CLOSED);
/// # Ok::<(), ostrya::Error>(())
/// ```
struct ConfigGroupExamples;

/// The examples of `Section`.
///
/// ```
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
///     pub group image = named "ex-image", closed {
///         Arch: Option<String> = "arch";
///     }
/// }
///
/// let cfg = RepoConfig::parse(
///     "[core]\nrepo_version=1\nmode=bare\n[ex-image \"base\"]\narch=x86\nzzz=1\n",
/// )?;
/// let base = cfg.section::<image::Group>("base").unwrap();
/// assert_eq!(
///     base.refuse_unknown_keys().unwrap_err().to_string(),
///     "invalid format: [ex-image \"base\"] holds the unknown key 'zzz'"
/// );
/// # Ok::<(), ostrya::Error>(())
/// ```
struct SectionExamples;