Skip to content
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
18 changes: 9 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ fn make_color_name_display_impl_tokens(sample_flavor: &Flavor) -> TokenStream {
}
});
quote! {
impl std::fmt::Display for ColorName {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Display for ColorName {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
#(#match_arms),*
}
Expand All @@ -562,8 +562,8 @@ fn make_ansi_color_name_display_impl_tokens(sample_flavor: &Flavor) -> TokenStre
}
});
quote! {
impl std::fmt::Display for AnsiColorName {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Display for AnsiColorName {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
#(#match_arms),*
}
Expand All @@ -581,8 +581,8 @@ fn make_ansi_color_pair_name_display_impl_tokens(sample_flavor: &Flavor) -> Toke
}
});
quote! {
impl std::fmt::Display for AnsiColorPairName {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Display for AnsiColorPairName {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
#(#match_arms),*
}
Expand Down Expand Up @@ -695,7 +695,7 @@ fn make_color_name_fromstr_impl_tokens(sample_flavor: &Flavor) -> TokenStream {
})
.collect::<Vec<_>>();
quote! {
impl std::str::FromStr for ColorName {
impl core::str::FromStr for ColorName {
type Err = ParseColorNameError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand All @@ -718,7 +718,7 @@ fn make_ansi_color_name_fromstr_impl_tokens(sample_flavor: &Flavor) -> TokenStre
})
.collect::<Vec<_>>();
quote! {
impl std::str::FromStr for AnsiColorName {
impl core::str::FromStr for AnsiColorName {
type Err = ParseColorNameError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand All @@ -741,7 +741,7 @@ fn make_ansi_color_pair_name_fromstr_impl_tokens(sample_flavor: &Flavor) -> Toke
})
.collect::<Vec<_>>();
quote! {
impl std::str::FromStr for AnsiColorPairName {
impl core::str::FromStr for AnsiColorPairName {
type Err = ParseColorNameError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down
22 changes: 15 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
//! This adds [serde](https://crates.io/crates/serde) as a dependency.
//!
//! Example: [`examples/serde.rs`](https://github.com/catppuccin/rust/blob/main/examples/serde.rs)
use std::{fmt, marker::PhantomData, ops::Index, str::FromStr};
#![no_std]

extern crate alloc;

use core::{fmt, marker::PhantomData, ops::Index, str::FromStr};

include!(concat!(env!("OUT_DIR"), "/generated_palette.rs"));

Expand Down Expand Up @@ -272,6 +276,9 @@ mod _hex {

use crate::{Hex, Rgb};

use alloc::string::String;
use alloc::string::ToString;

impl Serialize for Hex {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down Expand Up @@ -311,8 +318,8 @@ impl fmt::Display for FlavorName {
/// Error type for parsing a [`FlavorName`] from a string.
#[derive(Debug, PartialEq, Eq)]
pub struct ParseFlavorNameError;
impl std::error::Error for ParseFlavorNameError {}
impl std::fmt::Display for ParseFlavorNameError {
impl core::error::Error for ParseFlavorNameError {}
impl core::fmt::Display for ParseFlavorNameError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
Expand Down Expand Up @@ -515,8 +522,8 @@ impl<'a> IntoIterator for &'a Flavor {
/// Error type for parsing a [`ColorName`] from a string.
#[derive(Debug, PartialEq, Eq)]
pub struct ParseColorNameError;
impl std::error::Error for ParseColorNameError {}
impl std::fmt::Display for ParseColorNameError {
impl core::error::Error for ParseColorNameError {}
impl core::fmt::Display for ParseColorNameError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "invalid color identifier")
}
Expand Down Expand Up @@ -570,6 +577,7 @@ impl From<(f64, f64, f64)> for Hsl {
#[cfg(feature = "ansi-term")]
mod ansi_term {
use crate::{AnsiColor, Color};
use alloc::borrow::ToOwned;

impl Color {
/// Paints the given input with a color à la [ansi_term](https://docs.rs/ansi_term/latest/ansi_term/)
Expand All @@ -578,7 +586,7 @@ mod ansi_term {
input: I,
) -> ansi_term::ANSIGenericString<'a, S>
where
I: Into<std::borrow::Cow<'a, S>>,
I: Into<alloc::borrow::Cow<'a, S>>,
<S as ToOwned>::Owned: core::fmt::Debug,
{
ansi_term::Color::RGB(self.rgb.r, self.rgb.g, self.rgb.b).paint(input)
Expand All @@ -592,7 +600,7 @@ mod ansi_term {
input: I,
) -> ansi_term::ANSIGenericString<'a, S>
where
I: Into<std::borrow::Cow<'a, S>>,
I: Into<alloc::borrow::Cow<'a, S>>,
<S as ToOwned>::Owned: core::fmt::Debug,
{
ansi_term::Color::RGB(self.rgb.r, self.rgb.g, self.rgb.b).paint(input)
Expand Down