From 880b1847bd4170ce80be5781c2163ba085cdcaff Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 13 Mar 2023 21:39:38 +0100 Subject: Derive `Cast` for enums --- library/src/visualize/image.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'library/src/visualize') diff --git a/library/src/visualize/image.rs b/library/src/visualize/image.rs index 29a04c96..4509cf5a 100644 --- a/library/src/visualize/image.rs +++ b/library/src/visualize/image.rs @@ -113,33 +113,15 @@ impl Layout for ImageNode { } /// How an image should adjust itself to a given area. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)] pub enum ImageFit { - /// The image should completely cover the area. + /// The image should completely cover the area. This is the default. Cover, /// The image should be fully contained in the area. Contain, - /// The image should be stretched so that it exactly fills the area. - Stretch, -} - -cast_from_value! { - ImageFit, - /// The image should completely cover the area. This is the default. - "cover" => Self::Cover, - /// The image should be fully contained in the area. - "contain" => Self::Contain, /// The image should be stretched so that it exactly fills the area, even if /// this means that the image will be distorted. - "stretch" => Self::Stretch, -} - -cast_to_value! { - fit: ImageFit => Value::from(match fit { - ImageFit::Cover => "cover", - ImageFit::Contain => "contain", - ImageFit::Stretch => "stretch", - }) + Stretch, } /// Load an image from a path. -- cgit v1.2.3