named_colors
named_colors is a Rust library that provides named colors with their RGB values. The library allows you to retrieve RGB values by color name or use these values in different applications.
Features
- Retrieve RGB values by color name.
- Automatically fetches a JSON file containing color data from a remote URL.
- Supports a wide range of named colors (e.g.,
red,blue,green, etc.).
Installation
You can include named_colors in your project by adding the following line to your Cargo.toml file.
From GitHub
[]
= { = "https://github.com/teamflp/named_colors" }
From Crates.io (Version Specified)
If the library is published on Crates.io, you can specify a version:
[]
= "0.1.0"
Or you can specify a more specific version like this:
[]
= { = "0.1.0" }
Example
Here is an example of how to use the library:
extern crate named_colors;
use get_color_by_name;
This will output:
RGB for navy: (0, 0, 128)
Usage
Retrieving Colors by Name
You can use the get_color_by_name function to retrieve RGB values of a color by its name:
use get_color_by_name;
let rgb = get_color_by_name;
if let Some = rgb else
Available Colors
The library fetches color data from a JSON file hosted at a remote URL. It includes common colors such as:
- Red
- Green
- Blue
- Navy
- Magenta
- And many more...
The full list of colors is provided in the JSON file located here
Handling Errors
If the color name is invalid, the function will return None:
let invalid_color = get_color_by_name;
assert!;
Contributing
Feel free to open issues or submit pull requests if you'd like to contribute to this project.
- Fork the repository.
- Create a new branch for your feature.
- Make your changes and test thoroughly.
- Submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.