Skip to content

Commit 6a4f2ab

Browse files
authored
Merge pull request #29 from benedikt-schaber/feat/colorlifetime
feat!: allow `Color::Named` with limited lifetimes
2 parents 9dea507 + 9a137d4 commit 6a4f2ab

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
33

4+
## Unreleased
5+
#### Features
6+
- BREAKING: allow `Color::Named` with limited lifetimes - benedikt-schaber
7+
48
## 0.8.0 - 2025-07-12
59

610
- Updated to rust 2024 edition

src/color.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::fmt::{Display, Formatter, Result};
22

33
#[derive(Debug, Clone, Copy, PartialEq)]
4-
pub enum Color {
5-
Named(&'static str),
4+
pub enum Color<'a> {
5+
Named(&'a str),
66
Rgb(u8, u8, u8),
77
Hex(u32),
88
Hsl(u16, u8, u8),
99
}
1010

11-
impl Display for Color {
11+
impl Display for Color<'_> {
1212
fn fmt(&self, fmt: &mut Formatter) -> Result {
1313
match self {
1414
Color::Named(name) => write!(fmt, "{name}"),

src/style.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ pub enum LineJoin {
8585
}
8686

8787
#[derive(Debug, Clone, PartialEq)]
88-
pub struct Style {
88+
pub struct Style<'a> {
8989
pub opacity: Option<f32>,
90-
pub fill: Option<Color>,
90+
pub fill: Option<Color<'a>>,
9191
pub fill_opacity: Option<f32>,
92-
pub stroke_color: Option<Color>,
92+
pub stroke_color: Option<Color<'a>>,
9393
pub stroke_width: Option<f32>,
9494
pub stroke_opacity: Option<f32>,
9595
pub stroke_dasharray: Option<Vec<f32>>,
@@ -98,7 +98,7 @@ pub struct Style {
9898
pub radius: f32,
9999
}
100100

101-
impl Default for Style {
101+
impl Default for Style<'_> {
102102
fn default() -> Self {
103103
Self {
104104
opacity: None,
@@ -115,7 +115,7 @@ impl Default for Style {
115115
}
116116
}
117117

118-
impl Display for Style {
118+
impl Display for Style<'_> {
119119
fn fmt(&self, fmt: &mut Formatter) -> Result {
120120
if let Some(opacity) = self.opacity {
121121
write!(fmt, r#" opacity="{opacity}""#)?;

src/svg.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct Svg<'a> {
66
pub items: Vec<&'a dyn ToSvgStr>,
77
pub siblings: Vec<Svg<'a>>,
88
pub viewbox: ViewBox,
9-
pub style: Style,
9+
pub style: Style<'a>,
1010
pub width: Option<Unit>,
1111
pub height: Option<Unit>,
1212
}
@@ -17,7 +17,7 @@ impl<'a> Svg<'a> {
1717
self
1818
}
1919

20-
pub fn with_style(mut self, style: &Style) -> Self {
20+
pub fn with_style(mut self, style: &Style<'a>) -> Self {
2121
self.style = style.clone();
2222
for sibling in &mut self.siblings {
2323
*sibling = sibling.clone().with_style(style);
@@ -30,7 +30,7 @@ impl<'a> Svg<'a> {
3030
self
3131
}
3232

33-
pub fn with_color(mut self, color: Color) -> Self {
33+
pub fn with_color(mut self, color: Color<'a>) -> Self {
3434
self.style.fill = Some(color);
3535
self.style.stroke_color = Some(color);
3636
for sibling in &mut self.siblings {
@@ -47,7 +47,7 @@ impl<'a> Svg<'a> {
4747
self
4848
}
4949

50-
pub fn with_fill_color(mut self, fill: Color) -> Self {
50+
pub fn with_fill_color(mut self, fill: Color<'a>) -> Self {
5151
self.style.fill = Some(fill);
5252
for sibling in &mut self.siblings {
5353
*sibling = sibling.clone().with_fill_color(fill);
@@ -79,7 +79,7 @@ impl<'a> Svg<'a> {
7979
self
8080
}
8181

82-
pub fn with_stroke_color(mut self, stroke_color: Color) -> Self {
82+
pub fn with_stroke_color(mut self, stroke_color: Color<'a>) -> Self {
8383
self.style.stroke_color = Some(stroke_color);
8484
for sibling in &mut self.siblings {
8585
*sibling = sibling.clone().with_stroke_color(stroke_color);

0 commit comments

Comments
 (0)