File: beta_disabled.rs

package info (click to toggle)
rust-derive-deftly 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,652 kB
  • sloc: perl: 1,032; sh: 373; python: 227; makefile: 11
file content (41 lines) | stat: -rw-r--r-- 1,413 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Version of `mod beta` for when the cargo feature is disabled
//!
//! See `beta.rs` for dev documentation.

use super::prelude::*;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Enabled {}

pub type MaybeEnabled = Result<Enabled, ErrorGenerator<'static>>;

pub fn with_maybe_enabled<R>(_: MaybeEnabled, f: impl FnOnce() -> R) -> R {
    f()
}

impl Enabled {
    pub fn new_for_dd_option(span: Span) -> syn::Result<Self> {
        Err(span.error(
 "derive-deftly's `beta_deftly` template option is only available when the `beta` cargo feature is also enabled"
        ))
    }

    pub fn new_for_modules_feature(span: Span) -> syn::Result<Self> {
        Err(span.error(
 "reuseable define_derive_deftly modules are a beta feature, so only available when the `beta` cargo feature is also enabled"
        ))
    }

    pub fn new_for_imported_definitions() -> MaybeEnabled {
        Err(error_generator!(
 "module containing beta template features (defined using derive-deftly with beta cargo feature enabled)imported into template using derive-deftly with beta cargo feature disabled!"
        ))
    }

    #[allow(dead_code)] // sometimes we might not have any beta features
    pub fn new_for_syntax(span: Span) -> syn::Result<Self> {
        Err(span.error(
 "beta derive-deftly feature used, which requires both the `beta` cargo feature and the `beta_deftly` template option"
        ))
    }
}