Skip to content

Commit 961b58e

Browse files
bors[bot]mb64
andcommittedAug 28, 2018
Merge #110
110: No std support r=Ogeon a=mb64 Adds support for using palette without the standard library, as discussed in issue #108. Fixes #108. One tiny question: because this would be in a future release (not 0.4.0), what version should be in the README example Cargo.toml for `#![no_std]`? I put 0.4, but was unsure about if it should be something different. Co-authored-by: Mark Barbone <mark.l.barbone@gmail.com>
2 parents 941de7a + c729c30 commit 961b58e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+359
-175
lines changed
 

‎README.md

+26-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,27 @@ Add the following lines to your `Cargo.toml` file:
2020
palette = "0.4"
2121
```
2222

23-
### Optional Features
23+
### Features
2424

2525
These features are enabled by default:
2626

2727
* `"named"` - Enables color constants, located in the `named` module.
28-
* `"named_from_str"` - Enables the `named::from_str`, which maps name string to colors.
28+
* `"named_from_str"` - Enables the `named::from_str`, which maps name string to colors. This requires the standard library.
29+
* `"std"` - Enables use of the standard library.
2930

3031
These features are disabled by default:
3132

32-
* `"serde"` - Enables color serializing and deserializing.
33+
* `"serializing"` - Enables color serializing and deserializing using `serde`.
34+
35+
### Without the standard library
36+
37+
Here is an example `Cargo.toml` entry for using palette on `#![no_std]`:
38+
39+
```toml
40+
[dependencies.palette]
41+
version = "0.4"
42+
default-features = false
43+
```
3344

3445
## It's Never "Just RGB"
3546

@@ -113,6 +124,18 @@ This library is only meant for color manipulation and conversion. It's not a ful
113124

114125
[pixel_module]: https://ogeon.github.io/docs/palette/master/palette/pixel/index.html
115126

127+
## Using palette in an embedded environment
128+
129+
Palette supports `#![no_std]` environments by disabling the `"std"` feature. However, there are some things that are unavailable without the standard library:
130+
131+
* Gradients are unavailable, because they depend heavily on Vectors
132+
* The `"named_from_str"` feature requires the standard library as well
133+
* Serialization using `serde` is unavailable
134+
135+
It uses [`libm`] to provide the floating-point operations that are typically in `std`.
136+
137+
[`libm`]: https://github.com/japaric/libm
138+
116139
## Contributing
117140

118141
All sorts of contributions are welcome, no matter how huge or tiny, so take a look at [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines, if you are interested.

‎palette/Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ license = "MIT OR Apache-2.0"
1313
build = "build/main.rs"
1414

1515
[features]
16-
default = ["named_from_str"]
17-
named_from_str = ["named", "phf", "phf_codegen"]
16+
default = ["named_from_str", "std"]
17+
named_from_str = ["named", "phf", "phf_codegen", "std"]
1818
named = []
19+
std = ["approx/std", "num-traits/std"]
20+
serializing = ["serde", "std"]
1921

2022
#internal
2123
strict = []
2224

2325
[dependencies]
2426
palette_derive = {version = "0.4.1", path = "../palette_derive"}
25-
num-traits = "0.2"
26-
approx = "0.2"
27+
num-traits = {version = "0.2", default-features = false}
28+
approx = {version = "0.2", default-features = false}
29+
libm = "0.1.2"
2730

2831
[dependencies.phf]
2932
version = "0.7"
3033
optional = true
3134

3235
[dependencies.serde]
33-
#feature
3436
version = "1"
3537
features = ["serde_derive"]
3638
optional = true

0 commit comments

Comments
 (0)