1
Fork 0

Add configuration for image size.

This commit is contained in:
Bauke 2022-04-02 17:01:00 +02:00
parent 1f25982b84
commit 24f907b59b
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 17 additions and 0 deletions

View File

@ -26,12 +26,14 @@
#[derive(Debug)]
pub struct Generator {
pub base_url: String,
pub image_size: Option<i32>,
}
impl Default for Generator {
fn default() -> Self {
Self {
base_url: "www.gravatar.com".to_string(),
image_size: None,
}
}
}
@ -80,4 +82,19 @@ impl Generator {
..self
}
}
/// Configures the Generator to include a `s=<image size>` in the URL.
///
/// ```rust
/// use gravatar_rs::Generator;
///
/// // Get 128px images instead of the default 80px.
/// Generator::default().set_image_size(128);
/// ```
pub fn set_image_size(self, image_size: i32) -> Self {
Self {
image_size: Some(image_size),
..self
}
}
}