docs

v0.1.0 문서를 보고 있습니다. 이 버전은 더 이상 지원하지 않습니다. 최신 릴리스: v0.1.3 →

bare::mem

이 페이지의 내용

API 참조는 영어로만 있습니다. 표준 라이브러리 소스의 영어 문서 주석에서 만듭니다.

raw memory operations, Pod and bit casts.

A bit cast goes through a scratch block outside the GC (a generic value has no address of its own): the value is stored there as A and loaded as B, with nothing in between that could collect. reinterpret checks the sizes when called (a where sizeof::<A>() == sizeof::<B>() bound has no compile-time form).

Structs

GcBufSource

pub struct GcBuf<T>

One GC reference to an object holding a run of Ts. Compiler-known: its functions are intrinsics (unchecked indexing) whose bodies never run.

  • pub const unsafe fn new(len: usize) -> GcBuf<T>§

    Source

    buf_new: a zeroed buffer of len elements.

  • pub const unsafe fn get(self, i: usize) -> T§

    Source

    buf_get: element i. UB when i is out of bounds.

  • pub const unsafe fn set(self, i: usize, v: T)§

    Source

    buf_set: store v at i. UB when i is out of bounds.

Trait implementations 2
  • impl<T> Debug for GcBuf<T>
  • impl<T> Clone for GcBuf<T>

MaybeUninitSource

pub struct MaybeUninit<T>

A T that may not be initialized yet: same size and alignment as T, and as_mut_ptr points at the variable itself. Its bits start zeroed (uninit is zeroed: a GC reference in it is null until written, never garbage).

  • pub fn uninit() -> MaybeUninit<T>§

    Source

    A MaybeUninit not written yet; its bits are zero (zeroed).

  • pub fn zeroed() -> MaybeUninit<T>§

    Source

    A MaybeUninit with every byte zero. Panics when out of memory.

  • pub const fn new(value: T) -> MaybeUninit<T>§

    Source

    An initialized value.

  • pub const fn write(ref self, value: T)§

    Source

    Store value, overwriting what was there without dropping it.

  • pub fn as_ptr(self) -> ConstPtr<T>§

    Source

    A pointer to this variable's T (the receiver must be a place).

  • pub fn as_mut_ptr(ref self) -> Ptr<T>§

    Source

    A writable pointer to this variable's T (the receiver must be a place); write through it to initialize.

  • pub const unsafe fn assume_init(self) -> T§

    Source

    The value; UB unless it was initialized (write, new, or through as_mut_ptr).

Trait implementations 1
  • impl<T> Debug for MaybeUninit<T>

Traits

PodSource

pub unsafe trait Pod

Plain old data: every bit pattern of the type is a valid value, its layout is fixed and it has no Drop. User structs opt in with #[derive(Pod)] (#[repr(C)] / #[repr(transparent)]); a hand-written impl is unsafe impl Pod. bool and char are not Pod: most of their bit patterns are not values (read a u8 / u32 and convert).

Functions

size_ofSource

pub fn size_of<T>() -> usize

Size of T in bytes. A value's size at run time is x.size_of_val() (Reflect).

align_ofSource

pub fn align_of<T>() -> usize

Alignment of T in bytes.

buf_newSource

pub unsafe fn buf_new<T>(len: usize) -> GcBuf<T>

A zeroed buffer of len elements; T comes from the slot's type.

buf_getSource

pub unsafe fn buf_get<T>(buf: GcBuf<T>, i: usize) -> T

Element i (no bounds check).

buf_setSource

pub unsafe fn buf_set<T>(buf: GcBuf<T>, i: usize, v: T)

Store element i (no bounds check).

buf_sameSource

pub fn buf_same<T>(a: GcBuf<T>, b: GcBuf<T>) -> bool

Whether a and b are one buffer (identity, not contents). Pins nothing.

reinterpretSource

pub fn reinterpret<A: Pod, B: Pod>(a: A) -> B

The bits of a as a B; both are Pod and the same size (a size mismatch panics).

transmute_uncheckedSource

pub unsafe fn transmute_unchecked<A, B>(a: A) -> B

The bits of a as a B, unchecked: validity, size and the GC references inside are the caller's problem.

readSource

pub unsafe fn read<T>(src: ConstPtr<T>) -> T

The T at src. UB unless it points at a live, initialized T.

writeSource

pub unsafe fn write<T>(dst: Ptr<T>, value: T)

Store value at dst without reading or dropping the old one. UB unless dst is writable T memory.

copySource

pub unsafe fn copy<T>(src: ConstPtr<T>, dst: Ptr<T>, count: usize)

Copy count Ts; the ranges may overlap.

copy_nonoverlappingSource

pub unsafe fn copy_nonoverlapping<T>(src: ConstPtr<T>, dst: Ptr<T>, count: usize)

Copy count Ts between ranges that do not overlap.

write_bytesSource

pub unsafe fn write_bytes<T>(dst: Ptr<T>, value: u8, count: usize)

Set count * size_of::<T>() bytes at dst to value.

swapSource

pub unsafe fn swap<T>(a: Ptr<T>, b: Ptr<T>)

Swap the Ts at a and b; they may be the same place.

replaceSource

pub unsafe fn replace<T>(dst: Ptr<T>, value: T) -> T

Store value at dst and return what was there.

drop_in_placeSource

pub unsafe fn drop_in_place<T>(p: Ptr<T>)

Run the Drop of the T at p (and of its fields'); the memory stays.