| Crates.io | chat_1 |
| lib.rs | chat_1 |
| version | 67.0.64 |
| created_at | 2026-01-05 02:46:32.724346+00 |
| updated_at | 2026-01-05 02:46:32.724346+00 |
| description | High-quality integration for https://supermaker.ai/chat/ |
| homepage | https://supermaker.ai/chat/ |
| repository | https://github.com/qy-upup/chat-1 |
| max_upload_size | |
| id | 2023001 |
| size | 11,871 |
A lightweight Rust crate for managing and formatting chat messages. This library provides essential tools for building chat applications, focusing on simplicity and efficiency.
Add the following to your Cargo.toml file under the [dependencies] section:
toml
chat-1 = "0.1.0" # Replace with the latest version
Here are a few examples demonstrating how to use chat-1 in different scenarios:
1. Basic Message Formatting: rust use chat_1::{Message, format_message};
fn main() { let message = Message { sender: "Alice".to_string(), content: "Hello, everyone!".to_string(), timestamp: chrono::Utc::now(), };
let formatted_message = format_message(&message);
println!("{}", formatted_message); // Output: Alice (YYYY-MM-DD HH:MM:SS UTC): Hello, everyone!
}
2. Custom Timestamp Formatting: rust use chat_1::{Message, format_message_with_custom_timestamp}; use chrono::Utc; use chrono::format::{self, DelayedFormat, StrftimeItems};
fn main() { let message = Message { sender: "Bob".to_string(), content: "How's it going?".to_string(), timestamp: Utc::now(), };
let format_string = "%Y-%m-%d %H:%M";
let formatted_message = format_message_with_custom_timestamp(&message, format_string);
println!("{}", formatted_message); // Output: Bob (YYYY-MM-DD HH:MM): How's it going?
}
3. Handling System Messages: rust use chat_1::{Message, format_system_message}; use chrono::Utc;
fn main() { let system_message = Message { sender: "System".to_string(), content: "User 'Charlie' has joined the chat.".to_string(), timestamp: Utc::now(), };
let formatted_message = format_system_message(&system_message);
println!("{}", formatted_message); // Output: [System] User 'Charlie' has joined the chat.
}
4. Formatting Messages with Emojis: rust use chat_1::{Message, format_message}; use chrono::Utc;
fn main() { let message = Message { sender: "David".to_string(), content: "I'm so happy! 😄".to_string(), timestamp: Utc::now(), };
let formatted_message = format_message(&message);
println!("{}", formatted_message); // Output: David (YYYY-MM-DD HH:MM:SS UTC): I'm so happy! 😄
}
5. Integrating with a Chat Application: rust use chat_1::{Message, format_message}; use chrono::Utc;
fn main() { // Simulate receiving a message from the network let sender = "Eve".to_string(); let content = "This is a test message from Eve.".to_string(); let timestamp = Utc::now();
let message = Message {
sender,
content,
timestamp,
};
let formatted_message = format_message(&message);
// Display the message in your chat application's UI
println!("{}", formatted_message); // Output: Eve (YYYY-MM-DD HH:MM:SS UTC): This is a test message from Eve.
}
Message struct to represent chat messages, including sender, content, and timestamp.MIT
This crate is part of the chat-1 ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/chat/