[O] Shorten
This commit is contained in:
parent
981602b690
commit
d5751e06af
1 changed files with 6 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::num::{NonZeroU8, NonZeroUsize};
|
use std::num::{NonZeroU8, NonZeroUsize};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as _};
|
use anyhow::{anyhow, Result, Context as _};
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use palette::num::ClampAssign as _;
|
use palette::num::ClampAssign as _;
|
||||||
use palette::{IntoColorMut as _, LinSrgb, Okhsl, Srgb};
|
use palette::{IntoColorMut as _, LinSrgb, Okhsl, Srgb};
|
||||||
|
|
@ -28,14 +28,14 @@ impl ColorProfile {
|
||||||
Self { colors }
|
Self { colors }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_hex_colors<S>(hex_colors: Vec<S>) -> anyhow::Result<Self>
|
pub fn from_hex_colors<S>(hex_colors: Vec<S>) -> Result<Self>
|
||||||
where
|
where
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
{
|
{
|
||||||
let colors = hex_colors
|
let colors = hex_colors
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.as_ref().parse())
|
.map(|s| s.as_ref().parse())
|
||||||
.collect::<anyhow::Result<_, _>>()
|
.collect::<Result<_, _>>()
|
||||||
.context("failed to parse hex colors")?;
|
.context("failed to parse hex colors")?;
|
||||||
Ok(Self::new(colors))
|
Ok(Self::new(colors))
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ impl ColorProfile {
|
||||||
///
|
///
|
||||||
/// * `weights` - Weights of each color (`weights[i]` = how many times
|
/// * `weights` - Weights of each color (`weights[i]` = how many times
|
||||||
/// `colors[i]` appears)
|
/// `colors[i]` appears)
|
||||||
pub fn with_weights(&self, weights: Vec<u8>) -> anyhow::Result<Self> {
|
pub fn with_weights(&self, weights: Vec<u8>) -> Result<Self> {
|
||||||
if weights.len() != self.colors.len() {
|
if weights.len() != self.colors.len() {
|
||||||
debug!(?weights, ?self.colors, "length mismatch between `weights` and `colors`");
|
debug!(?weights, ?self.colors, "length mismatch between `weights` and `colors`");
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
|
|
@ -65,7 +65,7 @@ impl ColorProfile {
|
||||||
|
|
||||||
/// Creates a new color profile, with the colors spread to the specified
|
/// Creates a new color profile, with the colors spread to the specified
|
||||||
/// length.
|
/// length.
|
||||||
pub fn with_length(&self, length: NonZeroU8) -> anyhow::Result<Self> {
|
pub fn with_length(&self, length: NonZeroU8) -> Result<Self> {
|
||||||
let orig_len = self.colors.len();
|
let orig_len = self.colors.len();
|
||||||
let orig_len: NonZeroUsize = orig_len.try_into().expect("`colors` should not be empty");
|
let orig_len: NonZeroUsize = orig_len.try_into().expect("`colors` should not be empty");
|
||||||
let orig_len: NonZeroU8 = orig_len
|
let orig_len: NonZeroU8 = orig_len
|
||||||
|
|
@ -119,7 +119,7 @@ impl ColorProfile {
|
||||||
color_mode: AnsiMode,
|
color_mode: AnsiMode,
|
||||||
foreground_background: ForegroundBackground,
|
foreground_background: ForegroundBackground,
|
||||||
space_only: bool,
|
space_only: bool,
|
||||||
) -> anyhow::Result<String>
|
) -> Result<String>
|
||||||
where
|
where
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue