deploy: 95756b1a57
This commit is contained in:
commit
0fa87f2b35
16382 changed files with 734838 additions and 0 deletions
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `FromColorUnclamped` derive in crate `cosmic`."><title>FromColorUnclamped in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc derive"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Derive Macro <span class="derive">FromColorUnclamped</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>#[derive(FromColorUnclamped)]
|
||||
{
|
||||
<span class="comment">// Attributes available to this derive:</span>
|
||||
#[palette]
|
||||
}
|
||||
</code></pre></section></div></main></body></html>
|
||||
316
cosmic/cosmic_theme/palette/convert/index.html
Normal file
316
cosmic/cosmic_theme/palette/convert/index.html
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Traits for converting between color spaces."><title>cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module convert</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#in-place-conversion" title="In-place Conversion">In-place Conversion</a></li><li><a href="#deriving" title="Deriving">Deriving</a><ul><li><a href="#configuration-attributes" title="Configuration Attributes">Configuration Attributes</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#derives" title="Derive Macros">Derive Macros</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a></div><h1>Module <span>convert</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/lib.rs.html#352">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Traits for converting between color spaces.</p>
|
||||
<p>Each color space type, such as <a href="../rgb/struct.Rgb.html" title="struct cosmic::cosmic_theme::palette::rgb::Rgb"><code>Rgb</code></a> and
|
||||
<a href="../struct.Hsl.html" title="struct cosmic::cosmic_theme::palette::Hsl"><code>Hsl</code></a>, implement a number of conversion traits:</p>
|
||||
<ul>
|
||||
<li><a href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor"><code>FromColor</code></a> - Similar to <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From"><code>From</code></a>, converts from another color space.</li>
|
||||
<li><a href="../trait.IntoColor.html" title="trait cosmic::cosmic_theme::palette::IntoColor"><code>IntoColor</code></a> - Similar to <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into"><code>Into</code></a>, converts into another color space.</li>
|
||||
<li><a href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped"><code>FromColorUnclamped</code></a> - The same as <a href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor"><code>FromColor</code></a>, but the resulting
|
||||
values may be outside the typical bounds.</li>
|
||||
<li><a href="trait.IntoColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorUnclamped"><code>IntoColorUnclamped</code></a> - The same as <a href="../trait.IntoColor.html" title="trait cosmic::cosmic_theme::palette::IntoColor"><code>IntoColor</code></a>, but the resulting
|
||||
values may be outside the typical bounds.</li>
|
||||
</ul>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{FromColor, IntoColor, Srgb, Hsl};
|
||||
|
||||
<span class="kw">let </span>rgb = Srgb::new(<span class="number">0.3f32</span>, <span class="number">0.8</span>, <span class="number">0.1</span>);
|
||||
|
||||
<span class="kw">let </span>hsl1: Hsl = rgb.into_color();
|
||||
<span class="kw">let </span>hsl2 = Hsl::from_color(rgb);</code></pre></div>
|
||||
<p>Most of the color space types can be converted directly to each other, with
|
||||
these traits. If you look at the implemented traits for any color type, you
|
||||
will see a substantial list of <code>FromColorUnclamped</code> implementations. There
|
||||
are, however, exceptions and restrictions in some cases:</p>
|
||||
<ul>
|
||||
<li><strong>It’s not always possible to change the component type while
|
||||
converting.</strong> This can only be enabled in specific cases, to allow type
|
||||
inference to work. The input and output component types need to be the
|
||||
same in the general case.</li>
|
||||
<li><strong>It’s not always possible to change meta types while converting.</strong> Meta
|
||||
types are the additional input types on colors, such as white point or RGB
|
||||
standard. Similar to component types, these are generally restricted to
|
||||
help type inference.</li>
|
||||
<li><strong>Some color spaces want specific component types.</strong> For example,
|
||||
<a href="../struct.Xyz.html" title="struct cosmic::cosmic_theme::palette::Xyz"><code>Xyz</code></a> and many other color spaces require real-ish numbers
|
||||
(<code>f32</code>, <code>f64</code>, etc.).</li>
|
||||
<li><strong>Some color spaces want specific meta types.</strong> For example,
|
||||
<a href="../struct.Oklab.html" title="struct cosmic::cosmic_theme::palette::Oklab"><code>Oklab</code></a> requires the white point to be
|
||||
<a href="../white_point/struct.D65.html" title="struct cosmic::cosmic_theme::palette::white_point::D65"><code>D65</code></a>.</li>
|
||||
</ul>
|
||||
<p>These limitations are usually the reason for why the compiler gives an error
|
||||
when calling <code>into_color</code>, <code>from_color</code>, or the corresponding unclamped
|
||||
methods. They are possible to work around by splitting the conversion into
|
||||
multiple steps.</p>
|
||||
<h2 id="in-place-conversion"><a class="doc-anchor" href="#in-place-conversion">§</a>In-place Conversion</h2>
|
||||
<p>It’s possible for some color spaces to be converted in-place, meaning the
|
||||
destination color will use the memory space of the source color. The
|
||||
requirement for this is that the source and destination color types have the
|
||||
same memory layout. That is, the same component types and the same number of
|
||||
components. This is verified by the <a href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast"><code>ArrayCast</code></a>
|
||||
trait.</p>
|
||||
<p>In-place conversion is done with the <a href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut"><code>FromColorMut</code></a> and <a href="../trait.IntoColorMut.html" title="trait cosmic::cosmic_theme::palette::IntoColorMut"><code>IntoColorMut</code></a>
|
||||
traits, as well as their unclamped counterparts, <a href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut"><code>FromColorUnclampedMut</code></a>
|
||||
and <a href="trait.IntoColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorUnclampedMut"><code>IntoColorUnclampedMut</code></a>. They work for both single colors and slices
|
||||
of colors.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{convert::FromColorMut, Srgb, Hsl, Hwb};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>rgb_colors: Vec<Srgb<f32>> = <span class="macro">vec!</span>[<span class="comment">/* ... */</span>];
|
||||
|
||||
{
|
||||
<span class="comment">// Creates a scope guard that prevents `rgb_colors` from being modified as RGB.
|
||||
</span><span class="kw">let </span>hsl_colors = <[Hsl]>::from_color_mut(<span class="kw-2">&mut </span>rgb_colors);
|
||||
|
||||
<span class="comment">// The converted colors can be converted again, without keeping the previous guard around.
|
||||
</span><span class="kw">let </span>hwb_colors = hsl_colors.then_into_color_mut::<[Hwb]>();
|
||||
|
||||
<span class="comment">// The colors are automatically converted back to RGB at the end of the scope.
|
||||
// The use of `then_into_color_mut` above makes this conversion a single HWB -> RGB step,
|
||||
// instead of HWB -> HSL -> RGB, since it consumed the HSL guard.
|
||||
</span>}</code></pre></div>
|
||||
<h2 id="deriving"><a class="doc-anchor" href="#deriving">§</a>Deriving</h2>
|
||||
<p><code>FromColorUnclamped</code> can be derived in a mostly automatic way. The other
|
||||
traits are blanket implemented based on it. The default minimum requirement
|
||||
is to implement <code>FromColorUnclamped<Xyz></code>, but it can also be customized to
|
||||
make use of generics and have other manual implementations.</p>
|
||||
<p>It is also recommended to derive or implement
|
||||
<a href="../trait.WithAlpha.html" title="trait cosmic::cosmic_theme::palette::WithAlpha"><code>WithAlpha</code></a>, to be able to convert between all <code>Alpha</code>
|
||||
wrapped color types.</p>
|
||||
<h3 id="configuration-attributes"><a class="doc-anchor" href="#configuration-attributes">§</a>Configuration Attributes</h3>
|
||||
<p>The derives can be configured using one or more <code>#[palette(...)]</code>
|
||||
attributes. They can be attached to either the item itself, or to the
|
||||
fields.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[derive(FromColorUnclamped)]
|
||||
#[palette(
|
||||
component = <span class="string">"T"</span>,
|
||||
rgb_standard = <span class="string">"S"</span>,
|
||||
)]
|
||||
#[repr(C)]
|
||||
</span><span class="kw">struct </span>ExampleType<S, T> {
|
||||
<span class="comment">// ...
|
||||
</span><span class="attr">#[palette(alpha)]
|
||||
</span>alpha: T,
|
||||
standard: std::marker::PhantomData<S>,
|
||||
}
|
||||
</code></pre></div>
|
||||
<h4 id="item-attributes"><a class="doc-anchor" href="#item-attributes">§</a>Item Attributes</h4>
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>skip_derives(Luma, Rgb)</code>: No conversion derives will be implemented for
|
||||
these colors. They are instead to be implemented manually, and serve as the
|
||||
basis for the automatic implementations.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>white_point = "some::white_point::Type"</code>: Sets the white point type that
|
||||
should be used when deriving. The default is <code>D65</code>, but it may be any other
|
||||
type, including type parameters.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>component = "some::component::Type"</code>: Sets the color component type that
|
||||
should be used when deriving. The default is <code>f32</code>, but it may be any other
|
||||
type, including type parameters.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>rgb_standard = "some::rgb_standard::Type"</code>: Sets the RGB standard type
|
||||
that should be used when deriving. The default is to either use <code>Srgb</code> or a
|
||||
best effort to convert between standards, but sometimes it has to be set to
|
||||
a specific type. This also accepts type parameters.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>luma_standard = "some::rgb_standard::Type"</code>: Sets the Luma standard type
|
||||
that should be used when deriving, similar to <code>rgb_standard</code>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<h4 id="field-attributes"><a class="doc-anchor" href="#field-attributes">§</a>Field Attributes</h4>
|
||||
<ul>
|
||||
<li><code>alpha</code>: Specifies field as the color’s transparency value.</li>
|
||||
</ul>
|
||||
<h3 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h3>
|
||||
<p>Minimum requirements implementation:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::convert::FromColorUnclamped;
|
||||
<span class="kw">use </span>palette::{Srgb, Xyz, IntoColor};
|
||||
|
||||
<span class="doccomment">/// A custom version of Xyz that stores integer values from 0 to 100.
|
||||
</span><span class="attr">#[derive(PartialEq, Debug, FromColorUnclamped)]
|
||||
</span><span class="kw">struct </span>Xyz100 {
|
||||
x: u8,
|
||||
y: u8,
|
||||
z: u8,
|
||||
}
|
||||
|
||||
<span class="comment">// We have to implement at least one "manual" conversion. The default
|
||||
// is to and from `Xyz`, but it can be customized with `skip_derives(...)`.
|
||||
</span><span class="kw">impl </span>FromColorUnclamped<Xyz> <span class="kw">for </span>Xyz100 {
|
||||
<span class="kw">fn </span>from_color_unclamped(color: Xyz) -> Xyz100 {
|
||||
Xyz100 {
|
||||
x: (color.x * <span class="number">100.0</span>) <span class="kw">as </span>u8,
|
||||
y: (color.y * <span class="number">100.0</span>) <span class="kw">as </span>u8,
|
||||
z: (color.z * <span class="number">100.0</span>) <span class="kw">as </span>u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>FromColorUnclamped<Xyz100> <span class="kw">for </span>Xyz {
|
||||
<span class="kw">fn </span>from_color_unclamped(color: Xyz100) -> Xyz {
|
||||
Xyz::new(
|
||||
color.x <span class="kw">as </span>f32 / <span class="number">100.0</span>,
|
||||
color.y <span class="kw">as </span>f32 / <span class="number">100.0</span>,
|
||||
color.z <span class="kw">as </span>f32 / <span class="number">100.0</span>,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">// Start with an Xyz100 color.
|
||||
</span><span class="kw">let </span>xyz = Xyz100 {
|
||||
x: <span class="number">59</span>,
|
||||
y: <span class="number">75</span>,
|
||||
z: <span class="number">42</span>,
|
||||
};
|
||||
|
||||
<span class="comment">// Convert the color to sRGB.
|
||||
</span><span class="kw">let </span>rgb: Srgb = xyz.into_color();
|
||||
|
||||
<span class="macro">assert_eq!</span>(rgb.into_format(), Srgb::new(<span class="number">196u8</span>, <span class="number">238</span>, <span class="number">154</span>));</code></pre></div>
|
||||
<p>With generic components:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[macro_use]
|
||||
</span><span class="kw">extern crate </span>approx;
|
||||
|
||||
<span class="kw">use </span>palette::cast::{ComponentsAs, ArrayCast};
|
||||
<span class="kw">use </span>palette::rgb::{Rgb, RgbSpace, RgbStandard};
|
||||
<span class="kw">use </span>palette::encoding::Linear;
|
||||
<span class="kw">use </span>palette::white_point::D65;
|
||||
<span class="kw">use </span>palette::convert::{FromColorUnclamped, IntoColorUnclamped};
|
||||
<span class="kw">use </span>palette::{Hsv, Srgb, IntoColor};
|
||||
|
||||
<span class="doccomment">/// sRGB, but with a reversed memory layout.
|
||||
</span><span class="attr">#[derive(Copy, Clone, ArrayCast, FromColorUnclamped)]
|
||||
#[palette(
|
||||
skip_derives(Rgb),
|
||||
component = <span class="string">"T"</span>,
|
||||
rgb_standard = <span class="string">"palette::encoding::Srgb"
|
||||
</span>)]
|
||||
#[repr(C)] </span><span class="comment">// Makes sure the memory layout is as we want it.
|
||||
</span><span class="kw">struct </span>Bgr<T> {
|
||||
blue: T,
|
||||
green: T,
|
||||
red: T,
|
||||
}
|
||||
|
||||
<span class="comment">// It converts from and into any linear Rgb type that has the
|
||||
// D65 white point, which is the default if we don't specify
|
||||
// anything else with the `white_point` attribute argument.
|
||||
</span><span class="kw">impl</span><S, T> FromColorUnclamped<Bgr<T>> <span class="kw">for </span>Rgb<S, T>
|
||||
<span class="kw">where
|
||||
</span>S: RgbStandard,
|
||||
S::Space: RgbSpace<WhitePoint = D65>,
|
||||
Srgb<T>: IntoColorUnclamped<Rgb<S, T>>,
|
||||
{
|
||||
<span class="kw">fn </span>from_color_unclamped(color: Bgr<T>) -> Rgb<S, T> {
|
||||
Srgb::new(color.red, color.green, color.blue)
|
||||
.into_color_unclamped()
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><S, T> FromColorUnclamped<Rgb<S, T>> <span class="kw">for </span>Bgr<T>
|
||||
<span class="kw">where
|
||||
</span>S: RgbStandard,
|
||||
S::Space: RgbSpace<WhitePoint = D65>,
|
||||
Srgb<T>: FromColorUnclamped<Rgb<S, T>>,
|
||||
{
|
||||
<span class="kw">fn </span>from_color_unclamped(color: Rgb<S, T>) -> Bgr<T> {
|
||||
<span class="kw">let </span>color = Srgb::from_color_unclamped(color);
|
||||
Bgr {
|
||||
blue: color.blue,
|
||||
green: color.green,
|
||||
red: color.red,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>main() {
|
||||
<span class="kw">let </span>buffer = <span class="macro">vec!</span>[
|
||||
<span class="number">0.0f64</span>,
|
||||
<span class="number">0.0</span>,
|
||||
<span class="number">0.0</span>,
|
||||
<span class="number">0.0</span>,
|
||||
<span class="number">0.5</span>,
|
||||
<span class="number">0.25</span>,
|
||||
];
|
||||
<span class="kw">let </span>buffer: <span class="kw-2">&</span>[Bgr<<span class="kw">_</span>>] = buffer.components_as();
|
||||
<span class="kw">let </span>hsv: Hsv<<span class="kw">_</span>, f64> = buffer[<span class="number">1</span>].into_color();
|
||||
|
||||
<span class="macro">assert_relative_eq!</span>(hsv, Hsv::new(<span class="number">90.0</span>, <span class="number">1.0</span>, <span class="number">0.5</span>));
|
||||
}</code></pre></div>
|
||||
<p>With alpha component:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[macro_use]
|
||||
</span><span class="kw">extern crate </span>approx;
|
||||
|
||||
<span class="kw">use </span>palette::{LinSrgba, Srgb, IntoColor, WithAlpha};
|
||||
<span class="kw">use </span>palette::rgb::Rgb;
|
||||
<span class="kw">use </span>palette::convert::{FromColorUnclamped, IntoColorUnclamped};
|
||||
|
||||
<span class="doccomment">/// CSS style sRGB.
|
||||
</span><span class="attr">#[derive(PartialEq, Debug, FromColorUnclamped, WithAlpha)]
|
||||
#[palette(
|
||||
skip_derives(Rgb),
|
||||
rgb_standard = <span class="string">"palette::encoding::Srgb"
|
||||
</span>)]
|
||||
</span><span class="kw">struct </span>CssRgb {
|
||||
red: u8,
|
||||
green: u8,
|
||||
blue: u8,
|
||||
<span class="attr">#[palette(alpha)]
|
||||
</span>alpha: f32,
|
||||
}
|
||||
|
||||
<span class="comment">// We will write a conversion function for opaque RGB and
|
||||
// `impl_default_conversions` will take care of preserving
|
||||
// the transparency for us.
|
||||
</span><span class="kw">impl</span><S> FromColorUnclamped<Rgb<S, f32>> <span class="kw">for </span>CssRgb
|
||||
<span class="kw">where
|
||||
</span>Srgb<f32>: FromColorUnclamped<Rgb<S, f32>>
|
||||
{
|
||||
<span class="kw">fn </span>from_color_unclamped(color: Rgb<S, f32>) -> CssRgb{
|
||||
<span class="kw">let </span>srgb = Srgb::from_color_unclamped(color)
|
||||
.into_format();
|
||||
|
||||
CssRgb {
|
||||
red: srgb.red,
|
||||
green: srgb.green,
|
||||
blue: srgb.blue,
|
||||
alpha: <span class="number">1.0
|
||||
</span>}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><S> FromColorUnclamped<CssRgb> <span class="kw">for </span>Rgb<S, f32>
|
||||
<span class="kw">where
|
||||
</span>Srgb<f32>: IntoColorUnclamped<Rgb<S, f32>>
|
||||
{
|
||||
<span class="kw">fn </span>from_color_unclamped(color: CssRgb) -> Rgb<S, f32>{
|
||||
Srgb::new(color.red, color.green, color.blue)
|
||||
.into_format()
|
||||
.into_color_unclamped()
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>main() {
|
||||
<span class="kw">let </span>css_color = CssRgb {
|
||||
red: <span class="number">187</span>,
|
||||
green: <span class="number">0</span>,
|
||||
blue: <span class="number">255</span>,
|
||||
alpha: <span class="number">0.3</span>,
|
||||
};
|
||||
<span class="kw">let </span>color: LinSrgba = css_color.into_color();
|
||||
|
||||
<span class="macro">assert_relative_eq!</span>(color, LinSrgba::new(<span class="number">0.496933</span>, <span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.3</span>));
|
||||
}</code></pre></div>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.FromColorMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorMutGuard">From<wbr>Color<wbr>MutGuard</a></dt><dd>A scope guard that restores the guarded colors to their original type when
|
||||
dropped.</dd><dt><a class="struct" href="struct.FromColorUnclampedMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard">From<wbr>Color<wbr>Unclamped<wbr>MutGuard</a></dt><dd>A scope guard that restores the guarded colors to their original type,
|
||||
without clamping, when dropped.</dd><dt><a class="struct" href="struct.OutOfBounds.html" title="struct cosmic::cosmic_theme::palette::convert::OutOfBounds">OutOf<wbr>Bounds</a></dt><dd>The error type for a color conversion that converted a color into a color
|
||||
with invalid values.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::convert::FromColor">From<wbr>Color</a></dt><dd>A trait for converting one color from another, in a possibly lossy way.</dd><dt><a class="trait" href="trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorMut">From<wbr>Color<wbr>Mut</a></dt><dd>Temporarily convert colors in place.</dd><dt><a class="trait" href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped">From<wbr>Color<wbr>Unclamped</a></dt><dd>A trait for unchecked conversion of one color from another.</dd><dt><a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">From<wbr>Color<wbr>Unclamped<wbr>Mut</a></dt><dd>Temporarily convert colors in place, without clamping.</dd><dt><a class="trait" href="trait.IntoColor.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColor">Into<wbr>Color</a></dt><dd>A trait for converting a color into another, in a possibly lossy way.</dd><dt><a class="trait" href="trait.IntoColorMut.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorMut">Into<wbr>Color<wbr>Mut</a></dt><dd>Temporarily convert colors in place. The <code>Into</code> counterpart to
|
||||
<a href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut"><code>FromColorMut</code></a>.</dd><dt><a class="trait" href="trait.IntoColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorUnclamped">Into<wbr>Color<wbr>Unclamped</a></dt><dd>A trait for unchecked conversion of a color into another.</dd><dt><a class="trait" href="trait.IntoColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorUnclampedMut">Into<wbr>Color<wbr>Unclamped<wbr>Mut</a></dt><dd>Temporarily convert colors in place. The <code>Into</code> counterpart to
|
||||
<a href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut"><code>FromColorUnclampedMut</code></a>.</dd><dt><a class="trait" href="trait.TryFromColor.html" title="trait cosmic::cosmic_theme::palette::convert::TryFromColor">TryFrom<wbr>Color</a></dt><dd>A trait for fallible conversion of one color from another.</dd><dt><a class="trait" href="trait.TryIntoColor.html" title="trait cosmic::cosmic_theme::palette::convert::TryIntoColor">TryInto<wbr>Color</a></dt><dd>A trait for fallible conversion of a color into another.</dd></dl><h2 id="derives" class="section-header">Derive Macros<a href="#derives" class="anchor">§</a></h2><dl class="item-table"><dt><a class="derive" href="derive.FromColorUnclamped.html" title="derive cosmic::cosmic_theme::palette::convert::FromColorUnclamped">From<wbr>Color<wbr>Unclamped</a></dt></dl></section></div></main></body></html>
|
||||
1
cosmic/cosmic_theme/palette/convert/sidebar-items.js
Normal file
1
cosmic/cosmic_theme/palette/convert/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"derive":["FromColorUnclamped"],"struct":["FromColorMutGuard","FromColorUnclampedMutGuard","OutOfBounds"],"trait":["FromColor","FromColorMut","FromColorUnclamped","FromColorUnclampedMut","IntoColor","IntoColorMut","IntoColorUnclamped","IntoColorUnclampedMut","TryFromColor","TryIntoColor"]};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
78
cosmic/cosmic_theme/palette/convert/struct.OutOfBounds.html
Normal file
78
cosmic/cosmic_theme/palette/convert/struct.OutOfBounds.html
Normal file
File diff suppressed because one or more lines are too long
41
cosmic/cosmic_theme/palette/convert/trait.FromColor.html
Normal file
41
cosmic/cosmic_theme/palette/convert/trait.FromColor.html
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait for converting one color from another, in a possibly lossy way."><title>FromColor in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">From<wbr>Color</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#the-difference-between-fromcolor-and-from" title="The Difference Between FromColor and From">The Difference Between FromColor and From</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.from_color" title="from_color">from_color</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">FromColor</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#40">Source</a> </span></div><pre class="rust item-decl"><code>pub trait FromColor<T>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
||||
// Required method
|
||||
fn <a href="#tymethod.from_color" class="fn">from_color</a>(t: T) -> Self;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait for converting one color from another, in a possibly lossy way.</p>
|
||||
<p><code>U: FromColor<T></code> is implemented for every type <code>U: FromColorUnclamped<T> + Clamp</code>, as well as for <code>Vec<T></code> and <code>Box<[T]></code> where <code>T</code> and <code>U</code> have the
|
||||
same memory layout.</p>
|
||||
<p>See <a href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped"><code>FromColorUnclamped</code></a> for a
|
||||
lossless version of this trait. See
|
||||
<a href="trait.TryFromColor.html" title="trait cosmic::cosmic_theme::palette::convert::TryFromColor"><code>TryFromColor</code></a> for a trait that gives an
|
||||
error when the result is out of bounds.</p>
|
||||
<h2 id="the-difference-between-fromcolor-and-from"><a class="doc-anchor" href="#the-difference-between-fromcolor-and-from">§</a>The Difference Between FromColor and From</h2>
|
||||
<p>The conversion traits, including <code>FromColor</code>, were added to gain even more
|
||||
flexibility than what <code>From</code> and the other standard library traits can give.
|
||||
There are a few subtle, but important, differences in their semantics:</p>
|
||||
<ul>
|
||||
<li><code>FromColor</code> and <code>IntoColor</code> are allowed to be lossy, meaning converting <code>A -> B -> A</code> may result in a different value than the original. This applies
|
||||
to <code>A -> A</code> as well.</li>
|
||||
<li><code>From<Self></code> and <code>Into<Self></code> are blanket implemented, while
|
||||
<code>FromColor<Self></code> and <code>IntoColor<Self></code> have to be manually implemented.
|
||||
This allows additional flexibility, such as allowing implementing
|
||||
<code>FromColor<Rgb<S2, T>> for Rgb<S1, T></code>.</li>
|
||||
<li>Implementing <code>FromColorUnclamped</code>,
|
||||
<a href="../trait.IsWithinBounds.html" title="trait cosmic::cosmic_theme::palette::IsWithinBounds"><code>IsWithinBounds</code></a> and <a href="../trait.Clamp.html" title="trait cosmic::cosmic_theme::palette::Clamp"><code>Clamp</code></a> is enough to get
|
||||
all the other conversion traits, while <code>From</code> and <code>Into</code> would not be
|
||||
possible to blanket implement in the same way. This also reduces the work
|
||||
that needs to be done by macros.</li>
|
||||
</ul>
|
||||
<p>See the <a href="index.html" title="mod cosmic::cosmic_theme::palette::convert"><code>convert</code></a> module for how to implement
|
||||
<code>FromColorUnclamped</code> for custom colors.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.from_color" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#50">Source</a><h4 class="code-header">fn <a href="#tymethod.from_color" class="fn">from_color</a>(t: T) -> Self</h4></section></summary><div class="docblock"><p>Convert from T with values clamped to the color defined bounds.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{IsWithinBounds, FromColor, Lch, Srgb};
|
||||
|
||||
<span class="kw">let </span>rgb = Srgb::from_color(Lch::new(<span class="number">50.0f32</span>, <span class="number">100.0</span>, -<span class="number">175.0</span>));
|
||||
<span class="macro">assert!</span>(rgb.is_within_bounds());</code></pre></div>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-FromColor%3CBox%3C%5BT%5D%3E%3E-for-Box%3C%5BU%5D%3E" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#88-91">Source</a><a href="#impl-FromColor%3CBox%3C%5BT%5D%3E%3E-for-Box%3C%5BU%5D%3E" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><<a class="struct" href="../../../cctk/sctk/reexports/client/backend/smallvec/alloc/boxed/struct.Box.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::boxed::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a>>> for <a class="struct" href="../../../cctk/sctk/reexports/client/backend/smallvec/alloc/boxed/struct.Box.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::boxed::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[U]</a>><div class="where">where
|
||||
T: <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>,
|
||||
U: <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a><Array = <T as <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>>::<a class="associatedtype" href="../cast/trait.ArrayCast.html#associatedtype.Array" title="type cosmic::cosmic_theme::palette::cast::ArrayCast::Array">Array</a>> + <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><T>,</div></h3></section><section id="impl-FromColor%3CVec%3CT%3E%3E-for-Vec%3CU%3E" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#64-67">Source</a><a href="#impl-FromColor%3CVec%3CT%3E%3E-for-Vec%3CU%3E" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><<a class="struct" href="../../../cctk/sctk/reexports/client/backend/smallvec/alloc/vec/struct.Vec.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::vec::Vec">Vec</a><T>> for <a class="struct" href="../../../cctk/sctk/reexports/client/backend/smallvec/alloc/vec/struct.Vec.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::vec::Vec">Vec</a><U><div class="where">where
|
||||
T: <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>,
|
||||
U: <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a><Array = <T as <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>>::<a class="associatedtype" href="../cast/trait.ArrayCast.html#associatedtype.Array" title="type cosmic::cosmic_theme::palette::cast::ArrayCast::Array">Array</a>> + <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><T>,</div></h3></section><section id="impl-FromColor%3CT%3E-for-U" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#53-55">Source</a><a href="#impl-FromColor%3CT%3E-for-U" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><T> for U<div class="where">where
|
||||
U: <a class="trait" href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped">FromColorUnclamped</a><T> + <a class="trait" href="../trait.Clamp.html" title="trait cosmic::cosmic_theme::palette::Clamp">Clamp</a>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/from_into_color/trait.FromColor.js" data-ignore-extern-crates="alloc" async></script></section></div></main></body></html>
|
||||
93
cosmic/cosmic_theme/palette/convert/trait.FromColorMut.html
Normal file
93
cosmic/cosmic_theme/palette/convert/trait.FromColorMut.html
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Temporarily convert colors in place."><title>FromColorMut in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">From<wbr>Color<wbr>Mut</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#note" title="Note">Note</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.from_color_mut" title="from_color_mut">from_color_mut</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-FromColorMut%3C%5BU%5D%3E-for-%5BT%5D" title="[T]">[T]</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">FromColorMut</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#101">Source</a> </span></div><pre class="rust item-decl"><code>pub trait FromColorMut<T><div class="where">where
|
||||
T: <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><Self> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{
|
||||
// Required method
|
||||
fn <a href="#tymethod.from_color_mut" class="fn">from_color_mut</a>(color: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a>) -> <a class="struct" href="../struct.FromColorMutGuard.html" title="struct cosmic::cosmic_theme::palette::FromColorMutGuard">FromColorMutGuard</a><'_, Self, T>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Temporarily convert colors in place.</p>
|
||||
<p>It allows colors to be converted without using more additional memory than
|
||||
what is necessary for the conversion, itself. The conversion will however
|
||||
have to be reverted at some point, since the memory space is borrowed and
|
||||
has to be restored to its original format. This is enforced by a scope guard
|
||||
that does the opposite conversion when it’s dropped.</p>
|
||||
<p>See also <a href="../trait.IntoColorMut.html" title="trait cosmic::cosmic_theme::palette::IntoColorMut"><code>IntoColorMut</code></a> and <a href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut"><code>FromColorUnclampedMut</code></a>.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{FromColorMut, ShiftHueAssign, Srgb, Hsv};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>rgb = [
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
];
|
||||
|
||||
{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>hsv = <[Hsv]>::from_color_mut(<span class="kw-2">&mut </span>rgb);
|
||||
|
||||
<span class="comment">// All of the colors in `rgb` have been converted to `Hsv`:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
<span class="kw-2">*</span>hsv,
|
||||
[
|
||||
Hsv::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">120.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">240.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);
|
||||
|
||||
hsv.shift_hue_assign(<span class="number">60.0</span>);
|
||||
|
||||
} <span class="comment">// The guard is dropped here and the colors are restored to `Srgb`.
|
||||
|
||||
// Notice how the colors in `rgb` have changed:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
rgb,
|
||||
[
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);</code></pre></div>
|
||||
<p>The scope guard, <a href="../struct.FromColorMutGuard.html" title="struct cosmic::cosmic_theme::palette::FromColorMutGuard"><code>FromColorMutGuard</code></a>, has a few extra methods that can
|
||||
make multiple conversion steps more efficient. One of those is
|
||||
<a href="../struct.FromColorMutGuard.html#method.then_into_color_mut" title="method cosmic::cosmic_theme::palette::FromColorMutGuard::then_into_color_mut"><code>FromColorMutGuard::then_into_color_mut</code></a>, which works like
|
||||
<a href="../trait.IntoColorMut.html#tymethod.into_color_mut" title="method cosmic::cosmic_theme::palette::IntoColorMut::into_color_mut"><code>IntoColorMut::into_color_mut</code></a>, but does not add an extra step when
|
||||
restoring to the original color type. This example will convert <code>Srgb → Hsv → Hsl → Srgb</code> instead of <code>Srgb → Hsv → Hsl → Hsv → Srgb</code>:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{FromColorMut, ShiftHueAssign, LightenAssign, Srgb, Hsv, Hsl};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>rgb = [
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
];
|
||||
|
||||
{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>hsv = <[Hsv]>::from_color_mut(<span class="kw-2">&mut </span>rgb);
|
||||
hsv.shift_hue_assign(<span class="number">60.0</span>);
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>hsl = hsv.then_into_color_mut::<[Hsl]>();
|
||||
hsl.lighten_assign(<span class="number">0.5</span>);
|
||||
|
||||
} <span class="comment">// `then_into_color_mut` makes the guard restore directly to `Srgb` here.
|
||||
|
||||
// Notice how the colors in `rgb` have changed:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
rgb,
|
||||
[
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">1.0</span>, <span class="number">0.5</span>),
|
||||
Srgb::new(<span class="number">0.5</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.5</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);</code></pre></div>
|
||||
<h2 id="note"><a class="doc-anchor" href="#note">§</a>Note</h2>
|
||||
<p>The reused memory space could end up with unexpected values if the
|
||||
conversion panics or if the scope guard’s <code>drop</code> function doesn’t run. The
|
||||
default implementations of <code>FromColorMut</code> uses <a href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast"><code>ArrayCast</code></a>, which is only
|
||||
implemented for color types that can safely accept and recover from any
|
||||
value. Other color types will have to provide their own implementations that
|
||||
can handle this case.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.from_color_mut" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#110">Source</a><h4 class="code-header">fn <a href="#tymethod.from_color_mut" class="fn">from_color_mut</a>(color: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a>) -> <a class="struct" href="../struct.FromColorMutGuard.html" title="struct cosmic::cosmic_theme::palette::FromColorMutGuard">FromColorMutGuard</a><'_, Self, T></h4></section></summary><div class="docblock"><p>Temporarily convert from another color type in place.</p>
|
||||
<p>This reuses the memory space, and the returned scope guard will restore
|
||||
the converted colors to their original type when it’s dropped.</p>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-FromColorMut%3C%5BU%5D%3E-for-%5BT%5D" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#133-136">Source</a><a href="#impl-FromColorMut%3C%5BU%5D%3E-for-%5BT%5D" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[U]</a>> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a><div class="where">where
|
||||
T: <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><U> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
U: <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><T> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a><Array = <T as <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>>::<a class="associatedtype" href="../cast/trait.ArrayCast.html#associatedtype.Array" title="type cosmic::cosmic_theme::palette::cast::ArrayCast::Array">Array</a>> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><section id="method.from_color_mut" class="method trait-impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#139">Source</a><a href="#method.from_color_mut" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_color_mut" class="fn">from_color_mut</a>(colors: &mut <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[U]</a>) -> <a class="struct" href="../struct.FromColorMutGuard.html" title="struct cosmic::cosmic_theme::palette::FromColorMutGuard">FromColorMutGuard</a><'_, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[U]</a>></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-FromColorMut%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#113-116">Source</a><a href="#impl-FromColorMut%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><U> for T<div class="where">where
|
||||
T: <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><U> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
||||
U: <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><T> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a><Array = <T as <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>>::<a class="associatedtype" href="../cast/trait.ArrayCast.html#associatedtype.Array" title="type cosmic::cosmic_theme::palette::cast::ArrayCast::Array">Array</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/from_into_color_mut/trait.FromColorMut.js" data-ignore-extern-crates="std" async></script></section></div></main></body></html>
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,100 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Temporarily convert colors in place, without clamping."><title>FromColorUnclampedMut in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">From<wbr>Color<wbr>Unclamped<wbr>Mut</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#note" title="Note">Note</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.from_color_unclamped_mut" title="from_color_unclamped_mut">from_color_unclamped_mut</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-FromColorUnclampedMut%3C%5BU%5D%3E-for-%5BT%5D" title="[T]">[T]</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">FromColorUnclampedMut</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#102">Source</a> </span></div><pre class="rust item-decl"><code>pub trait FromColorUnclampedMut<T><div class="where">where
|
||||
T: <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><Self> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{
|
||||
// Required method
|
||||
fn <a href="#tymethod.from_color_unclamped_mut" class="fn">from_color_unclamped_mut</a>(
|
||||
color: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a>,
|
||||
) -> <a class="struct" href="struct.FromColorUnclampedMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard">FromColorUnclampedMutGuard</a><'_, Self, T>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Temporarily convert colors in place, without clamping.</p>
|
||||
<p>It allows colors to be converted without using more additional memory than
|
||||
what is necessary for the conversion, itself. The conversion will however
|
||||
have to be reverted at some point, since the memory space is borrowed and
|
||||
has to be restored to its original format. This is enforced by a scope guard
|
||||
that does the opposite conversion when it’s dropped.</p>
|
||||
<p>See also <a href="trait.IntoColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorUnclampedMut"><code>IntoColorUnclampedMut</code></a> and <a href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut"><code>FromColorMut</code></a>.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{convert::FromColorUnclampedMut, ShiftHueAssign, Srgb, Hsv};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>rgb = [
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
];
|
||||
|
||||
{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>hsv = <[Hsv]>::from_color_unclamped_mut(<span class="kw-2">&mut </span>rgb);
|
||||
|
||||
<span class="comment">// All of the colors in `rgb` have been converted to `Hsv`:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
<span class="kw-2">*</span>hsv,
|
||||
[
|
||||
Hsv::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">120.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">240.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);
|
||||
|
||||
hsv.shift_hue_assign(<span class="number">60.0</span>);
|
||||
|
||||
} <span class="comment">// The guard is dropped here and the colors are restored to `Srgb`.
|
||||
|
||||
// Notice how the colors in `rgb` have changed:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
rgb,
|
||||
[
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);</code></pre></div>
|
||||
<p>The scope guard, <a href="struct.FromColorUnclampedMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard"><code>FromColorUnclampedMutGuard</code></a>, has a few extra methods
|
||||
that can make multiple conversion steps more efficient. One of those is
|
||||
<a href="struct.FromColorUnclampedMutGuard.html#method.then_into_color_unclamped_mut" title="method cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard::then_into_color_unclamped_mut"><code>FromColorUnclampedMutGuard::then_into_color_unclamped_mut</code></a>, which works
|
||||
like <a href="trait.IntoColorUnclampedMut.html#tymethod.into_color_unclamped_mut" title="method cosmic::cosmic_theme::palette::convert::IntoColorUnclampedMut::into_color_unclamped_mut"><code>IntoColorUnclampedMut::into_color_unclamped_mut</code></a>, but does not add
|
||||
an extra step when restoring to the original color type. This example will
|
||||
convert <code>Srgb → Hsv → Hsl → Srgb</code> instead of <code>Srgb → Hsv → Hsl → Hsv → Srgb</code>:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{convert::FromColorUnclampedMut, ShiftHueAssign, LightenAssign, Srgb, Hsv, Hsl};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>rgb = [
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
];
|
||||
|
||||
{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>hsv = <[Hsv]>::from_color_unclamped_mut(<span class="kw-2">&mut </span>rgb);
|
||||
hsv.shift_hue_assign(<span class="number">60.0</span>);
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>hsl = hsv.then_into_color_unclamped_mut::<[Hsl]>();
|
||||
hsl.lighten_assign(<span class="number">0.5</span>);
|
||||
|
||||
} <span class="comment">// `then_into_color_unclamped_mut` makes the guard restore directly to `Srgb` here.
|
||||
|
||||
// Notice how the colors in `rgb` have changed:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
rgb,
|
||||
[
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">1.0</span>, <span class="number">0.5</span>),
|
||||
Srgb::new(<span class="number">0.5</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.5</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);</code></pre></div>
|
||||
<h2 id="note"><a class="doc-anchor" href="#note">§</a>Note</h2>
|
||||
<p>The reused memory space could end up with unexpected values if the
|
||||
conversion panics or if the scope guard’s <code>drop</code> function doesn’t run. The
|
||||
default implementations of <code>FromColorUnclampedMut</code> uses <a href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast"><code>ArrayCast</code></a>, which
|
||||
is only implemented for color types that can safely accept and recover from
|
||||
any value. Other color types will have to provide their own implementations
|
||||
that can handle this case.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.from_color_unclamped_mut" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#111">Source</a><h4 class="code-header">fn <a href="#tymethod.from_color_unclamped_mut" class="fn">from_color_unclamped_mut</a>(
|
||||
color: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a>,
|
||||
) -> <a class="struct" href="struct.FromColorUnclampedMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard">FromColorUnclampedMutGuard</a><'_, Self, T></h4></section></summary><div class="docblock"><p>Temporarily convert from another color type in place, without clamping.</p>
|
||||
<p>This reuses the memory space, and the returned scope guard will restore
|
||||
the converted colors to their original type when it’s dropped.</p>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-FromColorUnclampedMut%3C%5BU%5D%3E-for-%5BT%5D" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#134-137">Source</a><a href="#impl-FromColorUnclampedMut%3C%5BU%5D%3E-for-%5BT%5D" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[U]</a>> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a><div class="where">where
|
||||
T: <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><U> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
U: <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><T> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a><Array = <T as <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>>::<a class="associatedtype" href="../cast/trait.ArrayCast.html#associatedtype.Array" title="type cosmic::cosmic_theme::palette::cast::ArrayCast::Array">Array</a>> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><section id="method.from_color_unclamped_mut" class="method trait-impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#140">Source</a><a href="#method.from_color_unclamped_mut" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_color_unclamped_mut" class="fn">from_color_unclamped_mut</a>(
|
||||
colors: &mut <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[U]</a>,
|
||||
) -> <a class="struct" href="struct.FromColorUnclampedMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard">FromColorUnclampedMutGuard</a><'_, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[U]</a>></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-FromColorUnclampedMut%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#114-117">Source</a><a href="#impl-FromColorUnclampedMut%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><U> for T<div class="where">where
|
||||
T: <a class="trait" href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped">FromColorUnclamped</a><U> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,
|
||||
U: <a class="trait" href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped">FromColorUnclamped</a><T> + <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a><Array = <T as <a class="trait" href="../cast/trait.ArrayCast.html" title="trait cosmic::cosmic_theme::palette::cast::ArrayCast">ArrayCast</a>>::<a class="associatedtype" href="../cast/trait.ArrayCast.html#associatedtype.Array" title="type cosmic::cosmic_theme::palette::cast::ArrayCast::Array">Array</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/from_into_color_unclamped_mut/trait.FromColorUnclampedMut.js" data-ignore-extern-crates="std" async></script></section></div></main></body></html>
|
||||
14
cosmic/cosmic_theme/palette/convert/trait.IntoColor.html
Normal file
14
cosmic/cosmic_theme/palette/convert/trait.IntoColor.html
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait for converting a color into another, in a possibly lossy way."><title>IntoColor in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Into<wbr>Color</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.into_color" title="into_color">into_color</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">IntoColor</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#116">Source</a> </span></div><pre class="rust item-decl"><code>pub trait IntoColor<T>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
||||
// Required method
|
||||
fn <a href="#tymethod.into_color" class="fn">into_color</a>(self) -> T;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait for converting a color into another, in a possibly lossy way.</p>
|
||||
<p><code>U: IntoColor<T></code> is implemented for every type <code>T: FromColor<U></code>.</p>
|
||||
<p>See <a href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor"><code>FromColor</code></a> for more details.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.into_color" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#126">Source</a><h4 class="code-header">fn <a href="#tymethod.into_color" class="fn">into_color</a>(self) -> T</h4></section></summary><div class="docblock"><p>Convert into T with values clamped to the color defined bounds</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{IsWithinBounds, IntoColor, Lch, Srgb};
|
||||
|
||||
<span class="kw">let </span>rgb: Srgb = Lch::new(<span class="number">50.0</span>, <span class="number">100.0</span>, -<span class="number">175.0</span>).into_color();
|
||||
<span class="macro">assert!</span>(rgb.is_within_bounds());</code></pre></div>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-IntoColor%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color.rs.html#129-131">Source</a><a href="#impl-IntoColor%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="../trait.IntoColor.html" title="trait cosmic::cosmic_theme::palette::IntoColor">IntoColor</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor">FromColor</a><T>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/from_into_color/trait.IntoColor.js" async></script></section></div></main></body></html>
|
||||
48
cosmic/cosmic_theme/palette/convert/trait.IntoColorMut.html
Normal file
48
cosmic/cosmic_theme/palette/convert/trait.IntoColorMut.html
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Temporarily convert colors in place. The `Into` counterpart to `FromColorMut`."><title>IntoColorMut in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Into<wbr>Color<wbr>Mut</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.into_color_mut" title="into_color_mut">into_color_mut</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">IntoColorMut</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#195">Source</a> </span></div><pre class="rust item-decl"><code>pub trait IntoColorMut<T>: <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><T><div class="where">where
|
||||
T: <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><Self> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{
|
||||
// Required method
|
||||
fn <a href="#tymethod.into_color_mut" class="fn">into_color_mut</a>(&mut self) -> <a class="struct" href="../struct.FromColorMutGuard.html" title="struct cosmic::cosmic_theme::palette::FromColorMutGuard">FromColorMutGuard</a><'_, T, Self>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Temporarily convert colors in place. The <code>Into</code> counterpart to
|
||||
<a href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut"><code>FromColorMut</code></a>.</p>
|
||||
<p>See <a href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut"><code>FromColorMut</code></a> for more details and examples.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{IntoColorMut, ShiftHueAssign, Srgb, Hsv};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>rgb = [
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
];
|
||||
|
||||
{
|
||||
<span class="kw">let </span>hsv: <span class="kw-2">&mut </span>[Hsv] = <span class="kw-2">&mut </span>rgb.into_color_mut(); <span class="comment">// The guard is coerced into a slice.
|
||||
|
||||
// All of the colors in `rgb` have been converted to `Hsv`:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
hsv,
|
||||
[
|
||||
Hsv::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">120.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">240.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);
|
||||
|
||||
hsv.shift_hue_assign(<span class="number">60.0</span>);
|
||||
|
||||
} <span class="comment">// The guard is dropped here and the colors are restored to `Srgb`.
|
||||
|
||||
// Notice how the colors in `rgb` have changed:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
rgb,
|
||||
[
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);</code></pre></div>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.into_color_mut" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#205">Source</a><h4 class="code-header">fn <a href="#tymethod.into_color_mut" class="fn">into_color_mut</a>(&mut self) -> <a class="struct" href="../struct.FromColorMutGuard.html" title="struct cosmic::cosmic_theme::palette::FromColorMutGuard">FromColorMutGuard</a><'_, T, Self></h4></section></summary><div class="docblock"><p>Temporarily convert to another color type in place.</p>
|
||||
<p>This reuses the memory space, and the returned scope guard will restore
|
||||
the converted colors to their original type when it’s dropped.</p>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-IntoColorMut%3CT%3E-for-U" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_mut.rs.html#208-211">Source</a><a href="#impl-IntoColorMut%3CT%3E-for-U" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="../trait.IntoColorMut.html" title="trait cosmic::cosmic_theme::palette::IntoColorMut">IntoColorMut</a><T> for U<div class="where">where
|
||||
T: <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><U> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
U: <a class="trait" href="../trait.FromColorMut.html" title="trait cosmic::cosmic_theme::palette::FromColorMut">FromColorMut</a><T> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/from_into_color_mut/trait.IntoColorMut.js" async></script></section></div></main></body></html>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait for unchecked conversion of a color into another."><title>IntoColorUnclamped in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Into<wbr>Color<wbr>Unclamped</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.into_color_unclamped" title="into_color_unclamped">into_color_unclamped</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">IntoColorUnclamped</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped.rs.html#81">Source</a> </span></div><pre class="rust item-decl"><code>pub trait IntoColorUnclamped<T>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
||||
// Required method
|
||||
fn <a href="#tymethod.into_color_unclamped" class="fn">into_color_unclamped</a>(self) -> T;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait for unchecked conversion of a color into another.</p>
|
||||
<p><code>U: IntoColorUnclamped<T></code> is implemented for every type <code>T: FromColorUnclamped<U></code>.</p>
|
||||
<p>See <a href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped"><code>FromColorUnclamped</code></a> for more details.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.into_color_unclamped" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped.rs.html#92">Source</a><h4 class="code-header">fn <a href="#tymethod.into_color_unclamped" class="fn">into_color_unclamped</a>(self) -> T</h4></section></summary><div class="docblock"><p>Convert into T. The resulting color might be invalid in its color space</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::convert::IntoColorUnclamped;
|
||||
<span class="kw">use </span>palette::{IsWithinBounds, Lch, Srgb};
|
||||
|
||||
<span class="kw">let </span>rgb: Srgb = Lch::new(<span class="number">50.0</span>, <span class="number">100.0</span>, -<span class="number">175.0</span>).into_color_unclamped();
|
||||
<span class="macro">assert!</span>(!rgb.is_within_bounds());</code></pre></div>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-IntoColorUnclamped%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped.rs.html#95-97">Source</a><a href="#impl-IntoColorUnclamped%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="trait.IntoColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorUnclamped">IntoColorUnclamped</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped">FromColorUnclamped</a><T>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/from_into_color_unclamped/trait.IntoColorUnclamped.js" async></script></section></div></main></body></html>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Temporarily convert colors in place. The `Into` counterpart to `FromColorUnclampedMut`."><title>IntoColorUnclampedMut in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Into<wbr>Color<wbr>Unclamped<wbr>Mut</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.into_color_unclamped_mut" title="into_color_unclamped_mut">into_color_unclamped_mut</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">IntoColorUnclampedMut</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#196">Source</a> </span></div><pre class="rust item-decl"><code>pub trait IntoColorUnclampedMut<T>: <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><T><div class="where">where
|
||||
T: <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><Self> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{
|
||||
// Required method
|
||||
fn <a href="#tymethod.into_color_unclamped_mut" class="fn">into_color_unclamped_mut</a>(
|
||||
&mut self,
|
||||
) -> <a class="struct" href="struct.FromColorUnclampedMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard">FromColorUnclampedMutGuard</a><'_, T, Self>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Temporarily convert colors in place. The <code>Into</code> counterpart to
|
||||
<a href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut"><code>FromColorUnclampedMut</code></a>.</p>
|
||||
<p>See <a href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut"><code>FromColorUnclampedMut</code></a> for more details and examples.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{convert::IntoColorUnclampedMut, ShiftHueAssign, Srgb, Hsv};
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>rgb = [
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
];
|
||||
|
||||
{
|
||||
<span class="kw">let </span>hsv: <span class="kw-2">&mut </span>[Hsv] = <span class="kw-2">&mut </span>rgb.into_color_unclamped_mut(); <span class="comment">// The guard is coerced into a slice.
|
||||
|
||||
// All of the colors in `rgb` have been converted to `Hsv`:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
hsv,
|
||||
[
|
||||
Hsv::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">120.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Hsv::new(<span class="number">240.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);
|
||||
|
||||
hsv.shift_hue_assign(<span class="number">60.0</span>);
|
||||
|
||||
} <span class="comment">// The guard is dropped here and the colors are restored to `Srgb`.
|
||||
|
||||
// Notice how the colors in `rgb` have changed:
|
||||
</span><span class="macro">assert_eq!</span>(
|
||||
rgb,
|
||||
[
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>),
|
||||
Srgb::new(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>),
|
||||
Srgb::new(<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>),
|
||||
]
|
||||
);</code></pre></div>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.into_color_unclamped_mut" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#206">Source</a><h4 class="code-header">fn <a href="#tymethod.into_color_unclamped_mut" class="fn">into_color_unclamped_mut</a>(
|
||||
&mut self,
|
||||
) -> <a class="struct" href="struct.FromColorUnclampedMutGuard.html" title="struct cosmic::cosmic_theme::palette::convert::FromColorUnclampedMutGuard">FromColorUnclampedMutGuard</a><'_, T, Self></h4></section></summary><div class="docblock"><p>Temporarily convert to another color type in place, without clamping.</p>
|
||||
<p>This reuses the memory space, and the returned scope guard will restore
|
||||
the converted colors to their original type when it’s dropped.</p>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-IntoColorUnclampedMut%3CT%3E-for-U" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/from_into_color_unclamped_mut.rs.html#209-212">Source</a><a href="#impl-IntoColorUnclampedMut%3CT%3E-for-U" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="trait.IntoColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::IntoColorUnclampedMut">IntoColorUnclampedMut</a><T> for U<div class="where">where
|
||||
T: <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><U> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
U: <a class="trait" href="trait.FromColorUnclampedMut.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclampedMut">FromColorUnclampedMut</a><T> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/from_into_color_unclamped_mut/trait.IntoColorUnclampedMut.js" async></script></section></div></main></body></html>
|
||||
25
cosmic/cosmic_theme/palette/convert/trait.TryFromColor.html
Normal file
25
cosmic/cosmic_theme/palette/convert/trait.TryFromColor.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait for fallible conversion of one color from another."><title>TryFromColor in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">TryFrom<wbr>Color</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.try_from_color" title="try_from_color">try_from_color</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">TryFromColor</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/try_from_into_color.rs.html#50">Source</a> </span></div><pre class="rust item-decl"><code>pub trait TryFromColor<T>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
||||
// Required method
|
||||
fn <a href="#tymethod.try_from_color" class="fn">try_from_color</a>(t: T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self, <a class="struct" href="struct.OutOfBounds.html" title="struct cosmic::cosmic_theme::palette::convert::OutOfBounds">OutOfBounds</a><Self>>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait for fallible conversion of one color from another.</p>
|
||||
<p><code>U: TryFromColor<T></code> is implemented for every type <code>U: FromColorUnclamped<T> + Clamp</code>.</p>
|
||||
<p>See <a href="../trait.FromColor.html" title="trait cosmic::cosmic_theme::palette::FromColor"><code>FromColor</code></a> for a lossy version of this trait.
|
||||
See <a href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped"><code>FromColorUnclamped</code></a> for a lossless version.</p>
|
||||
<p>See the <a href="index.html" title="mod cosmic::cosmic_theme::palette::convert"><code>convert</code></a> module for how to implement <code>FromColorUnclamped</code> for
|
||||
custom colors.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.try_from_color" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/try_from_into_color.rs.html#67">Source</a><h4 class="code-header">fn <a href="#tymethod.try_from_color" class="fn">try_from_color</a>(t: T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self, <a class="struct" href="struct.OutOfBounds.html" title="struct cosmic::cosmic_theme::palette::convert::OutOfBounds">OutOfBounds</a><Self>></h4></section></summary><div class="docblock"><p>Convert from T, returning ok if the color is inside of its defined
|
||||
range, otherwise an <code>OutOfBounds</code> error is returned which contains
|
||||
the unclamped color.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code> <span class="kw">use </span>palette::convert::TryFromColor;
|
||||
<span class="kw">use </span>palette::{Hsl, Srgb};
|
||||
|
||||
<span class="kw">let </span>rgb = <span class="kw">match </span>Srgb::try_from_color(Hsl::new(<span class="number">150.0</span>, <span class="number">1.0</span>, <span class="number">1.1</span>)) {
|
||||
<span class="prelude-val">Ok</span>(color) => color,
|
||||
<span class="prelude-val">Err</span>(err) => {
|
||||
<span class="macro">println!</span>(<span class="string">"Color is out of bounds"</span>);
|
||||
err.color()
|
||||
}
|
||||
};</code></pre></div>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-TryFromColor%3CT%3E-for-U" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/try_from_into_color.rs.html#70-72">Source</a><a href="#impl-TryFromColor%3CT%3E-for-U" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="trait.TryFromColor.html" title="trait cosmic::cosmic_theme::palette::convert::TryFromColor">TryFromColor</a><T> for U<div class="where">where
|
||||
U: <a class="trait" href="trait.FromColorUnclamped.html" title="trait cosmic::cosmic_theme::palette::convert::FromColorUnclamped">FromColorUnclamped</a><T> + <a class="trait" href="../trait.IsWithinBounds.html" title="trait cosmic::cosmic_theme::palette::IsWithinBounds">IsWithinBounds</a><Mask = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/try_from_into_color/trait.TryFromColor.js" async></script></section></div></main></body></html>
|
||||
22
cosmic/cosmic_theme/palette/convert/trait.TryIntoColor.html
Normal file
22
cosmic/cosmic_theme/palette/convert/trait.TryIntoColor.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait for fallible conversion of a color into another."><title>TryIntoColor in cosmic::cosmic_theme::palette::convert - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">TryInto<wbr>Color</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.try_into_color" title="try_into_color">try_into_color</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>convert</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">convert</a></div><h1>Trait <span class="trait">TryIntoColor</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/convert/try_from_into_color.rs.html#90">Source</a> </span></div><pre class="rust item-decl"><code>pub trait TryIntoColor<T>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
||||
// Required method
|
||||
fn <a href="#tymethod.try_into_color" class="fn">try_into_color</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="struct" href="struct.OutOfBounds.html" title="struct cosmic::cosmic_theme::palette::convert::OutOfBounds">OutOfBounds</a><T>>;
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait for fallible conversion of a color into another.</p>
|
||||
<p><code>U: TryIntoColor<T></code> is implemented for every type <code>T: TryFromColor<U></code>.</p>
|
||||
<p>See <a href="trait.TryFromColor.html" title="trait cosmic::cosmic_theme::palette::convert::TryFromColor"><code>TryFromColor</code></a> for more details.</p>
|
||||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.try_into_color" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/try_from_into_color.rs.html#107">Source</a><h4 class="code-header">fn <a href="#tymethod.try_into_color" class="fn">try_into_color</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <a class="struct" href="struct.OutOfBounds.html" title="struct cosmic::cosmic_theme::palette::convert::OutOfBounds">OutOfBounds</a><T>></h4></section></summary><div class="docblock"><p>Convert into T, returning ok if the color is inside of its defined
|
||||
range, otherwise an <code>OutOfBounds</code> error is returned which contains
|
||||
the unclamped color.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code> <span class="kw">use </span>palette::convert::TryIntoColor;
|
||||
<span class="kw">use </span>palette::{Hsl, Srgb};
|
||||
|
||||
<span class="kw">let </span>rgb: Srgb = <span class="kw">match </span>Hsl::new(<span class="number">150.0</span>, <span class="number">1.0</span>, <span class="number">1.1</span>).try_into_color() {
|
||||
<span class="prelude-val">Ok</span>(color) => color,
|
||||
<span class="prelude-val">Err</span>(err) => {
|
||||
<span class="macro">println!</span>(<span class="string">"Color is out of bounds"</span>);
|
||||
err.color()
|
||||
}
|
||||
};</code></pre></div>
|
||||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-TryIntoColor%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/convert/try_from_into_color.rs.html#110-112">Source</a><a href="#impl-TryIntoColor%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="trait.TryIntoColor.html" title="trait cosmic::cosmic_theme::palette::convert::TryIntoColor">TryIntoColor</a><U> for T<div class="where">where
|
||||
U: <a class="trait" href="trait.TryFromColor.html" title="trait cosmic::cosmic_theme::palette::convert::TryFromColor">TryFromColor</a><T>,</div></h3></section></div><script src="../../../../trait.impl/palette/convert/try_from_into_color/trait.TryIntoColor.js" async></script></section></div></main></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue