Crates.io | kaff_sso |
lib.rs | kaff_sso |
version | 0.2.2 |
source | src |
created_at | 2025-05-11 04:30:57.592554+00 |
updated_at | 2025-05-18 05:16:49.423458+00 |
description | Small-buffer-optimized generic buffer and UTF-8 string type. |
homepage | |
repository | https://github.com/Pavez7274/kaff_sso |
max_upload_size | |
id | 1669060 |
size | 19,466 |
kaff_sso
provides a generic fixed-capacity buffer with heap fallback for both small and large collections.
B8
..B256
variants.Boxed
for buffers exceeding 256 elements.as_slice
, as_ptr
or From<String>
with length >=256
PartialEq
, Eq
, PartialOrd
, and Ord
based on buffer length.type UTF8 = Str<u8>
) with:
Deref<Target = str>
and AsRef<str>
From<&str>
and From<String>
feature = "napi"
): FromNapiValue
support for JavaScript strings.Cargo.toml
[dependencies]
kaff_sso = "0.1"
use kaff_sso::Str;
// Inline small buffer
let s: Str<u8> = Str::from(&[1, 2, 3][..]);
assert_eq!(unsafe { s.as_slice() }, &[1, 2, 3]);
// UTF-8 string
use kaff_sso::UTF8;
let s = UTF8::from("hello");
assert_eq!(&*s, "hello");
kaff_sso = { version = "0.1", features = ["napi"] }
#[cfg(feature = "napi")]
use napi::FromNapiValue;
// Now UTF8 implements FromNapiValue
This crate exposes several unsafe
interfaces that require careful usage:
unsafe fn as_slice(&self) -> &[E]
Returns a raw slice constructed from a pointer and length. The caller must ensure:
E
has a valid bit-pattern in the first len()
positions.unsafe fn as_mut_ptr(&mut self) -> *mut E
Provides an unchecked mutable pointer. The caller must ensure:
E
.impl AsRef<str>
and Deref<Target = str>
for UTF8
mem::transmute
to cast a &[u8]
slice to &str
without revalidation. The user must guarantee that the contained bytes are valid UTF-8.From<UTF8> for String
Consumes the buffer via String::from_raw_parts(ptr, len, len)
. Ensure that:
UTF8
instance holds a contiguous heap buffer (i.e. the Boxed
variant).String
expects (pointer, length, capacity).UTF8
again.as_slice
with prior validation via std::str::from_utf8
) whenever possible.unsafe
calls in minimal scopes and document the invariants being upheld.