Feature Flags

Configure apr-cookbook capabilities via Cargo features.

Available Features

FeatureDescriptionDefault
defaultCore bundling and conversion
encryptionAES-256-GCM encryption
fullAll features

Usage

Single Feature

[dependencies]
apr-cookbook = { version = "0.1", features = ["encryption"] }

All Features

[dependencies]
apr-cookbook = { version = "0.1", features = ["full"] }

Feature Details

encryption

Enables model encryption with AES-256-GCM:

#[cfg(feature = "encryption")]
use aprender::format::{save_encrypted, load_encrypted};

Adds dependencies:

  • aprender/format-encryption

Checking Features at Runtime

#[cfg(feature = "encryption")]
fn encrypt_available() -> bool { true }

#[cfg(not(feature = "encryption"))]
fn encrypt_available() -> bool { false }

Conditional Compilation

pub fn save_model(model: &Model, path: &str, encrypt: bool) -> Result<()> {
    if encrypt {
        #[cfg(feature = "encryption")]
        {
            return save_encrypted(model, path, "password");
        }

        #[cfg(not(feature = "encryption"))]
        {
            return Err(CookbookError::feature_not_available("encryption"));
        }
    }

    save(model, path)
}