Skip to content

Commit

Permalink
feat: remove const trait impl (#2522)
Browse files Browse the repository at this point in the history
  • Loading branch information
indietyp authored May 8, 2023
1 parent b3a0b35 commit ff48a35
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 216 deletions.
66 changes: 24 additions & 42 deletions libs/antsi/src/color.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::macros::impl_const;

/// Basic colors variants
///
/// ## Support
Expand Down Expand Up @@ -425,67 +423,51 @@ pub enum Color {
Cmyk(CmykColor),
}

impl_const! {
impl const? From<BasicColor> for Color {
fn from(value: BasicColor) -> Self {
Self::Basic(value)
}
impl From<BasicColor> for Color {
fn from(value: BasicColor) -> Self {
Self::Basic(value)
}
}

impl_const! {
impl const? From<BrightColor> for Color {
fn from(value: BrightColor) -> Self {
Self::Bright(value)
}
impl From<BrightColor> for Color {
fn from(value: BrightColor) -> Self {
Self::Bright(value)
}
}

impl_const! {
impl const? From<IndexedColor> for Color {
fn from(value: IndexedColor) -> Self {
Self::Indexed(value)
}
impl From<IndexedColor> for Color {
fn from(value: IndexedColor) -> Self {
Self::Indexed(value)
}
}

impl_const! {
impl const? From<RgbColor> for Color {
fn from(value: RgbColor) -> Self {
Self::Rgb(value)
}
impl From<RgbColor> for Color {
fn from(value: RgbColor) -> Self {
Self::Rgb(value)
}
}

#[cfg(feature = "rgba")]
impl_const! {
impl const? From<RgbaColor> for Color {
fn from(value: RgbaColor) -> Self {
Self::Rgba(value)
}
impl From<RgbaColor> for Color {
fn from(value: RgbaColor) -> Self {
Self::Rgba(value)
}
}

impl_const! {
impl const? From<CmyColor> for Color {
fn from(value: CmyColor) -> Self {
Self::Cmy(value)
}
impl From<CmyColor> for Color {
fn from(value: CmyColor) -> Self {
Self::Cmy(value)
}
}

impl_const! {
impl const? From<CmykColor> for Color {
fn from(value: CmykColor) -> Self {
Self::Cmyk(value)
}
impl From<CmykColor> for Color {
fn from(value: CmykColor) -> Self {
Self::Cmyk(value)
}
}

impl_const! {
impl const? From<TransparentColor> for Color {
fn from(value: TransparentColor) -> Self {
Self::Transparent(value)
}
impl From<TransparentColor> for Color {
fn from(value: TransparentColor) -> Self {
Self::Transparent(value)
}
}
128 changes: 39 additions & 89 deletions libs/antsi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// Good reference to begin with: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
#![no_std]
#![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))]
#![cfg_attr(nightly, feature(const_trait_impl))]
#![cfg_attr(
not(miri),
doc(test(attr(deny(warnings, clippy::pedantic, clippy::nursery))))
Expand All @@ -34,12 +33,9 @@ pub use decorations::{Decorations, Frame};
pub use font::FontScript;
pub use font::{Blinking, Font, FontFamily, FontWeight, Underline};

use crate::macros::impl_const;

mod color;
mod decorations;
mod font;
mod macros;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Foreground(Color);
Expand All @@ -56,14 +52,12 @@ impl Foreground {
}
}

impl_const! {
impl<T> const? From<T> for Foreground
where
T: ~const Into<Color>
{
fn from(value: T) -> Self {
Self(value.into())
}
impl<T> From<T> for Foreground
where
T: Into<Color>,
{
fn from(value: T) -> Self {
Self(value.into())
}
}

Expand All @@ -82,14 +76,12 @@ impl Background {
}
}

impl_const! {
impl<T> const? From<T> for Background
where
T: ~const Into<Color>
{
fn from(value: T) -> Self {
Self(value.into())
}
impl<T> From<T> for Background
where
T: Into<Color>,
{
fn from(value: T) -> Self {
Self(value.into())
}
}

Expand All @@ -112,14 +104,12 @@ impl UnderlineColor {
}

#[cfg(feature = "underline-color")]
impl_const! {
impl<T> const? From<T> for UnderlineColor
where
T: ~const Into<Color>
{
fn from(value: T) -> Self {
Self(value.into())
}
impl<T> From<T> for UnderlineColor
where
T: Into<Color>,
{
fn from(value: T) -> Self {
Self(value.into())
}
}

Expand Down Expand Up @@ -159,78 +149,38 @@ pub struct Style {
}

impl Style {
impl_const! {
#[nightly]
#[must_use]
pub const fn with_foreground(mut self, color: impl ~const Into<Foreground>) -> Self {
self.foreground = Some(color.into());

self
}
}

impl_const! {
#[stable]
#[must_use]
pub const fn with_foreground(mut self, color: Foreground) -> Self {
self.foreground = Some(color);

self
}
}

impl_const! {
#[nightly]
#[must_use]
pub const fn with_background(mut self, color: impl ~const Into<Background>) -> Self {
self.background = Some(color.into());

self
}
}

impl_const! {
#[stable]
#[must_use]
pub const fn with_background(mut self, color: Background) -> Self {
self.background = Some(color);

self
#[must_use]
pub const fn new() -> Self {
Self {
font: Font::new(),
decorations: Decorations::new(),
foreground: None,
background: None,
#[cfg(feature = "underline-color")]
underline_color: None,
}
}

#[cfg(feature = "underline-color")]
impl_const! {
#[nightly]
#[must_use]
pub const fn with_underline_color(mut self, color: impl ~const Into<UnderlineColor>) -> Self {
self.underline_color = Some(color.into());
#[must_use]
pub const fn with_underline_color(mut self, color: UnderlineColor) -> Self {
self.underline_color = Some(color);

self
}
self
}

#[cfg(feature = "underline-color")]
impl_const! {
#[stable]
#[must_use]
pub const fn with_underline_color(mut self, color: UnderlineColor) -> Self {
self.underline_color = Some(color);
#[must_use]
pub const fn with_background(mut self, color: Background) -> Self {
self.background = Some(color);

self
}
self
}

#[must_use]
pub const fn new() -> Self {
Self {
font: Font::new(),
decorations: Decorations::new(),
foreground: None,
background: None,
#[cfg(feature = "underline-color")]
underline_color: None,
}
pub const fn with_foreground(mut self, color: Foreground) -> Self {
self.foreground = Some(color);

self
}

#[must_use]
Expand Down
85 changes: 0 additions & 85 deletions libs/antsi/src/macros.rs

This file was deleted.

0 comments on commit ff48a35

Please sign in to comment.