| Crates.io | serde-cqcode |
| lib.rs | serde-cqcode |
| version | 0.1.0 |
| created_at | 2025-05-03 15:31:13.096241+00 |
| updated_at | 2025-05-03 15:31:13.096241+00 |
| description | Rust library designed to serialize and deserialize CQ codes. |
| homepage | |
| repository | https://github.com/arkuna23/serde-cqcode |
| max_upload_size | |
| id | 1658896 |
| size | 66,980 |
English | 中文
serde-cqcode is a Rust library designed to serialize and deserialize CQ codes, which are commonly used in messaging applications to represent rich media content like images, emojis, and mentions. This library leverages the serde framework to provide a seamless way to handle CQ codes in Rust applications.
WIP
Add serde-cqcode to your Cargo.toml:
[dependencies]
serde-cqcode = { git = "https://github.com/arkuna23/serde-cqcode.git" }
#...
Here's a basic example of how to use serde-cqcode to serialize and deserialize CQ codes:
use serde_cqcode::{from_str, to_string, CQCode};
fn main() {
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
enum Segment {
Text { text: String },
Face { id: u32 },
Image { file: String },
At { qq: u64 },
Emoji { id: u32 },
}
let input =
"你好[CQ:face,id=1][CQ:image,file=example.jpg][CQ:at,qq=123456][CQ:emoji,id=128512]";
let expected = vec![
Segment::Text {
text: "你好".to_string(),
},
Segment::Face { id: 1 },
Segment::Image {
file: "example.jpg".to_string(),
},
Segment::At { qq: 123456 },
Segment::Emoji { id: 128512 },
];
let deserialized: Vec<Segment> = from_str(input).unwrap();
assert_eq!(deserialized, expected);
let serialized = to_string(&expected).unwrap();
assert_eq!(serialized, input);
}
Contributions are welcome! Please feel free to submit a pull request or open an issue.
This project is intended for learning purposes only. It is not recommended for use in production environments.
This project is licensed under the MIT License.
For any questions or suggestions, please open an issue on the GitHub repository.