Fone Crate

The fone crate is a lightweight utility library for Rust that provides:
- Arithmetic Operations: Simple functions for performing basic math.
- Logging Utilities: Macros for in-memory and file-based logging with support for different severity levels.
Features
-
Arithmetic Utilities:
-
Logging Utilities:
- In-memory logging:
logi!, logd!, logw!, loge!
- File-based logging:
logfi!, logfd!, logfw!, logfe!
Installation
Add the following to your Cargo.toml:
[dependencies]
fone = "a.b.c"
Testing
To run the test suite:
cargo test -v
cargo test -- --show-output
cargo test test_t -v -- --show-output
Usage
use fone::add;
fn main() {
let result = add(2, 2);
println!("Result: {}", result);
}
use fone::{logi, logd, logw, loge};
fn main() {
logi!("Application initialized");
logd!("Configuration loaded");
logw!("Deprecated API used");
loge!("Critical system failure");
}
use fone::{logfi, logfd, logfw, logfe};
fn main() {
logfi!("Application initialized");
logfd!("Configuration loaded");
logfw!("Deprecated API used");
logfe!("Critical system failure");
}
start_format_time(None);
start_format_time(Some(1800)); start_format_time(Some(3600)); start_format_time(Some(3600 * 8)); fn start_format_time(time_zone_offset: Option<i32>) {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards");
let timestamp = now.as_secs();
let nanos = now.subsec_nanos(); let timestamp_with_millis = timestamp * 1_000 + (nanos / 1_000_000) as u64;
let date_time = DateTime::from_timestamp(timestamp_with_millis, time_zone_offset);
let format_date = "%Y-%m-%d"; let format_datetime = "%Y-%m-%d %H:%M"; let format_datetime_seconds = "%Y-%m-%d %H:%M:%S"; let format_datetime_millis = "%Y-%m-%d %H:%M:%S.%f";
println!("==========The Now Time:=========");
let current_time = DateTime::now(None);
println!("Current Time Components:");
current_time.print_components();
let formatted_time = current_time.format("%Y-%m-%d %H:%M:%S.%f");
println!("Formatted Current Time: {}", formatted_time);
println!("==========The Time:=========");
println!("Timestamp:{}, timestamp_with_millis:{}, time_zone_offset:{:?}", timestamp, timestamp_with_millis, time_zone_offset);
println!("Date: {}", date_time.format(format_date));
println!("DateTime: {}", date_time.format(format_datetime));
println!("DateTime with Seconds: {}", date_time.format(format_datetime_seconds));
println!("DateTime with Milliseconds: {}", date_time.format(format_datetime_millis));
println!("Time Zone: {}", date_time.get_time_zone());
println!("Year: {}", date_time.get_year());
println!("Month: {}", date_time.get_month());
println!("Day: {}", date_time.get_day());
println!("Hour: {}", date_time.get_hour());
println!("Minute: {}", date_time.get_minute());
println!("Second: {}", date_time.get_second());
println!("Millisecond: {}", date_time.get_millisecond());
println!("======The Time Zone======");
let timestamp = 1_696_500_000_000; let date_time = DateTime::from_timestamp(timestamp, Some(3600));
let time_zone = date_time.get_time_zone();
println!("Time Zone: {}", time_zone);
let date_time_negative = DateTime::from_timestamp(timestamp, Some(-18000)); let time_zone_negative = date_time_negative.get_time_zone();
println!("Time Zone: {}", time_zone_negative);
}
Documentation
Generate and view the documentation locally:
cargo doc --open
For online documentation, visit docs.rs/fone.
Contributing
Contributions are welcome! Please ensure that:
- New features include appropriate tests.
- Documentation is updated for all public APIs.
- Code adheres to Rust best practices and formatting standards.
License
This project is licensed under the MIT License. See LICENSE for details.