OxL Справочник OxL
РусскийEnglish

method CStr.fromPtr

Copies the NUL-terminated bytes at p into a str ("" for a null pointer). The bytes should be UTF-8.

Example:

oxl✓ проверяется в CI
use std.ffi { CStr, null }

fn main() io {
  let none_here = unsafe { CStr.fromPtr(null<u8>()) }
  let s = "native".toCString()
  print("[{none_here}] {unsafe { CStr.fromPtr(s.asPtr()) }}")
}
Вывод
[] native
pub(api) static unsafe fn fromPtr(p: *u8) -> str

Сложность. O(n) in the length of the C string.

С версии. 1.0.0-beta

Параметры

ИмяТип
p*u8

Возвращает

str

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/ffi/ffi.oxl:138

См. также