I would be happy to clone values from its, however TextAttribute doesn't implement a Clone trait. (PR #484)
I research all variants of TextAttribute and all its variats implements PartialEq and Debug, so TextAttribute could to derive this additional traits too. (PR #485)
more detail code example isssue
```Rust
#[derive(Default)]
struct StyledRanges {
separator: Vec>,
errors: Vec>,
}
impl StyledRanges {
const SEPARATOR_STYLE: &'static [TextAttribute; 1] = &[
TextAttribute::TextColor(Color::BLUE)
];
const ERRORS_STYLE: &'static [TextAttribute; 2] = &[
TextAttribute::TextColor(Color::YELLOW),
TextAttribute::Strikethrough(true)
];
}
let (ranges, text): (StyledRanges, String) = logger.get_text_with_errors();
let mut attrs: Vec<(Range, &[TextAttribute])> = std::iter::empty()
.chain(&mut ranges.separator.into_iter().zip(std::iter::repeat(&StyledRanges::SEPARATOR_STYLE[..])))
.chain(&mut ranges.errors.into_iter().zip(std::iter::repeat(&StyledRanges::ERRORS_STYLE[..])))
.collect();
// sort all types by `start` key due avoid assert
// https://github.com/linebender/piet/blob/8f7bc70a097d585205573442b970ec087d4e8f3b/piet-cairo/src/text.rs#L265-L268
attrs.sort_by_key(|(r, _)| r.start);
let mut text_layout: PietTextLayoutBuilder = ctx // &mut PaintCtx
.text() // &mut PietText
.new_text_layout(text) //PietTextLayoutBuilder
.max_width(rect.width());
for (range /* Range */, attrs /* &[TextAttribute] */) in attrs {
for attr /* &TextAttribute */ in attrs {
text_layout = text_layout.range_attribute(range.clone(), attr.clone()); // <--- I cannot clone `attr` here!
}
}
let text_layout = text_layout.build().unwrap();
```
I have a
'static
const array with some types of text styles:I would be happy to clone values from its, however
TextAttribute
doesn't implement aClone
trait. (PR #484)I research all variants of
TextAttribute
and all its variats implementsPartialEq
andDebug
, soTextAttribute
could to derive this additional traits too. (PR #485)more detail code example isssue
```Rust #[derive(Default)] struct StyledRanges { separator: Vec