Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Diagnosticism.Rust - CHANGES <!-- omit in toc -->


## 0.4.1 - 7th July 2026

* implement `Len` for `NanosecondsStr`;


## 0.4.0 - 30th June 2026

* added `DoomGram::to_mmm()` and `DoomGram::to_nmmm()` — compact min/mean/max duration summaries using `nanoseconds_to_string()`;
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ name = "diagnosticism"
readme = "README.md"
repository = "https://github.com/synesissoftware/Diagnosticism.Rust"
rust-version = "1.74"
version = "0.4.0"
version = "0.4.1"


# ##########################################################
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ diagnosticism = { version = "0" }

## Components


### Constants

No public constants are defined at this time.
Expand Down Expand Up @@ -320,6 +321,7 @@ Terse `Debug` form of `thing2`: Thing2 { name: "i-am-a-public-thing", internals:

## Project Information


### Where to get help

[GitHub Page](https://github.com/synesissoftware/Diagnosticism.Rust "GitHub Page")
Expand All @@ -332,7 +334,8 @@ Defect reports, feature requests, and pull requests are welcome on https://githu

### Dependencies

**Diagnosticism.Rust** has no (non-development) dependencies.
* [**base-traits**](https://github.com/synesissoftware/base-traits.rs);


#### Dev Dependencies

Expand Down
122 changes: 121 additions & 1 deletion src/diagnostics/time_format/nanoseconds_str.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// src/diagnostics/time_format/nanoseconds_str.rs : `NanosecondsStr`

use base_traits::AsStr;
use base_traits::{
AsStr,
Len,
};

use std::{
borrow::Borrow,
Expand Down Expand Up @@ -160,6 +163,14 @@ impl From<NanosecondsStr> for String {
}
}

impl Len for NanosecondsStr {
fn len(&self) -> usize {
match &self.inner {
NanosecondsStrInner::Heap(s) => s.len(),
NanosecondsStrInner::Inline { len, .. } => *len as usize,
}
}
}

impl PartialEq<NanosecondsStr> for &str {
fn eq(
Expand Down Expand Up @@ -360,6 +371,115 @@ mod tests {
assert!(s.as_str().len() <= INLINE_CAP);
}
}


mod TEST_AsStr {
#![allow(non_snake_case)]

use super::*;

use base_traits::AsStr;


#[allow(unused)]
fn as_AsStr<T : AsStr>(t : &T) -> &impl AsStr {
t
}


#[test]
fn TEST_INLINE_STORAGE() {
let s = nanoseconds_to_string(123_456_789, "");

assert!(!s.is_heap());
assert_eq!("123.4ms", AsStr::as_str(&s));

let as_trait = as_AsStr(&s);

assert_eq!("123.4ms", as_trait.as_str());

let s = &s;

assert_eq!("123.4ms", AsStr::as_str(s));
}

#[test]
fn TEST_INLINE_AT_INLINE_CAP() {
let expected = "a".repeat(INLINE_CAP);
let s = heap_from_bytes(expected.as_bytes());

assert!(!s.is_heap());
assert_eq!(expected.as_str(), AsStr::as_str(&s));
}

#[test]
fn TEST_HEAP_STORAGE() {
let expected = "x".repeat(INLINE_CAP + 4);
let s = heap_from_bytes(expected.as_bytes());

assert!(s.is_heap());
assert_eq!(expected, AsStr::as_str(&s));
}
}


mod TEST_Len {
#![allow(non_snake_case)]

use super::*;

use base_traits::Len;


#[allow(unused)]
fn as_Len<T : Len>(t : &T) -> &impl Len {
t
}


#[test]
fn TEST_INLINE_STORAGE() {
let s = nanoseconds_to_string(123_456_789, "");

assert!(!s.is_heap());
assert_eq!(s.as_str().len(), Len::len(&s));

let as_trait = as_Len(&s);

assert_eq!(s.as_str().len(), as_trait.len());

let s = &s;

assert_eq!(s.as_str().len(), Len::len(s));
}

#[test]
fn TEST_INLINE_AT_INLINE_CAP() {
let expected = "a".repeat(INLINE_CAP);
let s = heap_from_bytes(expected.as_bytes());

assert!(!s.is_heap());
assert_eq!(INLINE_CAP, Len::len(&s));
}

#[test]
fn TEST_HEAP_AT_INLINE_CAP_PLUS_ONE() {
let expected = "b".repeat(INLINE_CAP + 1);
let s = heap_from_bytes(expected.as_bytes());

assert!(s.is_heap());
assert_eq!(INLINE_CAP + 1, Len::len(&s));
}

#[test]
fn TEST_HEAP_STORAGE() {
let expected = "x".repeat(INLINE_CAP + 4);
let s = heap_from_bytes(expected.as_bytes());

assert!(s.is_heap());
assert_eq!(expected.len(), Len::len(&s));
}
}
}


Expand Down
Loading