http_kit/
utils.rs

1//! Utility types and functions for HTTP operations.
2//!
3//! This module provides convenient re-exports of commonly used types and utilities
4//! that are helpful when working with HTTP requests, responses, and async operations.
5//! These re-exports save you from having to import these dependencies directly.
6//!
7//! # Exported Types
8//!
9//! - [`Bytes`] - Efficient byte buffer for HTTP body data
10//! - [`ByteStr`] - UTF-8 validated byte string for text content
11//! - All items from `futures_lite` - Async utilities and traits
12//!
13//! # Examples
14//!
15//! ## Working with Bytes
16//!
17//! ```rust
18//! use http_kit::utils::Bytes;
19//!
20//! let data = Bytes::from("Hello, world!");
21//! assert_eq!(data.len(), 13);
22//! ```
23//!
24//! ## Working with ByteStr
25//!
26//! ```rust
27//! use http_kit::utils::ByteStr;
28//!
29//! let text = ByteStr::from_static("Hello, world!");
30//! assert_eq!(text.as_str(), "Hello, world!");
31//! ```
32//!
33//! ## Async Operations
34//!
35//! ```rust
36//! use http_kit::utils::{AsyncReadExt, AsyncWriteExt};
37//!
38//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
39//! // Use async I/O traits for streaming operations
40//! # Ok(())
41//! # }
42//! ```
43
44/// Efficient, reference-counted byte buffer for HTTP body data.
45///
46/// `Bytes` is a cheaply cloneable and sliceable chunk of contiguous memory.
47/// It's ideal for HTTP body content as it allows zero-copy operations when
48/// possible and efficient sharing of data between different parts of your application.
49///
50/// This is a re-export from the `bytes` crate.
51///
52/// # Examples
53///
54/// ```rust
55/// use http_kit::utils::Bytes;
56///
57/// let data = Bytes::from("HTTP body content");
58/// let slice = data.slice(0..4);  // Zero-copy slice
59/// assert_eq!(slice, "HTTP");
60/// ```
61pub use bytes::Bytes;
62
63/// UTF-8 validated byte string optimized for text content.
64///
65/// `ByteStr` provides a string-like interface over byte data while maintaining
66/// the underlying byte representation. It's particularly useful for HTTP text
67/// content where you need both string operations and efficient byte access.
68///
69/// This is a re-export from the `bytestr` crate.
70///
71/// # Examples
72///
73/// ```rust
74/// use http_kit::utils::ByteStr;
75///
76/// let text = ByteStr::from_static("Content-Type: application/json");
77/// assert_eq!(text.len(), 30);
78/// assert!(text.starts_with("Content-Type"));
79/// ```
80pub use bytestr::ByteStr;
81
82/// Complete async runtime utilities and traits.
83///
84/// This re-exports all items from `futures_lite`, providing:
85///
86/// - **Async I/O traits**: `AsyncRead`, `AsyncWrite`, `AsyncBufRead`, etc.
87/// - **Stream utilities**: `Stream`, `StreamExt` for async iteration
88/// - **Future utilities**: `FutureExt`, `future::ready`, `future::pending`
89/// - **Async combinators**: `join!`, `try_join!`, `select!`
90/// - **I/O utilities**: Async file operations, networking, etc.
91///
92/// This saves you from having to import `futures_lite` directly and provides
93/// all the async primitives needed for HTTP operations.
94///
95/// # Examples
96///
97/// ## Stream Processing
98///
99/// ```rust
100/// use http_kit::utils::{stream, StreamExt};
101///
102/// # async fn example() {
103/// let data = vec!["chunk1", "chunk2", "chunk3"];
104/// let mut stream = stream::iter(data);
105///
106/// while let Some(chunk) = stream.next().await {
107///     println!("Processing: {}", chunk);
108/// }
109/// # }
110/// ```
111///
112/// ## Async I/O
113///
114/// ```rust
115/// use http_kit::utils::{AsyncReadExt, AsyncWriteExt};
116///
117/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
118/// // These traits are available for async I/O operations
119/// # Ok(())
120/// # }
121/// ```
122pub use futures_lite::*;