Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename manifest fields, add example setting #5

Merged
merged 4 commits into from
Feb 13, 2025
Merged

Conversation

alexcasalboni
Copy link
Contributor

No description provided.

@alexcasalboni alexcasalboni self-assigned this Feb 13, 2025
@alexcasalboni alexcasalboni requested a review from a team as a code owner February 13, 2025 14:17
@CLEMENTINATOR
Copy link
Collaborator

can we add a way to parse the example setting in lib.rs ?

@alexcasalboni
Copy link
Contributor Author

alexcasalboni commented Feb 13, 2025

can we add a way to parse the example setting in lib.rs ?

yes it's probably a useful addition since the conversion from Dict is a bit annoying :)

something like:

pub struct Settings {
    pub example: String,
}

impl Settings {
    pub fn new(cred_map: Dict) -> anyhow::Result<Self> {
        let cred: HashMap<String, String> = cred_map
            .iter()
            .map(|(key, value)| (key.to_string(), value.to_string()))
            .collect();

        /*
        // required setting
        let example = cred
            .get("example")
            .context("Missing example setting")?
            .to_string();
        */

        // optional setting
        let example = cred
            .get("example")
            .map(String::to_string)
            .unwrap_or_default();

        Ok(Self {
            example
        })
    }
}

so in your handler you can just:

let my_settings = Settings::new(settings).map_err(|e| e.to_string())?;

@alexcasalboni alexcasalboni requested a review from a team February 13, 2025 15:02
@alexcasalboni alexcasalboni merged commit 813023c into main Feb 13, 2025
6 checks passed
@alexcasalboni alexcasalboni deleted the manifest-renaming branch February 13, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants