display_more/lib.rs
1// Copyright 2021 Datafuse Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Enhanced display formatting for various Rust types.
16//!
17//! This crate provides extension traits to add flexible display formatting capabilities
18//! for common types including `Option<T>`, `Result<T, E>`, slices, and Unix timestamps.
19//!
20//! # Examples
21//!
22//! ## Display Option
23//!
24//! ```rust
25//! use display_more::DisplayOptionExt;
26//!
27//! let some = Some(42);
28//! assert_eq!(some.display().to_string(), "42");
29//!
30//! let none: Option<i32> = None;
31//! assert_eq!(none.display().to_string(), "None");
32//! ```
33//!
34//! ## Display Result
35//!
36//! ```rust
37//! use display_more::DisplayResultExt;
38//!
39//! let ok = Result::<i32, &str>::Ok(42);
40//! assert_eq!(ok.display().to_string(), "Ok(42)");
41//!
42//! let err = Result::<i32, &str>::Err("error");
43//! assert_eq!(err.display().to_string(), "Err(error)");
44//! ```
45//!
46//! ## Display Slice
47//!
48//! ```rust
49//! use display_more::DisplaySliceExt;
50//!
51//! let numbers = vec![1, 2, 3, 4, 5, 6, 7, 8];
52//! assert_eq!(numbers.display().to_string(), "[1,2,3,4,..,8]");
53//! assert_eq!(numbers.display_n(3).to_string(), "[1,2,..,8]");
54//! ```
55//!
56//! ## Display Unix Timestamp
57//!
58//! ```rust
59//! use std::time::Duration;
60//!
61//! use display_more::DisplayUnixTimeStampExt;
62//!
63//! let timestamp = Duration::from_millis(1723102819023);
64//! assert_eq!(
65//! timestamp.display_unix_timestamp().to_string(),
66//! "2024-08-08T07:40:19.023000Z+0000"
67//! );
68//! ```
69
70pub mod display_option;
71mod display_result;
72pub mod display_slice;
73pub mod display_unix_epoch;
74
75pub use display_option::DisplayDebugOptionExt;
76pub use display_option::DisplayOptionExt;
77pub use display_result::DisplayResultExt;
78pub use display_slice::DisplaySliceExt;
79pub use display_unix_epoch::DisplayUnixTimeStampExt;