chat_1

Crates.iochat_1
lib.rschat_1
version67.0.64
created_at2026-01-05 02:46:32.724346+00
updated_at2026-01-05 02:46:32.724346+00
descriptionHigh-quality integration for https://supermaker.ai/chat/
homepagehttps://supermaker.ai/chat/
repositoryhttps://github.com/qy-upup/chat-1
max_upload_size
id2023001
size11,871
(qy-upup)

documentation

README

chat-1

A lightweight Rust crate for managing and formatting chat messages. This library provides essential tools for building chat applications, focusing on simplicity and efficiency.

Installation

Add the following to your Cargo.toml file under the [dependencies] section: toml chat-1 = "0.1.0" # Replace with the latest version

Usage Examples

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.

}

Feature Summary

  • Message Struct: A simple and well-defined Message struct to represent chat messages, including sender, content, and timestamp.
  • Formatting Functions: Provides functions for formatting messages with customizable timestamps and special handling for system messages.
  • Easy Integration: Designed for seamless integration into existing chat applications.
  • Lightweight: Minimal dependencies for a small footprint and fast performance.
  • Clear and Concise API: Easy to understand and use, promoting rapid development.

License

MIT

This crate is part of the chat-1 ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/chat/

Commit count: 0

cargo fmt