wechat-pub-rs
A simple, high-performance WeChat Official Account Rust SDK for uploading articles and managing drafts.
Features
- Simple API: One function to upload entire articles:
client.upload("./article.md").await?
- Smart Deduplication:
- Images deduplicated by BLAKE3 content hash
- Drafts deduplicated by title (updates existing drafts)
- Robust: Comprehensive error handling and retry mechanisms
- Fast: Async/await with concurrent image uploads
- Type Safe: Compile-time guarantees and runtime reliability
- Theme System: Built-in themes with syntax highlighting support
- Markdown Support: Full markdown parsing with frontmatter
Quick Start
Add this to your Cargo.toml
:
[]
= "0.2"
= { = "1.0", = ["full"] }
Basic Usage
use ;
async
Advanced Usage
use ;
async
Markdown Format
Your markdown files should include frontmatter with metadata:
title: "Your Article Title"
author: "Author Name"
cover: "images/cover.jpg" # Required: Cover image path
theme: "lapis" # Optional: Theme name
code: "github" # Optional: Code highlighting theme
Your markdown content here with images:

```rust
fn main() {
}
Available Themes
Theme | Description |
---|---|
default |
Simple, clean default theme |
lapis |
Blue accents with elegant styling |
maize |
Warm yellow tones |
orangeheart |
Orange accents |
phycat |
Unique phycat styling |
pie |
Sweet pie theme |
purple |
Purple accents |
rainbow |
Colorful rainbow theme |
Code Highlighting Themes
Theme | Description |
---|---|
github |
GitHub style (light) |
github-dark |
GitHub style (dark) |
vscode |
VS Code style |
atom-one-light |
Atom One Light |
atom-one-dark |
Atom One Dark |
solarized-light |
Solarized Light |
solarized-dark |
Solarized Dark |
monokai |
Monokai |
dracula |
Dracula |
xcode |
Xcode |
API Reference
WeChatClient
Main Methods
// Create a new client
pub async pub async pub async
Draft Management
// Get draft information
pub async pub async pub async pub async
Utility Methods
// Upload single image
pub async pub async
UploadOptions
Builder methods:
.title
.author
.cover_image
.show_cover
.comments
.source_url
with_theme
Environment Variables
For running examples, set these environment variables:
Error Handling
The library provides comprehensive error handling:
use ;
match client.upload.await
Performance
- Concurrent Uploads: Images are uploaded concurrently (max 5 concurrent)
- Deduplication: Images are deduplicated using BLAKE3 hash
- Memory Efficient: Streaming file operations
- Async: Non-blocking operations throughout
Requirements
- Rust 1.70+
- WeChat Official Account with API access
- Valid App ID and App Secret
Examples
Check the examples/
directory for more usage examples:
# Run the simple example
WECHAT_APP_ID=your_id WECHAT_APP_SECRET=your_secret
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Testing
# Run unit tests
# Run tests with output
# Run specific test
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Changelog
See CHANGELOG.md for a list of changes and version history.
Note: This SDK focuses specifically on article publishing to WeChat Official Accounts. For other WeChat functionalities (messaging, user management, etc.), consider using a more comprehensive WeChat SDK.