Movatterモバイル変換


[0]ホーム

URL:


Pointer

std::fmt

TraitPointer 

1.0.0 ·Source
pub trait Pointer {    // Required method    fnfmt(&self, f: &mutFormatter<'_>) ->Result<(),Error>;}
Expand description

p formatting.

ThePointer trait should format its output as a memory location. This is commonly presentedas hexadecimal. For more information on formatters, seethe module-level documentation.

Printing of pointers is not a reliable way to discover how Rust programs are implemented.The act of reading an address changes the program itself, and may change how the data is representedin memory, and may affect which optimizations are applied to the code.

The printed pointer values are not guaranteed to be stable nor unique identifiers of objects.Rust allows moving values to different memory locations, and may reuse the same memory locationsfor different purposes.

There is no guarantee that the printed value can be converted back to a pointer.

§Examples

Basic usage with&i32:

letx =&42;letaddress =format!("{x:p}");// this produces something like '0x7f06092ac6d0'

ImplementingPointer on a type:

usestd::fmt;structLength(i32);implfmt::PointerforLength {fnfmt(&self, f:&mutfmt::Formatter<'_>) -> fmt::Result {// use `as` to convert to a `*const T`, which implements Pointer, which we can useletptr =selfas*constSelf;        fmt::Pointer::fmt(&ptr, f)    }}letl = Length(42);println!("l is in memory here: {l:p}");letl_ptr =format!("{l:018p}");assert_eq!(l_ptr.len(),18);assert_eq!(&l_ptr[..2],"0x");

Required Methods§

1.0.0 ·Source

fnfmt(&self, f: &mutFormatter<'_>) ->Result<(),Error>

Formats the value using the given formatter.

§Errors

This function should returnErr if, and only if, the providedFormatter returnsErr.String formatting is considered an infallible operation; this function onlyreturns aResult because writing to the underlying stream might fail and it mustprovide a way to propagate the fact that an error has occurred back up the stack.

Implementors§

1.4.0 ·Source§

impl<F>Pointer for F
where F:FnPtr,

1.33.0 ·Source§

impl<Ptr>Pointer forPin<Ptr>
where Ptr:Pointer,

1.0.0 ·Source§

impl<T>Pointer for*const T
where T: ?Sized,

1.0.0 ·Source§

impl<T>Pointer for*mut T
where T: ?Sized,

1.0.0 ·Source§

impl<T>Pointer for&T
where T: ?Sized,

1.0.0 ·Source§

impl<T>Pointer for&mut T
where T: ?Sized,

1.25.0 ·Source§

impl<T>Pointer forNonNull<T>
where T: ?Sized,

1.24.0 ·Source§

impl<T>Pointer forAtomicPtr<T>

Available ontarget_has_atomic_load_store=ptr only.
1.0.0 ·Source§

impl<T, A>Pointer forBox<T, A>
where A:Allocator, T: ?Sized,

1.0.0 ·Source§

impl<T, A>Pointer forRc<T, A>
where A:Allocator, T: ?Sized,

Source§

impl<T, A>Pointer forUniqueRc<T, A>
where A:Allocator, T: ?Sized,

1.0.0 ·Source§

impl<T, A>Pointer forArc<T, A>
where A:Allocator, T: ?Sized,

Source§

impl<T, A>Pointer forUniqueArc<T, A>
where A:Allocator, T: ?Sized,


[8]ページ先頭

©2009-2026 Movatter.jp