Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antsi: remove const trait implementations #2522

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.