Skip to content

Commit

Permalink
feat: allow Application::load_from_file to accept paths (#583)
Browse files Browse the repository at this point in the history
Makes `Application::load_from_file` a bit more ergonomic by allowing it
to accept `String`, `str`, `PathBuf`, and `Path`.

Co-authored-by: Christoph Bühler <[email protected]>
  • Loading branch information
sandydoo and buehler authored Jan 15, 2025
1 parent de1c389 commit 2956242
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/credentials/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use custom_error::custom_error;
use jsonwebtoken::{encode, Algorithm, EncodingKey, Header};
use serde::{Deserialize, Serialize};
use std::fs::read_to_string;
use std::path::Path;

use crate::credentials::jwt::JwtClaims;

Expand Down Expand Up @@ -52,7 +53,7 @@ impl Application {
/// println!("{:#?}", application);
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn load_from_file(file_path: &str) -> Result<Self, ApplicationError> {
pub fn load_from_file<P: AsRef<Path>>(file_path: P) -> Result<Self, ApplicationError> {
let data = read_to_string(file_path).map_err(|e| ApplicationError::Io { source: e })?;
Application::load_from_json(data.as_str())
}
Expand Down

0 comments on commit 2956242

Please sign in to comment.