Skip to content

Commit

Permalink
include InStr in docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0x17 committed Aug 16, 2023
1 parent b3a760b commit d34fb0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.docify.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ plus a `u64` (cached hash code), it would be silly to use `Interned<T>` with int
directly, however it makes sense to do so for the purposes of memoizing an expensive
computation via `Memoized<I, T>`.

An interned string type, `InStr`, is also provided as a convenient wrapper around
`Interned<&'static str>`. It has a number of extra impls and should be your go-to type if you
want to work with interned strings.

### Interned Example
<!-- docify::embed!("tests/tests.rs", test_interned_showcase) -->

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ plus a `u64` (cached hash code), it would be silly to use `Interned<T>` with int
directly, however it makes sense to do so for the purposes of memoizing an expensive
computation via `Memoized<I, T>`.

An interned string type, `InStr`, is also provided as a convenient wrapper around
`Interned<&'static str>`. It has a number of extra impls and should be your go-to type if you
want to work with interned strings.

### Interned Example
```rust
#[test]
Expand All @@ -49,6 +53,10 @@ fn test_interned_showcase() {
assert_ne!(d, "fdsa".into());
assert_eq!(Interned::from("asdf"), d);
let e = Interned::from([1, 2, 3, 4, 5].as_slice());
let f = InStr::from("abc");
let g: InStr = "abc".into();
assert_eq!(f, g);
assert_eq!(f.as_ptr(), g.as_ptr());
assert_eq!(e, [1, 2, 3, 4, 5].as_slice().into());
assert_ne!(e, [4, 1, 7].as_slice().into());
assert_eq!(format!("{b:?}"), "Interned<i32> { value: 1289 }");
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
//! integer types directly, however it makes sense to do so for the purposes of memoizing an
//! expensive computation via [`Memoized<I, T>`].
//!
//! An interned string type, [`InStr`], is also provided as a convenient wrapper around
//! [`Interned<&'static str>`]. It has a number of extra impls and should be your go-to type if
//! you want to work with interned strings.
//!
//! ### Interned Example
#![doc = docify::embed_run!("tests/tests.rs", test_interned_showcase)]
//!
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ fn test_interned_showcase() {
assert_ne!(d, "fdsa".into());
assert_eq!(Interned::from("asdf"), d);
let e = Interned::from([1, 2, 3, 4, 5].as_slice());
let f = InStr::from("abc");
let g: InStr = "abc".into();
assert_eq!(f, g);
assert_eq!(f.as_ptr(), g.as_ptr());
assert_eq!(e, [1, 2, 3, 4, 5].as_slice().into());
assert_ne!(e, [4, 1, 7].as_slice().into());
assert_eq!(format!("{b:?}"), "Interned<i32> { value: 1289 }");
Expand Down

0 comments on commit d34fb0a

Please sign in to comment.