Known Types
Well-known types for Rust.
[Features] | [Prerequisites] | [Installation] | [Examples] | [Reference] | [Development]
✨ Features
- Zero default dependencies, only optional integrations.
- Supports opting out of any feature using comprehensive feature flags.
- Adheres to the Rust API Guidelines in its naming conventions.
- Cuts red tape: 100% free and unencumbered public domain software.
🛠️ Prerequisites
- Rust 1.85+ (2024 edition)
⬇️ Installation
Installation via Cargo
Installation via Cargo (all crates)
Installation in Cargo.toml
Enable all default features:
[]
= "0"
Installation in Cargo.toml (with all features enabled, in all crates)
[]
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
= "0"
Enable only specific features:
[]
= { = "0", = false, = ["serde"] }
Installation in Cargo.toml (with only specific features enabled, in all crates)
[]
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
= { = "0", = false, = ["serde"] }
👉 Examples
Importing the Library
use known_types;
Importing the library (all crates)
use known_types;
use known_types_anthropic;
use known_types_github;
use known_types_google;
use known_types_graphql;
use known_types_gravatar;
use known_types_ietf;
use known_types_instagram;
use known_types_linkedin;
use known_types_luma;
use known_types_nostr;
use known_types_openai;
use known_types_pypi;
use known_types_rubygems;
use known_types_w3c;
use known_types_x;
Using handles with SQLx
All handle crates support SQLx 0.9 through optional features:
| Feature | Effect |
|---|---|
sqlx |
Implements sqlx::{Type, Encode, Decode} transparently over String; enables std. |
sqlx-postgres |
Enables sqlx and the PostgreSQL driver, including PostgreSQL array support. |
sqlx-mysql |
Enables sqlx and the MySQL driver. |
sqlx-sqlite |
Enables sqlx and the SQLite driver. |
For example, to use XHandle with PostgreSQL:
[]
= { = "0.1", = ["sqlx-postgres"] }
= { = "0.9", = false, = ["postgres", "runtime-tokio"] }
use XHandle;
async
Handles can be bound by value or reference, decoded from string columns, and
wrapped in Option for nullable columns. PostgreSQL also supports Vec<Handle>
for text arrays. Decoding preserves the stored string without parsing or
normalizing it again.
The same features are available for FacebookHandle, GithubHandle,
GravatarHandle, InstagramHandle, IntrocoHandle, LinkedinHandle,
LocalaiHandle, LumaHandle, TelegramHandle, and WhatsappHandle in their
respective crates. If the application already enables its database driver on
sqlx, enabling just sqlx on a handle crate is sufficient. SQLx support is
disabled by default and also works with default-features = false.
When using SQLx's compile-time query macros, use an explicit column type override
such as SELECT handle AS "handle: XHandle" with query!, or
SELECT handle AS "handle: _" with query_as! and a struct field of type XHandle.
📚 Reference
Crates
| Crate | Version | Docs | Summary |
|---|---|---|---|
| known-types | Well-known types. | ||
| known-types-anthropic | Well-known types for Anthropic APIs. | ||
| known-types-github | Well-known types for GitHub APIs. | ||
| known-types-google | Well-known types for Google APIs. | ||
| known-types-graphql | Well-known types for GraphQL specifications. | ||
| known-types-gravatar | Well-known types for Gravatar APIs. | ||
| known-types-ietf | Well-known types for IETF specifications. | ||
| known-types-instagram | Well-known types for Instagram APIs. | ||
| known-types-linkedin | Well-known types for LinkedIn APIs. | ||
| known-types-luma | Well-known types for Luma APIs. | ||
| known-types-nostr | Well-known types for the Nostr protocol. | ||
| known-types-openai | Well-known types for OpenAI APIs. | ||
| known-types-pypi | Well-known types for Python Package Index (PyPI) APIs. | ||
| known-types-rubygems | Well-known types for RubyGems.org APIs. | ||
| known-types-w3c | Well-known types for W3C specifications. | ||
| known-types-x | Well-known types for X (formerly Twitter) APIs. | ||
Integrations
| Crate (Feature) | Version | Usage | Summary |
|---|---|---|---|
bincode ("bincode") |
2 | Derives bincode::{Encode, Decode} |
|
borsh ("borsh") |
1.5 | Derives borsh::{BorshSerialize, BorshDeserialize} |
|
musli ("musli") |
0.0.131 | Derives musli::{Encode, Decode} |
|
rasn ("rasn") |
0.26 | Derives rasn::AsnType with rasn(automatic_tags) |
|
serde ("serde") |
1 | Derives serde::{Serialize, Deserialize} |
|
SQLx ("sqlx") |
0.9 | Implements sqlx::{Type, Encode, Decode} for handles |
|
See Also
| Package | Crate | Docs |
|---|---|---|
| known-errors | ||
| known-languages | ||
| known-paths | ||
| known-schemes | ||
| known-types |
👨💻 Development