Skip to content

how to define AppStrategy in one place only? #41

@nschloe

Description

@nschloe

In the docs, I find

use etcetera::{choose_app_strategy, AppStrategy, AppStrategyArgs};

let strategy = choose_app_strategy(AppStrategyArgs {
    top_level_domain: "org".to_string(),
    author: "Acme Corp".to_string(),
    app_name: "Frobnicator Plus".to_string(),
}).unwrap();

let config_dir = strategy.config_dir();

Now, I'd like to get different dirs in different parts of my code. To this end, I'd like to define the strategy once somewhere in my code and then draw from it. Is this

use etcetera::{AppStrategy, AppStrategyArgs, choose_app_strategy};

pub fn get_dirs() -> impl AppStrategy {
    choose_app_strategy(AppStrategyArgs {
        top_level_domain: "com".to_string(),
        author: "YourName".to_string(),
        app_name: "MyApp".to_string(),
    })
    .expect("Failed to create app strategy")
}

the recommended way of doing it? Perhaps it's a little overkill to re-choose the strategy over and over again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions