refactor: derive(Cast) for ArtifactKind

This commit is contained in:
Tobias Schmitz 2025-06-25 14:54:16 +02:00
parent e6341c0fe4
commit 2d6e3b6151
No known key found for this signature in database

View File

@ -1,5 +1,5 @@
use ecow::EcoString; use ecow::EcoString;
use typst_macros::{cast, elem}; use typst_macros::{cast, elem, Cast};
use crate::diag::SourceResult; use crate::diag::SourceResult;
use crate::engine::Engine; use crate::engine::Engine;
@ -200,7 +200,7 @@ pub struct ArtifactElem {
pub body: Content, pub body: Content,
} }
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Cast)]
pub enum ArtifactKind { pub enum ArtifactKind {
/// Page header artifacts. /// Page header artifacts.
Header, Header,
@ -213,20 +213,6 @@ pub enum ArtifactKind {
Other, Other,
} }
cast! {
ArtifactKind,
self => match self {
ArtifactKind::Header => "header".into_value(),
ArtifactKind::Footer => "footer".into_value(),
ArtifactKind::Page => "page".into_value(),
ArtifactKind::Other => "other".into_value(),
},
"header" => Self::Header,
"footer" => Self::Footer,
"page" => Self::Page,
"other" => Self::Other,
}
impl Show for Packed<ArtifactElem> { impl Show for Packed<ArtifactElem> {
#[typst_macros::time(name = "pdf.artifact", span = self.span())] #[typst_macros::time(name = "pdf.artifact", span = self.span())]
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {