Skip to content

orzogc/gstr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e1c58e8 Β· Oct 9, 2024

History

16 Commits
Sep 6, 2024
Oct 9, 2024
Sep 9, 2024
Oct 6, 2024
Aug 25, 2024
Aug 25, 2024
Oct 5, 2024

Repository files navigation

gstr

GStr is an immutable string implementation optimized for small strings and comparison.

The size of GStr or Option<GStr> is guaranteed to be 16 bytes on 64-bit platforms or 12 bytes on 32-bit platforms.

The first 4 bytes of the string buffer are inlined in GStr, so comparing two GStrs is faster than comparing two strs in most cases.

The maximum length of GStr is i32::MAX.

Usage

use gstr::GStr;

// This clones the string into the heap memory.
let gstr = GStr::new("Hello, World!");
assert_eq!(gstr, "Hello, World!");

// `GStr` can be constructed from a static string in const context without allocating memory.
let gstr = const { GStr::from_static("Hello, Rust!") };
assert_eq!(gstr, "Hello, Rust!");

// `GStr` can be converted from `String` without allocating memory.
let gstr = GStr::from_string(String::from("Hello, πŸ¦€ and 🌎!"));
assert_eq!(gstr, "Hello, πŸ¦€ and 🌎!");

Features

gstr supports no_std, but needs the alloc crate to work.

gstr has the following features:

  • std: Enable support for some types in std. It's enabled by default.
  • serde: Enable serialization and deserialization support for serde.
  • rkyv: Enable serialization and deserialization support for rkyv.

Warnings

gstr is not tested on big endian platforms, but it maybe works fine on them.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages