MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / capabilities_from_enum

Function capabilities_from_enum

rust/stringzilla.rs:820–833  ·  view source on GitHub ↗

Copies the capabilities C-string into a fixed buffer and returns it. The returned SmallCString is guaranteed to be null-terminated.

(caps: u32)

Source from the content-addressed store, hash-verified

818/// Copies the capabilities C-string into a fixed buffer and returns it.
819/// The returned SmallCString is guaranteed to be null-terminated.
820pub(crate) fn capabilities_from_enum(caps: u32) -> SmallCString {
821 let caps_ptr = unsafe { sz_capabilities_to_string(caps) };
822 // Assume that the external function returns a valid null-terminated C string.
823 let cstr = unsafe { CStr::from_ptr(caps_ptr as *const c_char) };
824 let bytes = cstr.to_bytes();
825
826 let mut buf = SmallCString::new();
827 // Use core::fmt::Write to copy the bytes.
828 // If the string is too long, it will fail. You might want to truncate in a real-world use.
829 // Here, we assume it fits.
830 let s = core::str::from_utf8(bytes).unwrap_or("");
831 let _ = buf.write_str(s);
832 buf
833}
834
835/// Copies the capabilities C-string into a fixed buffer and returns it.
836/// The returned SmallCString is guaranteed to be null-terminated.

Callers 2

capabilitiesFunction · 0.85
capabilitiesFunction · 0.85

Calls 2

write_strMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…