{"diffoscope-json-version": 1, "source1": "/srv/reproducible-results/rbuild-debian/r-b-build.ZF97ctvn/b1/rustc_1.83.0+dfsg1-1_amd64.changes", "source2": "/srv/reproducible-results/rbuild-debian/r-b-build.ZF97ctvn/b2/rustc_1.83.0+dfsg1-1_amd64.changes", "unified_diff": null, "details": [{"source1": "Files", "source2": "Files", "unified_diff": "@@ -1,20 +1,20 @@\n \n c29c778ed91bd3f4fa632e0e74f0507a 72090168 debug optional cargo-dbgsym_1.83.0+dfsg1-1_amd64.deb\n- 4b6983a1811ce0151ba1aa655dd733b3 4309128 doc optional cargo-doc_1.83.0+dfsg1-1_all.deb\n+ 64b652610b06ccec3a747897f6c1b204 4309348 doc optional cargo-doc_1.83.0+dfsg1-1_all.deb\n f3faa0815b723aacebe9a4300381a43c 6208016 devel optional cargo_1.83.0+dfsg1-1_amd64.deb\n 93ca23253f0e08278b46c4b418461ceb 265907436 debug optional libstd-rust-1.83-dbgsym_1.83.0+dfsg1-1_amd64.deb\n b7d0ae05bc5885d32cc9f22710d9b720 19396008 libs optional libstd-rust-1.83_1.83.0+dfsg1-1_amd64.deb\n 83ec025906fb5073052c1ac8ad2147d5 121124628 libdevel optional libstd-rust-dev-wasm32_1.83.0+dfsg1-1_all.deb\n- c9c272d9c4aea73a9e0f15c0669d8e5e 43617732 libdevel optional libstd-rust-dev-windows_1.83.0+dfsg1-1_amd64.deb\n+ 1540d0250a1bd5eb380e5a94259784fb 43622568 libdevel optional libstd-rust-dev-windows_1.83.0+dfsg1-1_amd64.deb\n 5682dbca6a973c6bef4f9e907d071859 38654988 libdevel optional libstd-rust-dev_1.83.0+dfsg1-1_amd64.deb\n 1c03bfc5ddee21984d2424b4a499a192 237312 devel optional rust-all_1.83.0+dfsg1-1_all.deb\n 3dd7b9f3c5a33809baa28b975715354c 59965336 debug optional rust-clippy-dbgsym_1.83.0+dfsg1-1_amd64.deb\n a3762440ac21cab13df59e4e5ebc9a78 3297264 devel optional rust-clippy_1.83.0+dfsg1-1_amd64.deb\n- dec7be8f582aaf74e5cd59441909aef4 22223036 doc optional rust-doc_1.83.0+dfsg1-1_all.deb\n+ 49a772ebdfa678286ef4fe8409742d42 22073860 doc optional rust-doc_1.83.0+dfsg1-1_all.deb\n 60e3968ef3498034bc3f64056a8a7294 243016 devel optional rust-gdb_1.83.0+dfsg1-1_all.deb\n 11fb39af30be7dbad349585a186313bc 243768 devel optional rust-lldb_1.83.0+dfsg1-1_all.deb\n f3fc176b7109b9a419b055a26c1a9c7f 1712880 devel optional rust-llvm_1.83.0+dfsg1-1_amd64.deb\n ee5a3aed8c19a06659b4af89c954988a 46522292 devel optional rust-src_1.83.0+dfsg1-1_all.deb\n 67f763d52d2585df3af4250d41049c82 36425672 debug optional rustc-dbgsym_1.83.0+dfsg1-1_amd64.deb\n 3dbe75ac6c875230849f6519325b75d0 3767164 devel optional rustc_1.83.0+dfsg1-1_amd64.deb\n 089bb35fc6cb9b9b98c5e64ab1bb7144 24135700 debug optional rustfmt-dbgsym_1.83.0+dfsg1-1_amd64.deb\n"}, {"source1": "cargo-doc_1.83.0+dfsg1-1_all.deb", "source2": "cargo-doc_1.83.0+dfsg1-1_all.deb", "unified_diff": null, "details": [{"source1": "file list", "source2": "file list", "unified_diff": "@@ -1,3 +1,3 @@\n -rw-r--r-- 0 0 0 4 2024-12-04 17:07:54.000000 debian-binary\n--rw-r--r-- 0 0 0 74780 2024-12-04 17:07:54.000000 control.tar.xz\n--rw-r--r-- 0 0 0 4234156 2024-12-04 17:07:54.000000 data.tar.xz\n+-rw-r--r-- 0 0 0 74796 2024-12-04 17:07:54.000000 control.tar.xz\n+-rw-r--r-- 0 0 0 4234360 2024-12-04 17:07:54.000000 data.tar.xz\n"}, {"source1": "control.tar.xz", "source2": "control.tar.xz", "unified_diff": null, "details": [{"source1": "control.tar", "source2": "control.tar", "unified_diff": null, "details": [{"source1": "./md5sums", "source2": "./md5sums", "unified_diff": null, "details": [{"source1": "./md5sums", "source2": "./md5sums", "comments": ["Files differ"], "unified_diff": null}]}]}]}, {"source1": "data.tar.xz", "source2": "data.tar.xz", "unified_diff": null, "details": [{"source1": "data.tar", "source2": "data.tar", "unified_diff": null, "details": [{"source1": "file list", "source2": "file list", "unified_diff": "@@ -2745,15 +2745,15 @@\n -rw-r--r-- 0 root (0) root (0) 35914 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/crates_io/struct.Registry.html\n -rw-r--r-- 0 root (0) root (0) 22990 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/crates_io/struct.TotalCrates.html\n -rw-r--r-- 0 root (0) root (0) 25438 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/crates_io/struct.User.html\n -rw-r--r-- 0 root (0) root (0) 22944 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/crates_io/struct.Users.html\n -rw-r--r-- 0 root (0) root (0) 21933 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/crates_io/struct.Warnings.html\n -rw-r--r-- 0 root (0) root (0) 4964 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/crates_io/type.Result.html\n -rw-r--r-- 0 root (0) root (0) 2991 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/help.html\n--rw-r--r-- 0 root (0) root (0) 3266 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/index.html\n+-rw-r--r-- 0 root (0) root (0) 3273 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/index.html\n drwxr-xr-x 0 root (0) root (0) 0 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/mdman/\n -rw-r--r-- 0 root (0) root (0) 5349 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/mdman/all.html\n -rw-r--r-- 0 root (0) root (0) 28713 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/mdman/enum.Format.html\n -rw-r--r-- 0 root (0) root (0) 4171 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/mdman/fn.convert.html\n -rw-r--r-- 0 root (0) root (0) 3399 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/mdman/fn.extract_section.html\n -rw-r--r-- 0 root (0) root (0) 3207 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/mdman/fn.join_url.html\n -rw-r--r-- 0 root (0) root (0) 4043 2024-12-04 17:07:54.000000 ./usr/share/doc/cargo/reference/mdman/fn.md_parser.html\n"}, {"source1": "./usr/share/doc/cargo/reference/index.html", "source2": "./usr/share/doc/cargo/reference/index.html", "unified_diff": "@@ -1,2 +1,2 @@\n-
pub unsafe fn alloc(layout: Layout) -> *mut u8
Allocates memory with the global allocator.
\n+pub unsafe fn alloc(layout: Layout) -> *mut u8
Allocates memory with the global allocator.
\nThis function forwards calls to the GlobalAlloc::alloc
method\n of the allocator registered with the #[global_allocator]
attribute\n if there is one, or the std
crate\u2019s default.
This function is expected to be deprecated in favor of the alloc
method\n of the Global
type when it and the Allocator
trait become stable.
See GlobalAlloc::alloc
.
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8
Allocates zero-initialized memory with the global allocator.
\n+pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8
Allocates zero-initialized memory with the global allocator.
\nThis function forwards calls to the GlobalAlloc::alloc_zeroed
method\n of the allocator registered with the #[global_allocator]
attribute\n if there is one, or the std
crate\u2019s default.
This function is expected to be deprecated in favor of the alloc_zeroed
method\n of the Global
type when it and the Allocator
trait become stable.
See GlobalAlloc::alloc_zeroed
.
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout)
Deallocates memory with the global allocator.
\n+pub unsafe fn dealloc(ptr: *mut u8, layout: Layout)
Deallocates memory with the global allocator.
\nThis function forwards calls to the GlobalAlloc::dealloc
method\n of the allocator registered with the #[global_allocator]
attribute\n if there is one, or the std
crate\u2019s default.
This function is expected to be deprecated in favor of the dealloc
method\n of the Global
type when it and the Allocator
trait become stable.
See GlobalAlloc::dealloc
.
pub fn handle_alloc_error(layout: Layout) -> !
Signals a memory allocation error.
\n+pub fn handle_alloc_error(layout: Layout) -> !
Signals a memory allocation error.
\nCallers of memory allocation APIs wishing to cease execution\n in response to an allocation error are encouraged to call this function,\n-rather than directly invoking panic!
or similar.
panic!
or similar.\n This function is guaranteed to diverge (not return normally with a value), but depending on\n global configuration, it may either panic (resulting in unwinding or aborting as per\n configuration for all panics), or abort the process (with no unwinding).
\nThe default behavior is:
\nIf the binary links against std
(typically the case), then\n print a message to standard error and abort the process.\n This behavior can be replaced with set_alloc_error_hook
and take_alloc_error_hook
.\n Future versions of Rust may panic by default instead.
If the binary does not link against std
(all of its crates are marked\n-#![no_std]
), then call panic!
with a message.\n+#![no_std]
), then call panic!
with a message.\n The panic handler applies as to any panic.
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
Reallocates memory with the global allocator.
\n+pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
Reallocates memory with the global allocator.
\nThis function forwards calls to the GlobalAlloc::realloc
method\n of the allocator registered with the #[global_allocator]
attribute\n if there is one, or the std
crate\u2019s default.
This function is expected to be deprecated in favor of the realloc
method\n of the Global
type when it and the Allocator
trait become stable.
See GlobalAlloc::realloc
.
pub struct AllocError;
allocator_api
#32838)The AllocError
error indicates an allocation failure\n+
pub struct AllocError;
allocator_api
#32838)The AllocError
error indicates an allocation failure\n that may be due to resource exhaustion or to\n something wrong when combining the given input arguments with this\n allocator.
source
. Read moresource
. Read morepub struct Global;
allocator_api
#32838)The global memory allocator.
\nThis type implements the Allocator
trait by forwarding calls\n to the allocator registered with the #[global_allocator]
attribute\n if there is one, or the std
crate\u2019s default.
Note: while this type is unstable, the functionality it provides can be\n accessed through the free functions in alloc
.
allocator_api
#32838)allocator_api
#32838)allocate
, but also ensures that the returned memory is zero-initialized. Read moreallocator_api
#32838)allocator_api
#32838)allocate
, but also ensures that the returned memory is zero-initialized. Read moreallocator_api
#32838)ptr
. Read moreallocator_api
#32838)allocator_api
#32838)allocator_api
#32838)grow
, but also ensures that the new contents are set to zero before being\n+) -> Result<NonNull<[u8]>, AllocError>allocator_api
#32838)grow
, but also ensures that the new contents are set to zero before being\n returned. Read morepub struct Layout { /* private fields */ }
Layout of a block of memory.
\n+pub struct Layout { /* private fields */ }
Layout of a block of memory.
\nAn instance of Layout
describes a particular layout of memory.\n You build a Layout
up as an input to give to an allocator.
All layouts have an associated size and a power-of-two alignment. The size, when rounded up to\n the nearest multiple of align
, does not overflow isize
(i.e., the rounded value will always be\n less than or equal to isize::MAX
).
(Note that layouts are not required to have non-zero size,\n even though GlobalAlloc
requires that all memory requests\n be non-zero in size. A caller must either ensure that conditions\n like this are met, use specific allocators with looser\n requirements, or use the more lenient Allocator
interface.)
Constructs a Layout
from a given size
and align
,\n+
Constructs a Layout
from a given size
and align
,\n or returns LayoutError
if any of the following conditions\n are not met:
align
must not be zero,
size
, when rounded up to the nearest multiple of align
,\n must not overflow isize
(i.e., the rounded value must be\n less than or equal to isize::MAX
).
Creates a layout, bypassing all checks.
\nThis function is unsafe as it does not verify the preconditions from\n Layout::from_size_align
.
The minimum size in bytes for a memory block of this layout.
\n-The minimum byte alignment for a memory block of this layout.
\n+The minimum size in bytes for a memory block of this layout.
\n+The minimum byte alignment for a memory block of this layout.
\nThe returned alignment is guaranteed to be a power of two.
\n-Constructs a Layout
suitable for holding a value of type T
.
Produces layout describing a record that could be used to\n+
Constructs a Layout
suitable for holding a value of type T
.
Produces layout describing a record that could be used to\n allocate backing structure for T
(which could be a trait\n or other unsized type like a slice).
layout_for_ptr
#69835)Produces layout describing a record that could be used to\n+
layout_for_ptr
#69835)Produces layout describing a record that could be used to\n allocate backing structure for T
(which could be a trait\n or other unsized type like a slice).
This function is only safe to call if the following conditions hold:
\nT
is Sized
, this function is always safe to call.T
is:\n isize
.\n For the special case where the dynamic tail length is 0, this function\n is safe to call.T
acquired by an unsizing coercion,\n and the size of the entire value\n@@ -66,48 +66,48 @@\n call, but may panic or otherwise return the wrong value, as the\n extern type\u2019s layout is not known. This is the same behavior as\n Layout::for_value
on a reference to an extern type tail.alloc_layout_extra
#55724)Creates a NonNull
that is dangling, but well-aligned for this Layout.
alloc_layout_extra
#55724)Creates a NonNull
that is dangling, but well-aligned for this Layout.
Note that the pointer value may potentially represent a valid pointer,\n which means this must not be used as a \u201cnot yet initialized\u201d\n sentinel value. Types that lazily allocate must track initialization by\n some other means.
\n-Creates a layout describing the record that can hold a value\n+
Creates a layout describing the record that can hold a value\n of the same layout as self
, but that also is aligned to\n alignment align
(measured in bytes).
If self
already meets the prescribed alignment, then returns\n self
.
Note that this method does not add any padding to the overall\n size, regardless of whether the returned layout has a different\n alignment. In other words, if K
has size 16, K.align_to(32)
\n will still have size 16.
Returns an error if the combination of self.size()
and the given\n align
violates the conditions listed in Layout::from_size_align
.
alloc_layout_extra
#55724)Returns the amount of padding we must insert after self
\n+
alloc_layout_extra
#55724)Returns the amount of padding we must insert after self
\n to ensure that the following address will satisfy align
\n (measured in bytes).
e.g., if self.size()
is 9, then self.padding_needed_for(4)
\n returns 3, because that is the minimum number of bytes of\n padding required to get a 4-aligned address (assuming that the\n corresponding memory block starts at a 4-aligned address).
The return value of this function has no meaning if align
is\n not a power-of-two.
Note that the utility of the returned value requires align
\n to be less than or equal to the alignment of the starting\n address for the whole allocated block of memory. One way to\n satisfy this constraint is to ensure align <= self.align()
.
Creates a layout by rounding the size of this layout up to a multiple\n+
Creates a layout by rounding the size of this layout up to a multiple\n of the layout\u2019s alignment.
\nThis is equivalent to adding the result of padding_needed_for
\n to the layout\u2019s current size.
alloc_layout_extra
#55724)Creates a layout describing the record for n
instances of\n+
alloc_layout_extra
#55724)Creates a layout describing the record for n
instances of\n self
, with a suitable amount of padding between each to\n ensure that each instance is given its requested size and\n alignment. On success, returns (k, offs)
where k
is the\n layout of the array and offs
is the distance between the start\n of each element in the array.
(That distance between elements is sometimes known as \u201cstride\u201d.)
\nOn arithmetic overflow, returns LayoutError
.
Creates a layout describing the record for self
followed by\n+
Creates a layout describing the record for self
followed by\n next
, including any necessary padding to ensure that next
\n will be properly aligned, but no trailing padding.
In order to match C representation layout repr(C)
, you should\n call pad_to_align
after extending the layout with all fields.\n (There is no way to match the default Rust representation\n layout repr(Rust)
, as it is unspecified.)
Note that the alignment of the resulting layout will be the maximum of\n@@ -149,42 +149,42 @@\n let (new_layout, offset) = layout.extend(field)?;\n layout = new_layout;\n offsets.push(offset);\n }\n // Remember to finalize with `pad_to_align`!\n Ok((layout.pad_to_align(), offsets))\n }
alloc_layout_extra
#55724)Creates a layout describing the record for n
instances of\n+
alloc_layout_extra
#55724)Creates a layout describing the record for n
instances of\n self
, with no padding between each instance.
Note that, unlike repeat
, repeat_packed
does not guarantee\n that the repeated instances of self
will be properly\n aligned, even if a given instance of self
is properly\n aligned. In other words, if the layout returned by\n repeat_packed
is used to allocate an array, it is not\n guaranteed that all elements in the array will be properly\n aligned.
On arithmetic overflow, returns LayoutError
.
alloc_layout_extra
#55724)Creates a layout describing the record for self
followed by\n+
alloc_layout_extra
#55724)Creates a layout describing the record for self
followed by\n next
with no additional padding between the two. Since no\n padding is inserted, the alignment of next
is irrelevant,\n and is not incorporated at all into the resulting layout.
On arithmetic overflow, returns LayoutError
.
#[non_exhaustive]pub struct LayoutError;
The LayoutError
is returned when the parameters given\n+
#[non_exhaustive]pub struct LayoutError;
The LayoutError
is returned when the parameters given\n to Layout::from_size_align
\n or some other Layout
constructor\n do not satisfy its documented constraints.
source
. Read moreAlways evaluates to TryReserveErrorKind::CapacityOverflow
.
self
and other
values to be equal, and is used by ==
.source
. Read moreAlways evaluates to TryReserveErrorKind::CapacityOverflow
.
self
and other
values to be equal, and is used by ==
.pub unsafe trait Allocator {\n+Allocator in alloc::alloc - Rust pub unsafe trait Allocator {\n // Required methods\n- fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>;\n- unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout);\n+ fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>;\n+ unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout);\n \n // Provided methods\n fn allocate_zeroed(\n &self,\n layout: Layout,\n- ) -> Result<NonNull<[u8]>, AllocError> { ... }\n+ ) -> Result<NonNull<[u8]>, AllocError> { ... }\n unsafe fn grow(\n &self,\n- ptr: NonNull<u8>,\n+ ptr: NonNull<u8>,\n old_layout: Layout,\n new_layout: Layout,\n- ) -> Result<NonNull<[u8]>, AllocError> { ... }\n+ ) -> Result<NonNull<[u8]>, AllocError> { ... }\n unsafe fn grow_zeroed(\n &self,\n- ptr: NonNull<u8>,\n+ ptr: NonNull<u8>,\n old_layout: Layout,\n new_layout: Layout,\n- ) -> Result<NonNull<[u8]>, AllocError> { ... }\n+ ) -> Result<NonNull<[u8]>, AllocError> { ... }\n unsafe fn shrink(\n &self,\n- ptr: NonNull<u8>,\n+ ptr: NonNull<u8>,\n old_layout: Layout,\n new_layout: Layout,\n- ) -> Result<NonNull<[u8]>, AllocError> { ... }\n+ ) -> Result<NonNull<[u8]>, AllocError> { ... }\n fn by_ref(&self) -> &Self\n- where Self: Sized { ... }\n+ where Self: Sized { ... }\n }
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)Expand description
An implementation of Allocator
can allocate, grow, shrink, and deallocate arbitrary blocks of\n data described via Layout
.
\n Allocator
is designed to be implemented on ZSTs, references, or smart pointers because having\n an allocator like MyAlloc([u8; N])
cannot be moved, without updating the pointers to the\n allocated memory.
\n Unlike GlobalAlloc
, zero-sized allocations are allowed in Allocator
. If an underlying\n allocator does not support this (like jemalloc) or return a null pointer (such as\n@@ -83,16 +83,16 @@\n allocator. A copied or cloned allocator must behave like the same allocator, and
\n \n \n any pointer to a memory block which is currently allocated may be passed to any other\n method of the allocator.
\n \n \n-Required Methods\u00a7
sourcefn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Attempts to allocate a block of memory.
\n-On success, returns a NonNull<[u8]>
meeting the size and alignment guarantees of layout
.
\n+Required Methods\u00a7
sourcefn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Attempts to allocate a block of memory.
\n+On success, returns a NonNull<[u8]>
meeting the size and alignment guarantees of layout
.
\n The returned block may have a larger size than specified by layout.size()
, and may or may\n not have its contents initialized.
\n The returned block of memory remains valid as long as it is [currently allocated] and the shorter of:
\n \n - the borrow-checker lifetime of the allocator type itself.
\n - as long as at the allocator and all its clones has not been dropped.
\n
\n@@ -100,36 +100,36 @@\n Returning Err
indicates that either memory is exhausted or layout
does not meet\n allocator\u2019s size or alignment constraints.
\n Implementations are encouraged to return Err
on memory exhaustion rather than panicking or\n aborting, but this is not a strict requirement. (Specifically: it is legal to implement\n this trait atop an underlying native allocation library that aborts on memory exhaustion.)
\n Clients wishing to abort computation in response to an allocation error are encouraged to\n call the handle_alloc_error
function, rather than directly invoking panic!
or similar.
\n-sourceunsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Deallocates the memory referenced by ptr
.
\n+sourceunsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Deallocates the memory referenced by ptr
.
\n \u00a7Safety
\n \n ptr
must denote a block of memory currently allocated via this allocator, and \n layout
must fit that block of memory. \n
\n-Provided Methods\u00a7
sourcefn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Behaves like allocate
, but also ensures that the returned memory is zero-initialized.
\n+Provided Methods\u00a7
sourcefn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Behaves like allocate
, but also ensures that the returned memory is zero-initialized.
\n \u00a7Errors
\n Returning Err
indicates that either memory is exhausted or layout
does not meet\n allocator\u2019s size or alignment constraints.
\n Implementations are encouraged to return Err
on memory exhaustion rather than panicking or\n aborting, but this is not a strict requirement. (Specifically: it is legal to implement\n this trait atop an underlying native allocation library that aborts on memory exhaustion.)
\n Clients wishing to abort computation in response to an allocation error are encouraged to\n call the handle_alloc_error
function, rather than directly invoking panic!
or similar.
\n-sourceunsafe fn grow(\n &self,\n- ptr: NonNull<u8>,\n+ ptr: NonNull<u8>,\n old_layout: Layout,\n new_layout: Layout,\n-) -> Result<NonNull<[u8]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Attempts to extend the memory block.
\n-Returns a new NonNull<[u8]>
containing a pointer and the actual size of the allocated\n+) -> Result<NonNull<[u8]>, AllocError>\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Attempts to extend the memory block.
\n+Returns a new NonNull<[u8]>
containing a pointer and the actual size of the allocated\n memory. The pointer is suitable for holding data described by new_layout
. To accomplish\n this, the allocator may extend the allocation referenced by ptr
to fit the new layout.
\n If this returns Ok
, then ownership of the memory block referenced by ptr
has been\n transferred to this allocator. Any access to the old ptr
is Undefined Behavior, even if the\n allocation was grown in-place. The newly returned pointer is the only valid pointer\n for accessing this memory now.
\n If this method returns Err
, then ownership of the memory block has not been transferred to\n@@ -145,20 +145,20 @@\n
Returns Err
if the new layout does not meet the allocator\u2019s size and alignment\n constraints of the allocator, or if growing otherwise fails.
\n Implementations are encouraged to return Err
on memory exhaustion rather than panicking or\n aborting, but this is not a strict requirement. (Specifically: it is legal to implement\n this trait atop an underlying native allocation library that aborts on memory exhaustion.)
\n Clients wishing to abort computation in response to an allocation error are encouraged to\n call the handle_alloc_error
function, rather than directly invoking panic!
or similar.
\n-sourceunsafe fn grow_zeroed(\n+
sourceunsafe fn grow_zeroed(\n &self,\n- ptr: NonNull<u8>,\n+ ptr: NonNull<u8>,\n old_layout: Layout,\n new_layout: Layout,\n-) -> Result<NonNull<[u8]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Behaves like grow
, but also ensures that the new contents are set to zero before being\n+) -> Result<NonNull<[u8]>, AllocError>\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Behaves like grow
, but also ensures that the new contents are set to zero before being\n returned.
\n The memory block will contain the following contents after a successful call to\n grow_zeroed
:
\n \n - Bytes
0..old_layout.size()
are preserved from the original allocation. \n - Bytes
old_layout.size()..old_size
will either be preserved or zeroed, depending on\n the allocator implementation. old_size
refers to the size of the memory block prior\n@@ -178,21 +178,21 @@\n Returns Err
if the new layout does not meet the allocator\u2019s size and alignment\n constraints of the allocator, or if growing otherwise fails.
\n Implementations are encouraged to return Err
on memory exhaustion rather than panicking or\n aborting, but this is not a strict requirement. (Specifically: it is legal to implement\n this trait atop an underlying native allocation library that aborts on memory exhaustion.)
\n Clients wishing to abort computation in response to an allocation error are encouraged to\n call the handle_alloc_error
function, rather than directly invoking panic!
or similar.
\n-
sourceunsafe fn shrink(\n &self,\n- ptr: NonNull<u8>,\n+ ptr: NonNull<u8>,\n old_layout: Layout,\n new_layout: Layout,\n-) -> Result<NonNull<[u8]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Attempts to shrink the memory block.
\n-Returns a new NonNull<[u8]>
containing a pointer and the actual size of the allocated\n+) -> Result<NonNull<[u8]>, AllocError>\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Attempts to shrink the memory block.
\n+Returns a new NonNull<[u8]>
containing a pointer and the actual size of the allocated\n memory. The pointer is suitable for holding data described by new_layout
. To accomplish\n this, the allocator may shrink the allocation referenced by ptr
to fit the new layout.
\n If this returns Ok
, then ownership of the memory block referenced by ptr
has been\n transferred to this allocator. Any access to the old ptr
is Undefined Behavior, even if the\n allocation was shrunk in-place. The newly returned pointer is the only valid pointer\n for accessing this memory now.
\n If this method returns Err
, then ownership of the memory block has not been transferred to\n@@ -208,12 +208,12 @@\n
Returns Err
if the new layout does not meet the allocator\u2019s size and alignment\n constraints of the allocator, or if shrinking otherwise fails.
\n Implementations are encouraged to return Err
on memory exhaustion rather than panicking or\n aborting, but this is not a strict requirement. (Specifically: it is legal to implement\n this trait atop an underlying native allocation library that aborts on memory exhaustion.)
\n Clients wishing to abort computation in response to an allocation error are encouraged to\n call the handle_alloc_error
function, rather than directly invoking panic!
or similar.
\n-Implementors\u00a7
\n+
pub unsafe trait GlobalAlloc {\n+GlobalAlloc in alloc::alloc - Rust pub unsafe trait GlobalAlloc {\n // Required methods\n- unsafe fn alloc(&self, layout: Layout) -> *mut u8;\n- unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);\n+ unsafe fn alloc(&self, layout: Layout) -> *mut u8;\n+ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);\n \n // Provided methods\n- unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ... }\n+ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ... }\n unsafe fn realloc(\n &self,\n- ptr: *mut u8,\n+ ptr: *mut u8,\n layout: Layout,\n- new_size: usize,\n- ) -> *mut u8 { ... }\n+ new_size: usize,\n+ ) -> *mut u8 { ... }\n }
Expand description
A memory allocator that can be registered as the standard library\u2019s default\n through the #[global_allocator]
attribute.
\n Some of the methods require that a memory block be currently\n allocated via an allocator. This means that:
\n \n - \n
the starting address for that memory block was previously\n@@ -119,15 +119,15 @@\n optimization that can be applied. You may generally not rely on heap allocations\n happening if they can be removed without changing program behavior.\n Whether allocations happen or not is not part of the program behavior, even if it\n could be detected via an allocator that tracks allocations by printing or otherwise\n having side effects.
\n \n
\n-Required Methods\u00a7
1.28.0 \u00b7 sourceunsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory as described by the given layout
.
\n+Required Methods\u00a7
1.28.0 \u00b7 sourceunsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory as described by the given layout
.
\n Returns a pointer to newly-allocated memory,\n or null to indicate allocation failure.
\n \u00a7Safety
\n layout
must have non-zero size. Attempting to allocate for a zero-sized layout
may\n result in undefined behavior.
\n (Extension subtraits might provide more specific bounds on\n behavior, e.g., guarantee a sentinel address or a null pointer\n@@ -140,46 +140,46 @@\n exhaustion rather than aborting, but this is not\n a strict requirement. (Specifically: it is legal to\n implement this trait atop an underlying native allocation\n library that aborts on memory exhaustion.)
\n Clients wishing to abort computation in response to an\n allocation error are encouraged to call the handle_alloc_error
function,\n rather than directly invoking panic!
or similar.
\n-1.28.0 \u00b7 sourceunsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
Deallocates the block of memory at the given ptr
pointer with the given layout
.
\n+1.28.0 \u00b7 sourceunsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
Deallocates the block of memory at the given ptr
pointer with the given layout
.
\n \u00a7Safety
\n The caller must ensure:
\n \n - \n
ptr
is a block of memory currently allocated via this allocator and,
\n \n - \n
layout
is the same layout that was used to allocate that block of\n memory.
\n \n
\n Otherwise undefined behavior can result.
\n-Provided Methods\u00a7
1.28.0 \u00b7 sourceunsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
Behaves like alloc
, but also ensures that the contents\n+
Provided Methods\u00a7
1.28.0 \u00b7 sourceunsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
Behaves like alloc
, but also ensures that the contents\n are set to zero before being returned.
\n \u00a7Safety
\n The caller has to ensure that layout
has non-zero size. Like alloc
\n zero sized layout
can result in undefined behaviour.\n However the allocated block of memory is guaranteed to be initialized.
\n \u00a7Errors
\n Returning a null pointer indicates that either memory is exhausted\n or layout
does not meet allocator\u2019s size or alignment constraints,\n just as in alloc
.
\n Clients wishing to abort computation in response to an\n allocation error are encouraged to call the handle_alloc_error
function,\n rather than directly invoking panic!
or similar.
\n-1.28.0 \u00b7 sourceunsafe fn realloc(\n &self,\n- ptr: *mut u8,\n+ ptr: *mut u8,\n layout: Layout,\n- new_size: usize,\n-) -> *mut u8
Shrinks or grows a block of memory to the given new_size
in bytes.\n+ new_size: usize,\n+) -> *mut u8
Shrinks or grows a block of memory to the given new_size
in bytes.\n The block is described by the given ptr
pointer and layout
.
\n If this returns a non-null pointer, then ownership of the memory block\n referenced by ptr
has been transferred to this allocator.\n Any access to the old ptr
is Undefined Behavior, even if the\n allocation remained in-place. The newly returned pointer is the only valid pointer\n for accessing this memory now.
\n The new memory block is allocated with layout
,\n"}, {"source1": "./usr/share/doc/rust-doc/html/alloc/alloc/type.LayoutErr.html", "source2": "./usr/share/doc/rust-doc/html/alloc/alloc/type.LayoutErr.html", "unified_diff": "@@ -1 +1 @@\n-
LayoutErr in alloc::alloc - Rust pub type LayoutErr = LayoutError;
\ud83d\udc4eDeprecated since 1.52.0: Name does not follow std convention, use LayoutErrorAliased Type\u00a7
struct LayoutErr;
\n+LayoutErr in alloc::alloc - Rust pub type LayoutErr = LayoutError;
\ud83d\udc4eDeprecated since 1.52.0: Name does not follow std convention, use LayoutErrorAliased Type\u00a7
struct LayoutErr;
\n"}, {"source1": "./usr/share/doc/rust-doc/html/alloc/borrow/enum.Cow.html", "source2": "./usr/share/doc/rust-doc/html/alloc/borrow/enum.Cow.html", "unified_diff": "@@ -1,10 +1,10 @@\n Cow in alloc::borrow - Rust {\n+ Borrowed(&'a B),\n Owned(<B as ToOwned>::Owned),\n }Expand description
A clone-on-write smart pointer.
\n The type Cow
is a smart pointer providing clone-on-write functionality: it\n can enclose and provide immutable access to borrowed data, and clone the\n data lazily when mutation or ownership is required. The type is designed to\n work with general borrowed data via the Borrow
trait.
\n Cow
implements Deref
, which means that you can call\n@@ -69,27 +69,27 @@\n println!(\"clone_on_write = {:?}\", clone_on_write.values);\n \n // The data was mutated. Let's check it out.\n match clone_on_write {\n Items { values: Cow::Owned(_) } => println!(\"clone_on_write contains owned data\"),\n _ => panic!(\"expect owned data\"),\n }
\n- Variants\u00a7
\u00a71.36.0Borrowed(&'a B)
Borrowed data.
\n+Variants\u00a7
Implementations\u00a7
source\u00a7impl<B: ?Sized + ToOwned> Cow<'_, B>
sourcepub const fn is_borrowed(&self) -> bool
\ud83d\udd2cThis is a nightly-only experimental API. (cow_is_borrowed
#65143)
Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
\n+Implementations\u00a7
source\u00a7impl<B: ?Sized + ToOwned> Cow<'_, B>
sourcepub const fn is_borrowed(&self) -> bool
\ud83d\udd2cThis is a nightly-only experimental API. (cow_is_borrowed
#65143)
Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
\n \u00a7Examples
\n \n-sourcepub const fn is_owned(&self) -> bool
\ud83d\udd2cThis is a nightly-only experimental API. (cow_is_borrowed
#65143)
Returns true if the data is owned, i.e. if to_mut
would be a no-op.
\n+sourcepub const fn is_owned(&self) -> bool
\ud83d\udd2cThis is a nightly-only experimental API. (cow_is_borrowed
#65143)
Returns true if the data is owned, i.e. if to_mut
would be a no-op.
\n \u00a7Examples
\n #![feature(cow_is_borrowed)]\n use std::borrow::Cow;\n \n let cow: Cow<'_, str> = Cow::Owned(\"moo\".to_string());\n assert!(cow.is_owned());\n \n@@ -129,179 +129,179 @@\n let s = \"Hello world!\";\n let cow: Cow<'_, str> = Cow::Owned(String::from(s));\n \n assert_eq!(\n cow.into_owned(),\n String::from(s)\n );
\n-Trait Implementations\u00a7
1.14.0 \u00b7 source\u00a7impl<'a> AddAssign<&'a str> for Cow<'a, str>
source\u00a7fn add_assign(&mut self, rhs: &'a str)
Performs the +=
operation. Read more1.19.0 \u00b7 source\u00a7impl<'a> Extend<Cow<'a, str>> for String
source\u00a7fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read moreTrait Implementations\u00a7
1.14.0 \u00b7 source\u00a7impl<'a> AddAssign<&'a str> for Cow<'a, str>
source\u00a7fn add_assign(&mut self, rhs: &'a str)
Performs the +=
operation. Read more1.19.0 \u00b7 source\u00a7impl<'a> Extend<Cow<'a, str>> for String
source\u00a7fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more1.45.0 \u00b7 source\u00a7impl From<Cow<'_, str>> for Box<str>
source\u00a7fn from(cow: Cow<'_, str>) -> Box<str>
Converts a Cow<'_, str>
into a Box<str>
\n When cow
is the Cow::Borrowed
variant, this\n conversion allocates on the heap and copies the\n underlying str
. Otherwise, it will try to reuse the owned\n String
\u2019s allocation.
\n \u00a7Examples
\n \n \n \n-1.14.0 \u00b7 source\u00a7impl<'a, T> From<Cow<'a, [T]>> for Vec<T>
1.45.0 \u00b7 source\u00a7impl<'a, B> From<Cow<'a, B>> for Arc<B>
1.14.0 \u00b7 source\u00a7impl<'a> From<Cow<'a, str>> for String
1.22.0 \u00b7 source\u00a7impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + 'a>
1.22.0 \u00b7 source\u00a7impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a>
1.0.0 \u00b7 source\u00a7impl<'a> From<String> for Cow<'a, str>
1.0.0 \u00b7 source\u00a7impl<B> Ord for Cow<'_, B>
1.21.0 \u00b7 source\u00a7fn max(self, other: Self) -> Selfwhere\n- Self: Sized,
Compares and returns the maximum of two values. Read more1.0.0 \u00b7 source\u00a7impl<'a, B> PartialOrd for Cow<'a, B>
source\u00a7impl<B: ?Sized + ToOwned> DerefPure for Cow<'_, B>
1.0.0 \u00b7 source\u00a7impl<B> Eq for Cow<'_, B>
Auto Trait Implementations\u00a7
\u00a7impl<'a, B> Freeze for Cow<'a, B>
\u00a7impl<'a, B> RefUnwindSafe for Cow<'a, B>
\u00a7impl<'a, B> Send for Cow<'a, B>
\u00a7impl<'a, B> Sync for Cow<'a, B>
\u00a7impl<'a, B> Unpin for Cow<'a, B>
\u00a7impl<'a, B> UnwindSafe for Cow<'a, B>
Blanket Implementations\u00a7
source\u00a7impl<T> BorrowMut<T> for Twhere\n- T: ?Sized,
source\u00a7fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read moresource\u00a7impl<T> CloneToUninit for Twhere\n- T: Clone,
1.0.0 \u00b7 source\u00a7impl<B> Ord for Cow<'_, B>
1.21.0 \u00b7 source\u00a7fn max(self, other: Self) -> Selfwhere\n+ Self: Sized,
Compares and returns the maximum of two values. Read more1.0.0 \u00b7 source\u00a7impl<'a, B> PartialOrd for Cow<'a, B>
source\u00a7impl<B: ?Sized + ToOwned> DerefPure for Cow<'_, B>
1.0.0 \u00b7 source\u00a7impl<B> Eq for Cow<'_, B>
Auto Trait Implementations\u00a7
\u00a7impl<'a, B> Freeze for Cow<'a, B>
\u00a7impl<'a, B> RefUnwindSafe for Cow<'a, B>
\u00a7impl<'a, B> Send for Cow<'a, B>
\u00a7impl<'a, B> Sync for Cow<'a, B>
\u00a7impl<'a, B> Unpin for Cow<'a, B>
\u00a7impl<'a, B> UnwindSafe for Cow<'a, B>
Blanket Implementations\u00a7
source\u00a7impl<T> BorrowMut<T> for Twhere\n+ T: ?Sized,
source\u00a7fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read moresource\u00a7impl<T> CloneToUninit for Twhere\n+ T: Clone,
\n+ T: Clone,source\u00a7fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read moresource\u00a7fn clone_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. Read more\n"}, {"source1": "./usr/share/doc/rust-doc/html/alloc/borrow/trait.Borrow.html", "source2": "./usr/share/doc/rust-doc/html/alloc/borrow/trait.Borrow.html", "unified_diff": "@@ -1,20 +1,20 @@\n-Borrow in alloc::borrow - Rust pub trait Borrow<Borrowed>where\n- Borrowed: ?Sized,{\n+Borrow in alloc::borrow - Rust pub trait Borrow<Borrowed>where\n+ Borrowed: ?Sized,{\n // Required method\n- fn borrow(&self) -> &Borrowed;\n+ fn borrow(&self) -> &Borrowed;\n }
Expand description
A trait for borrowing data.
\n In Rust, it is common to provide different representations of a type for\n different use cases. For instance, storage location and management for a\n value can be specifically chosen as appropriate for a particular use via\n pointer types such as Box<T>
or Rc<T>
. Beyond these generic\n wrappers that can be used with any type, some types provide optional\n facets providing potentially costly functionality. An example for such a\n type is String
which adds the ability to extend a string to the basic\n-str
. This requires keeping additional information unnecessary for a\n+str
. This requires keeping additional information unnecessary for a\n simple, immutable string.
\n These types provide access to the underlying data through references\n to the type of that data. They are said to be \u2018borrowed as\u2019 that type.\n For instance, a Box<T>
can be borrowed as T
while a String
\n can be borrowed as str
.
\n Types express that they can be borrowed as some type T
by implementing\n Borrow<T>
, providing a reference to a T
in the trait\u2019s\n@@ -28,22 +28,22 @@\n on the identical behavior of these additional trait implementations.\n These traits will likely appear as additional trait bounds.
\n In particular Eq
, Ord
and Hash
must be equivalent for\n borrowed and owned values: x.borrow() == y.borrow()
should give the\n same result as x == y
.
\n If generic code merely needs to work for all types that can\n provide a reference to related type T
, it is often better to use\n-AsRef<T>
as more types can safely implement it.
\n+AsRef<T>
as more types can safely implement it.\n \u00a7Examples
\n As a data collection, HashMap<K, V>
owns both keys and values. If\n the key\u2019s actual data is wrapped in a managing type of some kind, it\n should, however, still be possible to search for a value using a\n reference to the key\u2019s data. For instance, if the key is a string, then\n it is likely stored with the hash map as a String
, while it should\n-be possible to search using a &str
. Thus, insert
needs to\n+be possible to search using a &str
. Thus, insert
needs to\n operate on a String
while get
needs to be able to use a &str
.
\n Slightly simplified, the relevant parts of HashMap<K, V>
look like\n this:
\n \n \n Can CaseInsensitiveString
implement Borrow<str>
? It certainly can\n provide a reference to a string slice via its contained owned string.\n But because its Hash
implementation differs, it behaves differently\n from str
and therefore must not, in fact, implement Borrow<str>
.\n If it wants to allow others access to the underlying str
, it can do\n that via AsRef<str>
which doesn\u2019t carry any extra requirements.
\n-Required Methods\u00a7
Required Methods\u00a7
Implementors\u00a7
1.0.0 \u00b7 source\u00a7impl Borrow<str> for String
1.3.0 \u00b7 source\u00a7impl Borrow<CStr> for CString
1.0.0 \u00b7 source\u00a7impl<'a, B> Borrow<B> for Cow<'a, B>
1.0.0 \u00b7 source\u00a7impl<T> Borrow<T> for &Twhere\n- T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T> Borrow<T> for &mut Twhere\n- T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T> Borrow<T> for Twhere\n- T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T, A: Allocator> Borrow<[T]> for Vec<T, A>
1.4.0 \u00b7 source\u00a7impl<T, const N: usize> Borrow<[T]> for [T; N]
1.1.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> Borrow<T> for Box<T, A>
1.0.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> Borrow<T> for Rc<T, A>
1.0.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> Borrow<T> for Arc<T, A>
\n+
Implementors\u00a7
1.0.0 \u00b7 source\u00a7impl Borrow<str> for String
1.3.0 \u00b7 source\u00a7impl Borrow<CStr> for CString
1.0.0 \u00b7 source\u00a7impl<'a, B> Borrow<B> for Cow<'a, B>
1.0.0 \u00b7 source\u00a7impl<T> Borrow<T> for &Twhere\n+ T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T> Borrow<T> for &mut Twhere\n+ T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T> Borrow<T> for Twhere\n+ T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T, A: Allocator> Borrow<[T]> for Vec<T, A>
1.4.0 \u00b7 source\u00a7impl<T, const N: usize> Borrow<[T]> for [T; N]
1.1.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> Borrow<T> for Box<T, A>
1.0.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> Borrow<T> for Rc<T, A>
1.0.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> Borrow<T> for Arc<T, A>
\n"}, {"source1": "./usr/share/doc/rust-doc/html/alloc/borrow/trait.BorrowMut.html", "source2": "./usr/share/doc/rust-doc/html/alloc/borrow/trait.BorrowMut.html", "unified_diff": "@@ -1,22 +1,22 @@\n-BorrowMut in alloc::borrow - Rust pub trait BorrowMut<Borrowed>: Borrow<Borrowed>where\n- Borrowed: ?Sized,{\n+BorrowMut in alloc::borrow - Rust pub trait BorrowMut<Borrowed>: Borrow<Borrowed>where\n+ Borrowed: ?Sized,{\n // Required method\n- fn borrow_mut(&mut self) -> &mut Borrowed;\n+ fn borrow_mut(&mut self) -> &mut Borrowed;\n }
Expand description
Required Methods\u00a7
1.0.0 \u00b7 sourcefn borrow_mut(&mut self) -> &mut Borrowed
Mutably borrows from an owned value.
\n+Required Methods\u00a7
1.0.0 \u00b7 sourcefn borrow_mut(&mut self) -> &mut Borrowed
Mutably borrows from an owned value.
\n \u00a7Examples
\n \n-Implementors\u00a7
1.36.0 \u00b7 source\u00a7impl BorrowMut<str> for String
1.0.0 \u00b7 source\u00a7impl<T> BorrowMut<T> for &mut Twhere\n- T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T> BorrowMut<T> for Twhere\n- T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T, A: Allocator> BorrowMut<[T]> for Vec<T, A>
1.4.0 \u00b7 source\u00a7impl<T, const N: usize> BorrowMut<[T]> for [T; N]
1.1.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> BorrowMut<T> for Box<T, A>
\n+
Implementors\u00a7
1.36.0 \u00b7 source\u00a7impl BorrowMut<str> for String
1.0.0 \u00b7 source\u00a7impl<T> BorrowMut<T> for &mut Twhere\n+ T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T> BorrowMut<T> for Twhere\n+ T: ?Sized,
1.0.0 \u00b7 source\u00a7impl<T, A: Allocator> BorrowMut<[T]> for Vec<T, A>
1.4.0 \u00b7 source\u00a7impl<T, const N: usize> BorrowMut<[T]> for [T; N]
1.1.0 \u00b7 source\u00a7impl<T: ?Sized, A: Allocator> BorrowMut<T> for Box<T, A>
Uses borrowed data to replace owned data, usually by cloning.
\n-This is borrow-generalized version of Clone::clone_from
.
This is borrow-generalized version of Clone::clone_from
.
Basic usage:
\n \n \n-isize::MAX
bytes.\n Move a value from the stack to the heap by creating a Box
:
Move a value from a Box
back to the stack by dereferencing:
Move a value from a Box
back to the stack by dereferencing:
Creating a recursive data structure:
\n \n#[allow(dead_code)]\n #[derive(Debug)]\n@@ -39,15 +39,15 @@\n pointer points to a valid value of the right type. More precisely, a value: *mut T
that has\n been allocated with the Global
allocator with Layout::for_value(&*value)
may be converted\n into a box using Box::<T>::from_raw(value)
. Conversely, the memory backing a value: *mut T
\n obtained from Box::<T>::into_raw
may be deallocated using the Global
allocator with\n Layout::for_value(&*value)
.\n For zero-sized values, the Box
pointer has to be non-null and sufficiently aligned. The\n recommended way to build a Box to a ZST if Box::new
cannot be used is to use\n-ptr::NonNull::dangling
.
\n+ptr::NonNull::dangling
.\n On top of these basic layout requirements, a Box<T>
must point to a valid value of T
.
\n So long as T: Sized
, a Box<T>
is guaranteed to be represented\n as a single pointer and is also ABI-compatible with C pointers\n (i.e. the C type T*
). This means that if you have extern \u201cC\u201d\n Rust functions that will be called from C, you can define those\n Rust functions using Box<T>
types, and use T*
as corresponding\n type on the C side. As an example, consider this C header which\n@@ -96,15 +96,15 @@\n
The aliasing rules for Box<T>
are the same as for &mut T
. Box<T>
\n asserts uniqueness over its content. Using raw pointers derived from a box\n after that box has been mutated through, moved or borrowed as &mut T
\n is not allowed. For more guidance on working with box from unsafe code, see\n rust-lang/unsafe-code-guidelines#326.
\n \u00a7Editions
\n A special case exists for the implementation of IntoIterator
for arrays on the Rust 2021\n-edition, as documented here. Unfortunately, it was later found that a similar\n+edition, as documented here. Unfortunately, it was later found that a similar\n workaround should be added for boxed slices, and this was applied in the 2024 edition.
\n Specifically, IntoIterator
is implemented for Box<[T]>
on all editions, but specific calls\n to into_iter()
for boxed slices will defer to the slice implementation on editions before\n 2024:
\n \n \u24d8// Rust 2015, 2018, and 2021:\n \n"}, {"source1": "./usr/share/doc/rust-doc/html/alloc/boxed/struct.Box.html", "source2": "./usr/share/doc/rust-doc/html/alloc/boxed/struct.Box.html", "unified_diff": "@@ -1,67 +1,67 @@\n-Box in alloc::boxed - Rust pub struct Box<T: ?Sized, A: Allocator = Global>(/* private fields */);
Expand description
A pointer type that uniquely owns a heap allocation of type T
.
\n+Box in alloc::boxed - Rust pub struct Box<T: ?Sized, A: Allocator = Global>(/* private fields */);
Expand description
A pointer type that uniquely owns a heap allocation of type T
.
\n See the module-level documentation for more.
\n Implementations\u00a7
source\u00a7impl<T> Box<T>
1.0.0 \u00b7 sourcepub fn new(x: T) -> Self
Allocates memory on the heap and then places x
into it.
\n This doesn\u2019t actually allocate if T
is zero-sized.
\n \u00a7Examples
\n \n-1.82.0 \u00b7 sourcepub fn new_uninit() -> Box<MaybeUninit<T>>
Constructs a new box with uninitialized contents.
\n+1.82.0 \u00b7 sourcepub fn new_uninit() -> Box<MaybeUninit<T>>
Constructs a new box with uninitialized contents.
\n \u00a7Examples
\n \n-sourcepub fn new_zeroed() -> Box<MaybeUninit<T>>
\ud83d\udd2cThis is a nightly-only experimental API. (new_zeroed_alloc
#129396)
Constructs a new Box
with uninitialized contents, with the memory\n+
sourcepub fn new_zeroed() -> Box<MaybeUninit<T>>
\ud83d\udd2cThis is a nightly-only experimental API. (new_zeroed_alloc
#129396)
Constructs a new Box
with uninitialized contents, with the memory\n being filled with 0
bytes.
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n \n-1.33.0 \u00b7 sourcepub fn pin(x: T) -> Pin<Box<T>>
Constructs a new Pin<Box<T>>
. If T
does not implement Unpin
, then\n+
1.33.0 \u00b7 sourcepub fn pin(x: T) -> Pin<Box<T>>
Constructs a new Pin<Box<T>>
. If T
does not implement Unpin
, then\n x
will be pinned in memory and unable to be moved.
\n Constructing and pinning of the Box
can also be done in two steps: Box::pin(x)
\n does the same as Box::into_pin(Box::new(x))
. Consider using\n into_pin
if you already have a Box<T>
, or if you want to\n construct a (pinned) Box
in a different way than with Box::new
.
\n-sourcepub fn try_new(x: T) -> Result<Self, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Allocates memory on the heap then places x
into it,\n+
sourcepub fn try_new(x: T) -> Result<Self, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Allocates memory on the heap then places x
into it,\n returning an error if the allocation fails
\n This doesn\u2019t actually allocate if T
is zero-sized.
\n \u00a7Examples
\n \n-sourcepub fn try_new_uninit() -> Result<Box<MaybeUninit<T>>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new box with uninitialized contents on the heap,\n+
sourcepub fn try_new_uninit() -> Result<Box<MaybeUninit<T>>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new box with uninitialized contents on the heap,\n returning an error if the allocation fails
\n \u00a7Examples
\n \n-sourcepub fn try_new_zeroed() -> Result<Box<MaybeUninit<T>>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new Box
with uninitialized contents, with the memory\n+
sourcepub fn try_new_zeroed() -> Result<Box<MaybeUninit<T>>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new Box
with uninitialized contents, with the memory\n being filled with 0
bytes on the heap
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n #![feature(allocator_api)]\n \n let zero = Box::<u32>::try_new_zeroed()?;\n let zero = unsafe { zero.assume_init() };\n \n@@ -71,25 +71,25 @@\n This doesn\u2019t actually allocate if T
is zero-sized.
\n \u00a7Examples
\n \n-
sourcepub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>where\n+
sourcepub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>where\n A: Allocator,
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Allocates memory in the given allocator then places x
into it,\n returning an error if the allocation fails
\n This doesn\u2019t actually allocate if T
is zero-sized.
\n \u00a7Examples
\n \n-sourcepub fn new_uninit_in(alloc: A) -> Box<MaybeUninit<T>, A>where\n+
sourcepub fn new_uninit_in(alloc: A) -> Box<MaybeUninit<T>, A>where\n A: Allocator,
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new box with uninitialized contents in the provided allocator.
\n \u00a7Examples
\n \n-sourcepub fn try_new_uninit_in(alloc: A) -> Result<Box<MaybeUninit<T>, A>, AllocError>where\n+
sourcepub fn try_new_uninit_in(alloc: A) -> Result<Box<MaybeUninit<T>, A>, AllocError>where\n A: Allocator,
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new box with uninitialized contents in the provided allocator,\n returning an error if the allocation fails
\n \u00a7Examples
\n \n-sourcepub fn new_zeroed_in(alloc: A) -> Box<MaybeUninit<T>, A>where\n+
sourcepub fn new_zeroed_in(alloc: A) -> Box<MaybeUninit<T>, A>where\n A: Allocator,
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new Box
with uninitialized contents, with the memory\n being filled with 0
bytes in the provided allocator.
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n \n-sourcepub fn try_new_zeroed_in(alloc: A) -> Result<Box<MaybeUninit<T>, A>, AllocError>where\n+
sourcepub fn try_new_zeroed_in(alloc: A) -> Result<Box<MaybeUninit<T>, A>, AllocError>where\n A: Allocator,
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new Box
with uninitialized contents, with the memory\n being filled with 0
bytes in the provided allocator,\n returning an error if the allocation fails,
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n \n-sourcepub fn pin_in(x: T, alloc: A) -> Pin<Self>where\n- A: 'static + Allocator,
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new Pin<Box<T, A>>
. If T
does not implement Unpin
, then\n+
sourcepub fn pin_in(x: T, alloc: A) -> Pin<Self>where\n+ A: 'static + Allocator,
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new Pin<Box<T, A>>
. If T
does not implement Unpin
, then\n x
will be pinned in memory and unable to be moved.
\n Constructing and pinning of the Box
can also be done in two steps: Box::pin_in(x, alloc)
\n does the same as Box::into_pin(Box::new_in(x, alloc))
. Consider using\n into_pin
if you already have a Box<T, A>
, or if you want to\n construct a (pinned) Box
in a different way than with Box::new_in
.
\n-sourcepub fn into_boxed_slice(boxed: Self) -> Box<[T], A>
\ud83d\udd2cThis is a nightly-only experimental API. (box_into_boxed_slice
#71582)
Converts a Box<T>
into a Box<[T]>
\n+sourcepub fn into_boxed_slice(boxed: Self) -> Box<[T], A>
\ud83d\udd2cThis is a nightly-only experimental API. (box_into_boxed_slice
#71582)
Converts a Box<T>
into a Box<[T]>
\n This conversion does not allocate on the heap and happens in place.
\n sourcepub fn into_inner(boxed: Self) -> T
\ud83d\udd2cThis is a nightly-only experimental API. (box_into_inner
#80437)
Consumes the Box
, returning the wrapped value.
\n \u00a7Examples
\n \n-source\u00a7impl<T> Box<[T]>
1.82.0 \u00b7 sourcepub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>]>
Constructs a new boxed slice with uninitialized contents.
\n+source\u00a7impl<T> Box<[T]>
1.82.0 \u00b7 sourcepub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>]>
Constructs a new boxed slice with uninitialized contents.
\n \u00a7Examples
\n \n-sourcepub fn new_zeroed_slice(len: usize) -> Box<[MaybeUninit<T>]>
\ud83d\udd2cThis is a nightly-only experimental API. (new_zeroed_alloc
#129396)
Constructs a new boxed slice with uninitialized contents, with the memory\n+
sourcepub fn new_zeroed_slice(len: usize) -> Box<[MaybeUninit<T>]>
\ud83d\udd2cThis is a nightly-only experimental API. (new_zeroed_alloc
#129396)
Constructs a new boxed slice with uninitialized contents, with the memory\n being filled with 0
bytes.
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n \n sourcepub fn try_new_uninit_slice(\n- len: usize,\n-) -> Result<Box<[MaybeUninit<T>]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents. Returns an error if\n+ len: usize,\n+) -> Result<Box<[MaybeUninit<T>]>, AllocError>\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents. Returns an error if\n the allocation fails.
\n \u00a7Examples
\n #![feature(allocator_api)]\n \n let mut values = Box::<[u32]>::try_new_uninit_slice(3)?;\n let values = unsafe {\n // Deferred initialization:\n@@ -204,27 +204,27 @@\n values[1].as_mut_ptr().write(2);\n values[2].as_mut_ptr().write(3);\n values.assume_init()\n };\n \n assert_eq!(*values, [1, 2, 3]);
\n sourcepub fn try_new_zeroed_slice(\n- len: usize,\n-) -> Result<Box<[MaybeUninit<T>]>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents, with the memory\n+ len: usize,\n+) -> Result<Box<[MaybeUninit<T>]>, AllocError>\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents, with the memory\n being filled with 0
bytes. Returns an error if the allocation fails.
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n \n-source\u00a7impl<T, A: Allocator> Box<[T], A>
sourcepub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[MaybeUninit<T>], A>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator.
\n+source\u00a7impl<T, A: Allocator> Box<[T], A>
sourcepub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[MaybeUninit<T>], A>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator.
\n \u00a7Examples
\n \n-sourcepub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[MaybeUninit<T>], A>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator,\n+
sourcepub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[MaybeUninit<T>], A>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator,\n with the memory being filled with 0
bytes.
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n \n sourcepub fn try_new_uninit_slice_in(\n- len: usize,\n+ len: usize,\n alloc: A,\n-) -> Result<Box<[MaybeUninit<T>], A>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator. Returns an error if\n+) -> Result<Box<[MaybeUninit<T>], A>, AllocError>\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator. Returns an error if\n the allocation fails.
\n \u00a7Examples
\n \n sourcepub fn try_new_zeroed_slice_in(\n- len: usize,\n+ len: usize,\n alloc: A,\n-) -> Result<Box<[MaybeUninit<T>], A>, AllocError>
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator, with the memory\n+) -> Result<Box<[MaybeUninit<T>], A>, AllocError>\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a new boxed slice with uninitialized contents in the provided allocator, with the memory\n being filled with 0
bytes. Returns an error if the allocation fails.
\n-See MaybeUninit::zeroed
for examples of correct and incorrect usage\n+
See MaybeUninit::zeroed
for examples of correct and incorrect usage\n of this method.
\n \u00a7Examples
\n \n-source\u00a7impl<T, A: Allocator> Box<MaybeUninit<T>, A>
1.82.0 \u00b7 sourcepub unsafe fn assume_init(self) -> Box<T, A>
Converts to Box<T, A>
.
\n+source\u00a7impl<T, A: Allocator> Box<MaybeUninit<T>, A>
1.82.0 \u00b7 sourcepub unsafe fn assume_init(self) -> Box<T, A>
Converts to Box<T, A>
.
\n \u00a7Safety
\n-As with MaybeUninit::assume_init
,\n+
As with MaybeUninit::assume_init
,\n it is up to the caller to guarantee that the value\n really is in an initialized state.\n Calling this when the content is not yet fully initialized\n causes immediate undefined behavior.
\n \u00a7Examples
\n \n-source\u00a7impl<T, A: Allocator> Box<[MaybeUninit<T>], A>
1.82.0 \u00b7 sourcepub unsafe fn assume_init(self) -> Box<[T], A>
Converts to Box<[T], A>
.
\n+source\u00a7impl<T, A: Allocator> Box<[MaybeUninit<T>], A>
1.82.0 \u00b7 sourcepub unsafe fn assume_init(self) -> Box<[T], A>
Converts to Box<[T], A>
.
\n \u00a7Safety
\n-As with MaybeUninit::assume_init
,\n+
As with MaybeUninit::assume_init
,\n it is up to the caller to guarantee that the values\n really are in an initialized state.\n Calling this when the content is not yet fully initialized\n causes immediate undefined behavior.
\n \u00a7Examples
\n \n-source\u00a7impl<T: ?Sized> Box<T>
1.4.0 \u00b7 sourcepub unsafe fn from_raw(raw: *mut T) -> Self
Constructs a box from a raw pointer.
\n After calling this function, the raw pointer is owned by the\n resulting Box
. Specifically, the Box
destructor will call\n the destructor of T
and free the allocated memory. For this\n to be safe, the memory must have been allocated in accordance\n with the memory layout used by Box
.
\n \u00a7Safety
\n This function is unsafe because improper use may lead to\n@@ -373,15 +373,15 @@\n let ptr = alloc(Layout::new::<i32>()) as *mut i32;\n // In general .write is required to avoid attempting to destruct\n // the (uninitialized) previous contents of `ptr`, though for this\n // simple example `*ptr = 5` would have worked as well.\n ptr.write(5);\n let x = Box::from_raw(ptr);\n }
\n-sourcepub unsafe fn from_non_null(ptr: NonNull<T>) -> Self
\ud83d\udd2cThis is a nightly-only experimental API. (box_vec_non_null
#130364)
Constructs a box from a NonNull
pointer.
\n+sourcepub unsafe fn from_non_null(ptr: NonNull<T>) -> Self
\ud83d\udd2cThis is a nightly-only experimental API. (box_vec_non_null
#130364)
Constructs a box from a NonNull
pointer.
\n After calling this function, the NonNull
pointer is owned by\n the resulting Box
. Specifically, the Box
destructor will call\n the destructor of T
and free the allocated memory. For this\n to be safe, the memory must have been allocated in accordance\n with the memory layout used by Box
.
\n \u00a7Safety
\n This function is unsafe because improper use may lead to\n@@ -408,15 +408,15 @@\n let non_null = NonNull::new(alloc(Layout::new::<i32>()).cast::<i32>())\n .expect(\"allocation failed\");\n // In general .write is required to avoid attempting to destruct\n // the (uninitialized) previous contents of `non_null`.\n non_null.write(5);\n let x = Box::from_non_null(non_null);\n }
\n-source\u00a7impl<T: ?Sized, A: Allocator> Box<T, A>
sourcepub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a box from a raw pointer in the given allocator.
\n+source\u00a7impl<T: ?Sized, A: Allocator> Box<T, A>
sourcepub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a box from a raw pointer in the given allocator.
\n After calling this function, the raw pointer is owned by the\n resulting Box
. Specifically, the Box
destructor will call\n the destructor of T
and free the allocated memory. For this\n to be safe, the memory must have been allocated in accordance\n with the memory layout used by Box
.
\n \u00a7Safety
\n This function is unsafe because improper use may lead to\n@@ -443,15 +443,15 @@\n let ptr = System.allocate(Layout::new::<i32>())?.as_mut_ptr() as *mut i32;\n // In general .write is required to avoid attempting to destruct\n // the (uninitialized) previous contents of `ptr`, though for this\n // simple example `*ptr = 5` would have worked as well.\n ptr.write(5);\n let x = Box::from_raw_in(ptr, System);\n }
\n-sourcepub const unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a box from a NonNull
pointer in the given allocator.
\n+sourcepub const unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Constructs a box from a NonNull
pointer in the given allocator.
\n After calling this function, the NonNull
pointer is owned by\n the resulting Box
. Specifically, the Box
destructor will call\n the destructor of T
and free the allocated memory. For this\n to be safe, the memory must have been allocated in accordance\n with the memory layout used by Box
.
\n \u00a7Safety
\n This function is unsafe because improper use may lead to\n@@ -477,15 +477,15 @@\n unsafe {\n let non_null = System.allocate(Layout::new::<i32>())?.cast::<i32>();\n // In general .write is required to avoid attempting to destruct\n // the (uninitialized) previous contents of `non_null`.\n non_null.write(5);\n let x = Box::from_non_null_in(non_null, System);\n }
\n-1.4.0 \u00b7 sourcepub fn into_raw(b: Self) -> *mut T
Consumes the Box
, returning a wrapped raw pointer.
\n+1.4.0 \u00b7 sourcepub fn into_raw(b: Self) -> *mut T
Consumes the Box
, returning a wrapped raw pointer.
\n The pointer will be properly aligned and non-null.
\n After calling this function, the caller is responsible for the\n memory previously managed by the Box
. In particular, the\n caller should properly destroy T
and release the memory, taking\n into account the memory layout used by Box
. The easiest way to\n do this is to convert the raw pointer back into a Box
with the\n Box::from_raw
function, allowing the Box
destructor to perform\n@@ -515,15 +515,15 @@\n
Note: This is equivalent to the following:
\n \n \n-sourcepub fn into_non_null(b: Self) -> NonNull<T>
\ud83d\udd2cThis is a nightly-only experimental API. (box_vec_non_null
#130364)
Consumes the Box
, returning a wrapped NonNull
pointer.
\n+sourcepub fn into_non_null(b: Self) -> NonNull<T>
\ud83d\udd2cThis is a nightly-only experimental API. (box_vec_non_null
#130364)
Consumes the Box
, returning a wrapped NonNull
pointer.
\n The pointer will be properly aligned.
\n After calling this function, the caller is responsible for the\n memory previously managed by the Box
. In particular, the\n caller should properly destroy T
and release the memory, taking\n into account the memory layout used by Box
. The easiest way to\n do this is to convert the NonNull
pointer back into a Box
with the\n Box::from_non_null
function, allowing the Box
destructor to\n@@ -558,15 +558,15 @@\n
\n-sourcepub fn into_raw_with_allocator(b: Self) -> (*mut T, A)
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Consumes the Box
, returning a wrapped raw pointer and the allocator.
\n+sourcepub fn into_raw_with_allocator(b: Self) -> (*mut T, A)
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Consumes the Box
, returning a wrapped raw pointer and the allocator.
\n The pointer will be properly aligned and non-null.
\n After calling this function, the caller is responsible for the\n memory previously managed by the Box
. In particular, the\n caller should properly destroy T
and release the memory, taking\n into account the memory layout used by Box
. The easiest way to\n do this is to convert the raw pointer back into a Box
with the\n Box::from_raw_in
function, allowing the Box
destructor to perform\n@@ -596,15 +596,15 @@\n let x = Box::new_in(String::from(\"Hello\"), System);\n let (ptr, alloc) = Box::into_raw_with_allocator(x);\n unsafe {\n ptr::drop_in_place(ptr);\n let non_null = NonNull::new_unchecked(ptr);\n alloc.deallocate(non_null.cast(), Layout::new::<String>());\n }
\n-sourcepub fn into_non_null_with_allocator(b: Self) -> (NonNull<T>, A)
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Consumes the Box
, returning a wrapped NonNull
pointer and the allocator.
\n+sourcepub fn into_non_null_with_allocator(b: Self) -> (NonNull<T>, A)
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Consumes the Box
, returning a wrapped NonNull
pointer and the allocator.
\n The pointer will be properly aligned.
\n After calling this function, the caller is responsible for the\n memory previously managed by the Box
. In particular, the\n caller should properly destroy T
and release the memory, taking\n into account the memory layout used by Box
. The easiest way to\n do this is to convert the NonNull
pointer back into a Box
with the\n Box::from_non_null_in
function, allowing the Box
destructor to\n@@ -633,15 +633,15 @@\n \n let x = Box::new_in(String::from(\"Hello\"), System);\n let (non_null, alloc) = Box::into_non_null_with_allocator(x);\n unsafe {\n non_null.drop_in_place();\n alloc.deallocate(non_null.cast::<u8>(), Layout::new::<String>());\n }
\n-sourcepub fn as_mut_ptr(b: &mut Self) -> *mut T
\ud83d\udd2cThis is a nightly-only experimental API. (box_as_ptr
#129090)
Returns a raw mutable pointer to the Box
\u2019s contents.
\n+sourcepub fn as_mut_ptr(b: &mut Self) -> *mut T
\ud83d\udd2cThis is a nightly-only experimental API. (box_as_ptr
#129090)
Returns a raw mutable pointer to the Box
\u2019s contents.
\n The caller must ensure that the Box
outlives the pointer this\n function returns, or else it will end up dangling.
\n This method guarantees that for the purpose of the aliasing model, this method\n does not materialize a reference to the underlying memory, and thus the returned pointer\n will remain valid when mixed with other calls to as_ptr
and as_mut_ptr
.\n Note that calling other methods that materialize references to the memory\n may still invalidate this pointer.\n@@ -656,15 +656,15 @@\n let ptr1 = Box::as_mut_ptr(&mut b);\n ptr1.write(1);\n let ptr2 = Box::as_mut_ptr(&mut b);\n ptr2.write(2);\n // Notably, the write to `ptr2` did *not* invalidate `ptr1`:\n ptr1.write(3);\n }
\n-sourcepub fn as_ptr(b: &Self) -> *const T
\ud83d\udd2cThis is a nightly-only experimental API. (box_as_ptr
#129090)
Returns a raw pointer to the Box
\u2019s contents.
\n+sourcepub fn as_ptr(b: &Self) -> *const T
\ud83d\udd2cThis is a nightly-only experimental API. (box_as_ptr
#129090)
Returns a raw pointer to the Box
\u2019s contents.
\n The caller must ensure that the Box
outlives the pointer this\n function returns, or else it will end up dangling.
\n The caller must also ensure that the memory the pointer (non-transitively) points to\n is never written to (except inside an UnsafeCell
) using this pointer or any pointer\n derived from it. If you need to mutate the contents of the Box
, use as_mut_ptr
.
\n This method guarantees that for the purpose of the aliasing model, this method\n does not materialize a reference to the underlying memory, and thus the returned pointer\n@@ -685,19 +685,19 @@\n // No write to this memory has happened yet, so `ptr1` is still valid.\n let _val = ptr1.read();\n // However, once we do a write...\n ptr2.write(1);\n // ... `ptr1` is no longer valid.\n // This would be UB: let _val = ptr1.read();\n }
\n-sourcepub const fn allocator(b: &Self) -> &A
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Returns a reference to the underlying allocator.
\n+sourcepub const fn allocator(b: &Self) -> &A
\ud83d\udd2cThis is a nightly-only experimental API. (allocator_api
#32838)
Returns a reference to the underlying allocator.
\n Note: this is an associated function, which means that you have\n to call it as Box::allocator(&b)
instead of b.allocator()
. This\n is so that there is no conflict with a method on the inner type.
\n-1.26.0 \u00b7 sourcepub fn leak<'a>(b: Self) -> &'a mut Twhere\n A: 'a,
Consumes and leaks the Box
, returning a mutable reference,\n &'a mut T
.
\n Note that the type T
must outlive the chosen lifetime 'a
. If the type\n has only static references, or none at all, then this may be chosen to be\n 'static
.
\n This function is mainly useful for data that lives for the remainder of\n the program\u2019s life. Dropping the returned reference will cause a memory\n@@ -717,19 +717,19 @@\n assert_eq!(*static_ref, 42);
\n Unsized data:
\n \n \n-1.63.0 (const: unstable) \u00b7 sourcepub fn into_pin(boxed: Self) -> Pin<Self>where\n- A: 'static,
Converts a Box<T>
into a Pin<Box<T>>
. If T
does not implement Unpin
, then\n+
1.63.0 (const: unstable) \u00b7 sourcepub fn into_pin(boxed: Self) -> Pin<Self>where\n+ A: 'static,
Converts a Box<T>
into a Pin<Box<T>>
. If T
does not implement Unpin
, then\n *boxed
will be pinned in memory and unable to be moved.
\n This conversion does not allocate on the heap and happens in place.
\n-This is also available via From
.
\n+This is also available via From
.
\n Constructing and pinning a Box
with Box::into_pin(Box::new(x))
\n can also be written more concisely using Box::pin(x)
.\n This into_pin
method is useful if you already have a Box<T>
, or you are\n constructing a (pinned) Box
in a different way than with Box::new
.
\n \u00a7Notes
\n It\u2019s not recommended that crates add an impl like From<Box<T>> for Pin<T>
,\n as it\u2019ll introduce an ambiguity when calling Pin::from
.\n@@ -740,295 +740,295 @@\n fn from(_: Box<()>) -> Pin<Foo> {\n Pin::new(Foo)\n }\n }\n \n let foo = Box::new(());\n let bar = Pin::from(foo);
\n-
source\u00a7impl<A: Allocator> Box<dyn Any, A>
1.0.0 \u00b7 sourcepub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self>
Attempts to downcast the box to a concrete type.
\n \u00a7Examples
\n use std::any::Any;\n \n fn print_if_string(value: Box<dyn Any>) {\n if let Ok(string) = value.downcast::<String>() {\n println!(\"String ({}): {}\", string.len(), string);\n }\n }\n \n let my_string = \"Hello World\".to_string();\n print_if_string(Box::new(my_string));\n print_if_string(Box::new(0i8));
\n-sourcepub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A>
\ud83d\udd2cThis is a nightly-only experimental API. (downcast_unchecked
#90850)
Downcasts the box to a concrete type.
\n+sourcepub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A>
\ud83d\udd2cThis is a nightly-only experimental API. (downcast_unchecked
#90850)
Downcasts the box to a concrete type.
\n For a safe alternative see downcast
.
\n \u00a7Examples
\n #![feature(downcast_unchecked)]\n \n use std::any::Any;\n \n let x: Box<dyn Any> = Box::new(1_usize);\n \n unsafe {\n assert_eq!(*x.downcast_unchecked::<usize>(), 1);\n }
\n \u00a7Safety
\n The contained value must be of type T
. Calling this method\n with the incorrect type is undefined behavior.
\n-source\u00a7impl<A: Allocator> Box<dyn Any + Send, A>
1.0.0 \u00b7 sourcepub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self>
Attempts to downcast the box to a concrete type.
\n \u00a7Examples
\n use std::any::Any;\n \n fn print_if_string(value: Box<dyn Any + Send>) {\n if let Ok(string) = value.downcast::<String>() {\n println!(\"String ({}): {}\", string.len(), string);\n }\n }\n \n let my_string = \"Hello World\".to_string();\n print_if_string(Box::new(my_string));\n print_if_string(Box::new(0i8));
\n-sourcepub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A>
\ud83d\udd2cThis is a nightly-only experimental API. (downcast_unchecked
#90850)
Downcasts the box to a concrete type.
\n+sourcepub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A>
\ud83d\udd2cThis is a nightly-only experimental API. (downcast_unchecked
#90850)
Downcasts the box to a concrete type.
\n For a safe alternative see downcast
.
\n \u00a7Examples
\n #![feature(downcast_unchecked)]\n \n use std::any::Any;\n \n let x: Box<dyn Any + Send> = Box::new(1_usize);\n \n unsafe {\n assert_eq!(*x.downcast_unchecked::<usize>(), 1);\n }
\n \u00a7Safety
\n The contained value must be of type T
. Calling this method\n with the incorrect type is undefined behavior.
\n-source\u00a7impl<A: Allocator> Box<dyn Any + Send + Sync, A>
1.51.0 \u00b7 sourcepub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self>
Attempts to downcast the box to a concrete type.
\n \u00a7Examples
\n use std::any::Any;\n \n fn print_if_string(value: Box<dyn Any + Send + Sync>) {\n if let Ok(string) = value.downcast::<String>() {\n println!(\"String ({}): {}\", string.len(), string);\n }\n }\n \n let my_string = \"Hello World\".to_string();\n print_if_string(Box::new(my_string));\n print_if_string(Box::new(0i8));
\n-sourcepub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A>
\ud83d\udd2cThis is a nightly-only experimental API. (downcast_unchecked
#90850)
Downcasts the box to a concrete type.
\n+sourcepub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A>
\ud83d\udd2cThis is a nightly-only experimental API. (downcast_unchecked
#90850)
Downcasts the box to a concrete type.
\n For a safe alternative see downcast
.
\n \u00a7Examples
\n #![feature(downcast_unchecked)]\n \n use std::any::Any;\n \n let x: Box<dyn Any + Send + Sync> = Box::new(1_usize);\n \n unsafe {\n assert_eq!(*x.downcast_unchecked::<usize>(), 1);\n }
\n \u00a7Safety
\n The contained value must be of type T
. Calling this method\n with the incorrect type is undefined behavior.
\n-
async_fn_traits
)AsyncFn
, returning a future which may borrow from the called closure.async_fn_traits
)AsyncFn
, returning a future which may borrow from the called closure.async_fn_traits
)AsyncFnMut::async_call_mut
and AsyncFn::async_call
.async_fn_traits
)AsyncFnMut::async_call_mut
and AsyncFn::async_call
.async_fn_traits
)AsyncFnMut
, returning a future which may borrow from the called closure.async_fn_traits
)async_fn_traits
)AsyncFnOnce::async_call_once
.async_fn_traits
)AsyncFnMut
, returning a future which may borrow from the called closure.async_fn_traits
)async_fn_traits
)AsyncFnOnce::async_call_once
.async_fn_traits
)AsyncFnOnce
, returning a future which may move out of the called closure.async_iterator
#79024)async_iterator
#79024)async_fn_traits
)AsyncFnOnce
, returning a future which may move out of the called closure.async_iterator
#79024)async_iterator
#79024)None
if the async iterator is exhausted. Read moreCopies source
\u2019s contents into self
without creating a new allocation,\n+None
if the async iterator is exhausted. Read more
Copies source
\u2019s contents into self
without creating a new allocation,\n so long as the two are of the same length.
Returns a new box with a clone()
of this box\u2019s contents.
Copies source
\u2019s contents into self
without creating a new allocation.
Copies source
\u2019s contents into self
without creating a new allocation.
coroutine_trait
#43122)coroutine_trait
#43122)coroutine_trait
#43122)coroutine_trait
#43122)n
th element from the end of the iterator. Read moreiter_advance_by
#77404)n
elements. Read moreIterator::try_fold()
: it takes\n-elements starting from the back of the iterator. Read moreextend_one
#72631)Converts a &[T]
into a Box<[T]>
coroutine_trait
#43122)n
th element from the end of the iterator. Read moreiter_advance_by
#77404)n
elements. Read moreIterator::try_fold()
: it takes\n+elements starting from the back of the iterator. Read moreextend_one
#72631)Converts a Box<T>
into a Pin<Box<T>>
. If T
does not implement Unpin
, then\n *boxed
will be pinned in memory and unable to be moved.
This conversion does not allocate on the heap and happens in place.
\nThis is also available via Box::into_pin
.
Constructing and pinning a Box
with <Pin<Box<T>>>::from(Box::new(x))
\n can also be written more concisely using Box::pin(x)
.\n This From
implementation is useful if you already have a Box<T>
, or you are\n constructing a (pinned) Box
in a different way than with Box::new
.
Converts a Box<str>
into a Box<[u8]>
This conversion does not allocate on the heap and happens in place.
\n// create a Box<str> which will be used to create a Box<[u8]>\n let boxed: Box<str> = Box::from(\"hello\");\n let boxed_str: Box<[u8]> = Box::from(boxed);\n \n // create a &[u8] which will be used to create a Box<[u8]>\n let slice: &[u8] = &[104, 101, 108, 108, 111];\n let boxed_slice = Box::from(slice);\n \n assert_eq!(boxed_slice, boxed_str);
Converts a Cow<'_, str>
into a Box<str>
When cow
is the Cow::Borrowed
variant, this\n conversion allocates on the heap and copies the\n underlying str
. Otherwise, it will try to reuse the owned\n String
\u2019s allocation.
Converts a type of Error
into a box of dyn Error
.
use std::error::Error;\n use std::fmt;\n use std::mem;\n \n #[derive(Debug)]\n struct AnError;\n@@ -1041,16 +1041,16 @@\n \n impl Error for AnError {}\n \n let an_error = AnError;\n assert!(0 == mem::size_of_val(&an_error));\n let a_boxed_error = Box::<dyn Error>::from(an_error);\n assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
Converts a type of Error
+ Send
+ Sync
into a box of\n+dyn Error
+ Send
+ Sync
.
use std::error::Error;\n use std::fmt;\n use std::mem;\n \n #[derive(Debug)]\n struct AnError;\n@@ -1068,287 +1068,287 @@\n unsafe impl Sync for AnError {}\n \n let an_error = AnError;\n assert!(0 == mem::size_of_val(&an_error));\n let a_boxed_error = Box::<dyn Error + Send + Sync>::from(an_error);\n assert!(\n mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
u128
into this hasher.usize
into this hasher.i128
into this hasher.isize
into this hasher.n
th element of the iterator. Read moreu128
into this hasher.usize
into this hasher.i128
into this hasher.isize
into this hasher.n
th element of the iterator. Read moreiter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moreiter_intersperse
#79524)separator
\n-between adjacent items of the original iterator. Read morepeek
and peek_mut
methods\n+) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>iter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moreiter_intersperse
#79524)separator
\n+between adjacent items of the original iterator. Read moren
elements. Read moren
elements, or fewer\n-if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n-self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n-the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_is_partitioned
#62544)true
precede all those that return false
. Read moren
elements. Read moren
elements, or fewer\n+if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n+self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n+the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_is_partitioned
#62544)true
precede all those that return false
. Read moreiterator_try_reduce
#87053)iterator_try_reduce
#87053)try_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read morePartialOrd
elements of\n-this Iterator
with those of another. The comparison works like short-circuit\n+ f: impl FnMut(&Self::Item) -> R,\n+) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypetry_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read morePartialOrd
elements of\n+this Iterator
with those of another. The comparison works like short-circuit\n evaluation, returning a result without comparing the remaining elements.\n-As soon as an order can be determined, the evaluation stops and a result is returned. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n-less than those of another. Read moreIterator
are lexicographically\n-less or equal to those of another. Read moreIterator
are lexicographically\n-greater than those of another. Read moreIterator
are lexicographically\n-greater than or equal to those of another. Read moreAttempts to convert a Box<[T]>
into a Box<[T; N]>
.
iter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n+less than those of another. Read moreIterator
are lexicographically\n+less or equal to those of another. Read moreIterator
are lexicographically\n+greater than those of another. Read moreIterator
are lexicographically\n+greater than or equal to those of another. Read moreAttempts to convert a Box<[T]>
into a Box<[T; N]>
.
The conversion occurs in-place and does not require a\n new memory allocation.
\nReturns the old Box<[T]>
in the Err
variant if\n boxed_slice.len()
does not equal N
.
Attempts to convert a Vec<T>
into a Box<[T; N]>
.
Like Vec::into_boxed_slice
, this is in-place if vec.capacity() == N
,\n but will require a reallocation otherwise.
Returns the original Vec<T>
in the Err
variant if\n boxed_slice.len()
does not equal N
.
This can be used with vec!
to create an array on the heap:
This implementation is required to make sure that the &Box<[I]>: IntoIterator
\n+
This implementation is required to make sure that the &Box<[I]>: IntoIterator
\n implementation doesn\u2019t overlap with IntoIterator for T where T: Iterator
blanket.
This implementation is required to make sure that the &mut Box<[I]>: IntoIterator
\n+
This implementation is required to make sure that the &mut Box<[I]>: IntoIterator
\n implementation doesn\u2019t overlap with IntoIterator for T where T: Iterator
blanket.
This implementation is required to make sure that the Box<[I]>: IntoIterator
\n+
This implementation is required to make sure that the Box<[I]>: IntoIterator
\n implementation doesn\u2019t overlap with IntoIterator for T where T: Iterator
blanket.
async_iterator
#79024)async_iterator
#79024)async_iterator
#79024)self
into an async iteratorpattern
#27721)pattern
#27721)self
and the haystack
to search in.pattern
#27721)pattern
#27721)pattern
#27721)pattern
#27721)async_iterator
#79024)async_iterator
#79024)async_iterator
#79024)self
into an async iteratorpattern
#27721)pattern
#27721)self
and the haystack
to search in.pattern
#27721)pattern
#27721)pattern
#27721)pattern
#27721)pattern
#27721)pub struct ThinBox<T: ?Sized> { /* private fields */ }
thin_box
#92791)ThinBox.
\n+pub struct ThinBox<T: ?Sized> { /* private fields */ }
thin_box
#92791)ThinBox.
\nA thin pointer for heap allocation, regardless of T.
\n#![feature(thin_box)]\n use std::boxed::ThinBox;\n \n let five = ThinBox::new(5);\n let thin_slice = ThinBox::<[i32]>::new_unsize([1, 2, 3, 4]);\n \n use std::mem::{size_of, size_of_val};\n let size_of_ptr = size_of::<*const ()>();\n assert_eq!(size_of_ptr, size_of_val(&five));\n assert_eq!(size_of_ptr, size_of_val(&thin_slice));
thin_box
#92791)Moves a type to the heap with its Metadata
stored in the heap allocation instead of on\n+
thin_box
#92791)thin_box
#92791)Moves a type to the heap with its Metadata
stored in the heap allocation instead of on\n+
thin_box
#92791)thin_box
#92791)Moves a type to the heap with its Metadata
stored in the heap allocation instead of on\n+
ThinBox<T>
is Send
if T
is Send
because the data is owned.
ThinBox<T>
is Sync
if T
is Sync
because the data is owned.
ThinBox<T>
is Send
if T
is Send
because the data is owned.
ThinBox<T>
is Sync
if T
is Sync
because the data is owned.
pub struct BinaryHeap<T, A: Allocator = Global> { /* private fields */ }
A priority queue implemented with a binary heap.
\nThis will be a max-heap.
\nIt is a logic error for an item to be modified in such a way that the\n-item\u2019s ordering relative to any other item, as determined by the Ord
\n+item\u2019s ordering relative to any other item, as determined by the Ord
\n trait, changes while it is in the heap. This is normally only possible\n through interior mutability, global state, I/O, or unsafe code. The\n behavior resulting from such a logic error is not specified, but will\n be encapsulated to the BinaryHeap
that observed the logic error and not\n result in undefined behavior. This could include panics, incorrect results,\n aborts, memory leaks, and non-termination.
As long as no elements change their relative order while being in the heap\n@@ -56,15 +56,15 @@\n assert!(heap.is_empty())
A BinaryHeap
with a known list of items can be initialized from an array:
Either core::cmp::Reverse
or a custom Ord
implementation can be used to\n+
Either core::cmp::Reverse
or a custom Ord
implementation can be used to\n make BinaryHeap
a min-heap. This makes heap.pop()
return the smallest\n value instead of the greatest one.
use std::collections::BinaryHeap;\n use std::cmp::Reverse;\n \n let mut heap = BinaryHeap::new();\n@@ -81,55 +81,55 @@\n assert_eq!(heap.pop(), None);
The value for push
is an expected cost; the method documentation gives a\n more detailed analysis.
Creates an empty BinaryHeap
as a max-heap.
Creates an empty BinaryHeap
with at least the specified capacity.
Creates an empty BinaryHeap
with at least the specified capacity.
The binary heap will be able to hold at least capacity
elements without\n reallocating. This method is allowed to allocate for more elements than\n capacity
. If capacity
is 0, the binary heap will not allocate.
Basic usage:
\n \n \n-allocator_api
#32838)Creates an empty BinaryHeap
as a max-heap, using A
as allocator.
allocator_api
#32838)Creates an empty BinaryHeap
as a max-heap, using A
as allocator.
Basic usage:
\n \n \n-allocator_api
#32838)Creates an empty BinaryHeap
with at least the specified capacity, using A
as allocator.
allocator_api
#32838)Creates an empty BinaryHeap
with at least the specified capacity, using A
as allocator.
The binary heap will be able to hold at least capacity
elements without\n reallocating. This method is allowed to allocate for more elements than\n capacity
. If capacity
is 0, the binary heap will not allocate.
Basic usage:
\n \n \n-Returns a mutable reference to the greatest item in the binary heap, or\n+
Returns a mutable reference to the greatest item in the binary heap, or\n None
if it is empty.
Note: If the PeekMut
value is leaked, some heap elements might get\n leaked along with it, but the remaining elements will remain a valid\n heap.
Basic usage:
\n \n@@ -144,15 +144,15 @@\n let mut val = heap.peek_mut().unwrap();\n *val = 0;\n }\n assert_eq!(heap.peek(), Some(&2));If the item is modified then the worst case time complexity is O(log(n)),\n otherwise it\u2019s O(1).
\n-Removes the greatest item from the binary heap and returns it, or None
if it\n+
Removes the greatest item from the binary heap and returns it, or None
if it\n is empty.
Basic usage:
\n \n \nRetains only the elements specified by the predicate.
\nIn other words, remove all elements e
for which f(&e)
returns\n false
. The elements are visited in unsorted (and unspecified) order.
Basic usage:
\n \nuse std::collections::BinaryHeap;\n \n@@ -264,72 +264,72 @@\n Basic usage:
\n \n \n-
Returns the greatest item in the binary heap, or None
if it is empty.
Returns the greatest item in the binary heap, or None
if it is empty.
Basic usage:
\n \nuse std::collections::BinaryHeap;\n let mut heap = BinaryHeap::new();\n assert_eq!(heap.peek(), None);\n \n heap.push(1);\n heap.push(5);\n heap.push(2);\n assert_eq!(heap.peek(), Some(&5));\n
Cost is O(1) in the worst case.
\n-Returns the number of elements the binary heap can hold without reallocating.
\n+Returns the number of elements the binary heap can hold without reallocating.
\nBasic usage:
\n \n \n-Reserves the minimum capacity for at least additional
elements more than\n+
Reserves the minimum capacity for at least additional
elements more than\n the current length. Unlike reserve
, this will not\n deliberately over-allocate to speculatively avoid frequent allocations.\n After calling reserve_exact
, capacity will be greater than or equal to\n self.len() + additional
. Does nothing if the capacity is already\n sufficient.
Panics if the new capacity overflows usize
.
Panics if the new capacity overflows usize
.
Basic usage:
\n \n \n-Reserves capacity for at least additional
elements more than the\n+
Reserves capacity for at least additional
elements more than the\n current length. The allocator may reserve more space to speculatively\n avoid frequent allocations. After calling reserve
,\n capacity will be greater than or equal to self.len() + additional
.\n Does nothing if capacity is already sufficient.
Panics if the new capacity overflows usize
.
Panics if the new capacity overflows usize
.
Basic usage:
\n \n \nTries to reserve the minimum capacity for at least additional
elements\n+ additional: usize,\n+) -> Result<(), TryReserveError>
Tries to reserve the minimum capacity for at least additional
elements\n more than the current length. Unlike try_reserve
, this will not\n deliberately over-allocate to speculatively avoid frequent allocations.\n After calling try_reserve_exact
, capacity will be greater than or\n equal to self.len() + additional
if it returns Ok(())
.\n Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it\n requests. Therefore, capacity can not be relied upon to be precisely\n@@ -348,15 +348,15 @@\n heap.try_reserve_exact(data.len())?;\n \n // Now we know this can't OOM in the middle of our complex work\n heap.extend(data.iter());\n \n Ok(heap.pop())\n }
Tries to reserve capacity for at least additional
elements more than the\n+
Tries to reserve capacity for at least additional
elements more than the\n current length. The allocator may reserve more space to speculatively\n avoid frequent allocations. After calling try_reserve
, capacity will be\n greater than or equal to self.len() + additional
if it returns\n Ok(())
. Does nothing if capacity is already sufficient. This method\n preserves the contents even if an error occurs.
If the capacity overflows, or the allocator reports a failure, then an error\n@@ -382,26 +382,26 @@\n \n
\n-Discards capacity with a lower bound.
\n+Discards capacity with a lower bound.
\nThe capacity will remain at least as large as both the length\n and the supplied value.
\nIf the current capacity is less than the lower limit, this is a no-op.
\nReturns a slice of all values in the underlying vector, in arbitrary\n+
Returns a slice of all values in the underlying vector, in arbitrary\n order.
\nBasic usage:
\n \n \n-allocator_api
#32838)Returns a reference to the underlying allocator.
\n-allocator_api
#32838)Returns a reference to the underlying allocator.
\n+Overwrites the contents of self
with a clone of the contents of source
.
Overwrites the contents of self
with a clone of the contents of source
.
This method is preferred over simply assigning source.clone()
to self
,\n as it avoids reallocation if possible.
See Vec::clone_from()
for more details.
Creates an empty BinaryHeap<T>
.
extend_one
#72631)extend_one
#72631)Creates an empty BinaryHeap<T>
.
extend_one
#72631)extend_one
#72631)Converts a BinaryHeap<T>
into a Vec<T>
.
Converts a BinaryHeap<T>
into a Vec<T>
.
This conversion requires no data movement or allocation, and has\n constant time complexity.
\n-Converts a Vec<T>
into a BinaryHeap<T>
.
Converts a Vec<T>
into a BinaryHeap<T>
.
This conversion happens in-place, and has O(n) time complexity.
\n-pub struct Drain<'a, T: 'a, A: Allocator = Global> { /* private fields */ }
A draining iterator over the elements of a BinaryHeap
.
This struct
is created by BinaryHeap::drain()
. See its\n documentation for more.
iter_advance_by
#77404)n
elements. Read moren
th element from the end of the iterator. Read moreIterator::try_fold()
: it takes\n-elements starting from the back of the iterator. Read moreiter_advance_by
#77404)n
elements. Read moren
th element from the end of the iterator. Read moreIterator::try_fold()
: it takes\n+elements starting from the back of the iterator. Read moreiter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n-between adjacent items of the original iterator. Read morepeek
and peek_mut
methods\n+) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>iter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n+between adjacent items of the original iterator. Read moren
elements. Read moren
elements, or fewer\n-if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n-self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n-the windows during mapping overlap as well. Read moreiter_collect_into
#94780)n
elements. Read moren
elements, or fewer\n+if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n+self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n+the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_partition_in_place
#62543)iter_partition_in_place
#62543)true
precede all those that return false
.\n-Returns the number of true
elements found. Read moreiter_is_partitioned
#62544)true
precede all those that return false
. Read moretrue
elements found. Read moreiter_is_partitioned
#62544)true
precede all those that return false
. Read moreiterator_try_reduce
#87053)iterator_try_reduce
#87053)try_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read morePartialOrd
elements of\n-this Iterator
with those of another. The comparison works like short-circuit\n+ f: impl FnMut(&Self::Item) -> R,\n+) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypetry_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read morePartialOrd
elements of\n+this Iterator
with those of another. The comparison works like short-circuit\n evaluation, returning a result without comparing the remaining elements.\n-As soon as an order can be determined, the evaluation stops and a result is returned. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n-less than those of another. Read moreIterator
are lexicographically\n-less or equal to those of another. Read moreIterator
are lexicographically\n-greater than those of another. Read moreIterator
are lexicographically\n-greater than or equal to those of another. Read moreCalls U::from(self)
.
iter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n+less than those of another. Read moreIterator
are lexicographically\n+less or equal to those of another. Read moreIterator
are lexicographically\n+greater than those of another. Read moreIterator
are lexicographically\n+greater than or equal to those of another. Read moreFrom<T> for U
chooses to do.\n+pub struct DrainSorted<'a, T: Ord, A: Allocator = Global> { /* private fields */ }
binary_heap_drain_sorted
#59278)A draining iterator over the elements of a BinaryHeap
.
pub struct DrainSorted<'a, T: Ord, A: Allocator = Global> { /* private fields */ }
binary_heap_drain_sorted
#59278)A draining iterator over the elements of a BinaryHeap
.
This struct
is created by BinaryHeap::drain_sorted()
. See its\n documentation for more.
iter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n-between adjacent items of the original iterator. Read morepeek
and peek_mut
methods\n+) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>iter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n+between adjacent items of the original iterator. Read moren
elements. Read moren
elements, or fewer\n-if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n-self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n-the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_is_partitioned
#62544)true
precede all those that return false
. Read moren
elements. Read moren
elements, or fewer\n+if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n+self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n+the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_is_partitioned
#62544)true
precede all those that return false
. Read moreiterator_try_reduce
#87053)iterator_try_reduce
#87053)try_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read morePartialOrd
elements of\n-this Iterator
with those of another. The comparison works like short-circuit\n+ f: impl FnMut(&Self::Item) -> R,\n+) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypetry_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read morePartialOrd
elements of\n+this Iterator
with those of another. The comparison works like short-circuit\n evaluation, returning a result without comparing the remaining elements.\n-As soon as an order can be determined, the evaluation stops and a result is returned. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n-less than those of another. Read moreIterator
are lexicographically\n-less or equal to those of another. Read moreIterator
are lexicographically\n-greater than those of another. Read moreIterator
are lexicographically\n-greater than or equal to those of another. Read moreCalls U::from(self)
.
iter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n+less than those of another. Read moreIterator
are lexicographically\n+less or equal to those of another. Read moreIterator
are lexicographically\n+greater than those of another. Read moreIterator
are lexicographically\n+greater than or equal to those of another. Read moreFrom<T> for U
chooses to do.\n+pub struct IntoIter<T, A: Allocator = Global> { /* private fields */ }
An owning iterator over the elements of a BinaryHeap
.
This struct
is created by BinaryHeap::into_iter()
\n-(provided by the IntoIterator
trait). See its documentation for more.
Creates an empty binary_heap::IntoIter
.
IntoIterator
trait). See its documentation for more.\n+iter_advance_by
#77404)n
elements. Read moren
th element from the end of the iterator. Read moreIterator::try_fold()
: it takes\n-elements starting from the back of the iterator. Read moreiter_advance_by
#77404)n
elements. Read moren
th element from the end of the iterator. Read moreIterator::try_fold()
: it takes\n+elements starting from the back of the iterator. Read moreiter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n-between adjacent items of the original iterator. Read morepeek
and peek_mut
methods\n+) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>iter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n+between adjacent items of the original iterator. Read moren
elements. Read moren
elements, or fewer\n-if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n-self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n-the windows during mapping overlap as well. Read moreiter_collect_into
#94780)n
elements. Read moren
elements, or fewer\n+if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n+self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n+the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_partition_in_place
#62543)iter_partition_in_place
#62543)true
precede all those that return false
.\n-Returns the number of true
elements found. Read moreiter_is_partitioned
#62544)true
precede all those that return false
. Read moretrue
elements found. Read moreiter_is_partitioned
#62544)true
precede all those that return false
. Read moreiterator_try_reduce
#87053)iterator_try_reduce
#87053)try_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read morePartialOrd
elements of\n-this Iterator
with those of another. The comparison works like short-circuit\n+ f: impl FnMut(&Self::Item) -> R,\n+) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypetry_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read morePartialOrd
elements of\n+this Iterator
with those of another. The comparison works like short-circuit\n evaluation, returning a result without comparing the remaining elements.\n-As soon as an order can be determined, the evaluation stops and a result is returned. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n-less than those of another. Read moreIterator
are lexicographically\n-less or equal to those of another. Read moreIterator
are lexicographically\n-greater than those of another. Read moreIterator
are lexicographically\n-greater than or equal to those of another. Read moreCalls U::from(self)
.
iter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n+less than those of another. Read moreIterator
are lexicographically\n+less or equal to those of another. Read moreIterator
are lexicographically\n+greater than those of another. Read moreIterator
are lexicographically\n+greater than or equal to those of another. Read moreFrom<T> for U
chooses to do.\n+pub struct IntoIterSorted<T, A: Allocator = Global> { /* private fields */ }
binary_heap_into_iter_sorted
#59278)source
. Read morepub struct IntoIterSorted<T, A: Allocator = Global> { /* private fields */ }
binary_heap_into_iter_sorted
#59278)source
. Read moreiter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n-between adjacent items of the original iterator. Read morepeek
and peek_mut
methods\n+) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>iter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n+between adjacent items of the original iterator. Read moren
elements. Read moren
elements, or fewer\n-if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n-self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n-the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_is_partitioned
#62544)true
precede all those that return false
. Read moren
elements. Read moren
elements, or fewer\n+if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n+self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n+the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_is_partitioned
#62544)true
precede all those that return false
. Read moreiterator_try_reduce
#87053)iterator_try_reduce
#87053)try_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read morePartialOrd
elements of\n-this Iterator
with those of another. The comparison works like short-circuit\n+ f: impl FnMut(&Self::Item) -> R,\n+) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypetry_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read morePartialOrd
elements of\n+this Iterator
with those of another. The comparison works like short-circuit\n evaluation, returning a result without comparing the remaining elements.\n-As soon as an order can be determined, the evaluation stops and a result is returned. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n-less than those of another. Read moreIterator
are lexicographically\n-less or equal to those of another. Read moreIterator
are lexicographically\n-greater than those of another. Read moreIterator
are lexicographically\n-greater than or equal to those of another. Read moreCalls U::from(self)
.
iter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n+less than those of another. Read moreIterator
are lexicographically\n+less or equal to those of another. Read moreIterator
are lexicographically\n+greater than those of another. Read moreIterator
are lexicographically\n+greater than or equal to those of another. Read moreFrom<T> for U
chooses to do.\n+pub struct Iter<'a, T: 'a> { /* private fields */ }
An iterator over the elements of a BinaryHeap
.
This struct
is created by BinaryHeap::iter()
. See its\n documentation for more.
iter_advance_by
#77404)n
elements. Read moren
th element from the end of the iterator. Read moreIterator::try_fold()
: it takes\n-elements starting from the back of the iterator. Read moreiter_advance_by
#77404)n
elements. Read moren
th element from the end of the iterator. Read moreIterator::try_fold()
: it takes\n+elements starting from the back of the iterator. Read moreiter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n-between adjacent items of the original iterator. Read morepeek
and peek_mut
methods\n+) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>iter_next_chunk
#98326)N
values. Read moreiter_advance_by
#77404)n
elements. Read moren
th element of the iterator. Read moreiter_intersperse
#79524)separator
\n+between adjacent items of the original iterator. Read moren
elements. Read moren
elements, or fewer\n-if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n-self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n-the windows during mapping overlap as well. Read moreiter_collect_into
#94780)n
elements. Read moren
elements, or fewer\n+if the underlying iterator ends sooner. Read moreiter_map_windows
#87155)f
for each contiguous window of size N
over\n+self
and returns an iterator over the outputs of f
. Like slice::windows()
,\n+the windows during mapping overlap as well. Read moreiter_collect_into
#94780)iter_partition_in_place
#62543)iter_partition_in_place
#62543)true
precede all those that return false
.\n-Returns the number of true
elements found. Read moreiter_is_partitioned
#62544)true
precede all those that return false
. Read moretrue
elements found. Read moreiter_is_partitioned
#62544)true
precede all those that return false
. Read moreiterator_try_reduce
#87053)iterator_try_reduce
#87053)try_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read morePartialOrd
elements of\n-this Iterator
with those of another. The comparison works like short-circuit\n+ f: impl FnMut(&Self::Item) -> R,\n+) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypetry_find
#63178)iter_array_chunks
#100450)N
elements of the iterator at a time. Read moreiter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read morePartialOrd
elements of\n+this Iterator
with those of another. The comparison works like short-circuit\n evaluation, returning a result without comparing the remaining elements.\n-As soon as an order can be determined, the evaluation stops and a result is returned. Read moreiter_order_by
#64295)Iterator
with those\n-of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n-less than those of another. Read moreIterator
are lexicographically\n-less or equal to those of another. Read moreIterator
are lexicographically\n-greater than those of another. Read moreIterator
are lexicographically\n-greater than or equal to those of another. Read moreCalls U::from(self)
.
iter_order_by
#64295)Iterator
with those\n+of another with respect to the specified comparison function. Read moreiter_order_by
#64295)Iterator
are lexicographically\n+less than those of another. Read moreIterator
are lexicographically\n+less or equal to those of another. Read moreIterator
are lexicographically\n+greater than those of another. Read moreIterator
are lexicographically\n+greater than or equal to those of another. Read moreFrom<T> for U
chooses to do.\n+pub struct PeekMut<'a, T: 'a + Ord, A: Allocator = Global> { /* private fields */ }
Structure wrapping a mutable reference to the greatest item on a\n+
pub struct PeekMut<'a, T: 'a + Ord, A: Allocator = Global> { /* private fields */ }
Structure wrapping a mutable reference to the greatest item on a\n BinaryHeap
.
This struct
is created by the peek_mut
method on BinaryHeap
. See\n its documentation for more.
From<T> for U
chooses to do.\n+pub enum Entry<'a, K: 'a, V: 'a, A: Allocator + Clone = Global> {\n+Entry in alloc::collections::btree_map - Rust pub enum Entry<'a, K: 'a, V: 'a, A: Allocator + Clone = Global> {\n Vacant(VacantEntry<'a, K, V, A>),\n Occupied(OccupiedEntry<'a, K, V, A>),\n }
Expand description
Variants\u00a7
\u00a71.36.0Vacant(VacantEntry<'a, K, V, A>)
A vacant entry.
\n \u00a71.36.0Occupied(OccupiedEntry<'a, K, V, A>)
An occupied entry.
\n-Implementations\u00a7
source\u00a7impl<'a, K: Ord, V, A: Allocator + Clone> Entry<'a, K, V, A>
Implementations\u00a7
source\u00a7impl<'a, K: Ord, V, A: Allocator + Clone> Entry<'a, K, V, A>
1.0.0 \u00b7 sourcepub fn or_insert(self, default: V) -> &'a mut V
Ensures a value is in the entry by inserting the default if empty, and returns\n a mutable reference to the value in the entry.
\n \u00a7Examples
\n \n-1.0.0 \u00b7 sourcepub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
Ensures a value is in the entry by inserting the result of the default function if empty,\n+
1.0.0 \u00b7 sourcepub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
Ensures a value is in the entry by inserting the result of the default function if empty,\n and returns a mutable reference to the value in the entry.
\n \u00a7Examples
\n \n-1.50.0 \u00b7 sourcepub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V
Ensures a value is in the entry by inserting, if empty, the result of the default function.
\n+1.50.0 \u00b7 sourcepub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V
Ensures a value is in the entry by inserting, if empty, the result of the default function.
\n This method allows for generating key-derived values for insertion by providing the default\n function a reference to the key that was moved during the .entry(key)
method call.
\n The reference to the moved key is provided so that cloning or copying the key is\n unnecessary, unlike with .or_insert_with(|| ... )
.
\n \u00a7Examples
\n \n-1.10.0 \u00b7 sourcepub fn key(&self) -> &K
Returns a reference to this entry\u2019s key.
\n \u00a7Examples
\n \n 1.26.0 \u00b7 sourcepub fn and_modify<F>(self, f: F) -> Self
Provides in-place mutable access to an occupied entry before any\n potential inserts into the map.
\n \u00a7Examples
\n use std::collections::BTreeMap;\n \n let mut map: BTreeMap<&str, usize> = BTreeMap::new();\n \n map.entry(\"poneyland\")\n@@ -57,40 +57,40 @@\n .or_insert(42);\n assert_eq!(map[\"poneyland\"], 42);\n \n map.entry(\"poneyland\")\n .and_modify(|e| { *e += 1 })\n .or_insert(42);\n assert_eq!(map[\"poneyland\"], 43);
\n-source\u00a7impl<'a, K: Ord, V: Default, A: Allocator + Clone> Entry<'a, K, V, A>
1.28.0 \u00b7 sourcepub fn or_default(self) -> &'a mut V
Ensures a value is in the entry by inserting the default value if empty,\n+
Trait Implementations\u00a7
Auto Trait Implementations\u00a7
\u00a7impl<'a, K, V, A> Freeze for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> RefUnwindSafe for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> Send for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> Sync for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> Unpin for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A = Global> !UnwindSafe for Entry<'a, K, V, A>
Blanket Implementations\u00a7
Trait Implementations\u00a7
Auto Trait Implementations\u00a7
\u00a7impl<'a, K, V, A> Freeze for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> RefUnwindSafe for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> Send for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> Sync for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A> Unpin for Entry<'a, K, V, A>
\u00a7impl<'a, K, V, A = Global> !UnwindSafe for Entry<'a, K, V, A>
Blanket Implementations\u00a7
source\u00a7impl<T> BorrowMut<T> for Twhere\n+ T: ?Sized,
source\u00a7fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more\n+From<T> for U
chooses to do.\n+
pub struct BTreeMap<K, V, A: Allocator + Clone = Global> { /* private fields */ }
An ordered map based on a B-Tree.
\n+pub struct BTreeMap<K, V, A: Allocator + Clone = Global> { /* private fields */ }
An ordered map based on a B-Tree.
\nB-Trees represent a fundamental compromise between cache-efficiency and actually minimizing\n the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal\n choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum amount of\n comparisons necessary to find an element (log2n). However, in practice the way this\n is done is very inefficient for modern computer architectures. In particular, every element\n is stored in its own individually heap-allocated node. This means that every single insertion\n triggers a heap-allocation, and every single comparison should be a cache-miss. Since these\n@@ -18,16 +18,16 @@\n
Currently, our implementation simply performs naive linear search. This provides excellent\n performance on small nodes of elements which are cheap to compare. However in the future we\n would like to further explore choosing the optimal search strategy based on the choice of B,\n and possibly other factors. Using linear search, searching for a random element is expected\n to take B * log(n) comparisons, which is generally worse than a BST. In practice,\n however, performance is excellent.
\nIt is a logic error for a key to be modified in such a way that the key\u2019s ordering relative to\n-any other key, as determined by the Ord
trait, changes while it is in the map. This is\n-normally only possible through Cell
, RefCell
, global state, I/O, or unsafe code.\n+any other key, as determined by the Ord
trait, changes while it is in the map. This is\n+normally only possible through Cell
, RefCell
, global state, I/O, or unsafe code.\n The behavior resulting from such a logic error is not specified, but will be encapsulated to the\n BTreeMap
that observed the logic error and not result in undefined behavior. This could\n include panics, incorrect results, aborts, memory leaks, and non-termination.
Iterators obtained from functions such as BTreeMap::iter
, BTreeMap::into_iter
, BTreeMap::values
, or\n BTreeMap::keys
produce their items in order by key, and take worst-case logarithmic and\n amortized constant time per item returned.
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map\u2019s key type, but the ordering\n on the borrowed form must match the ordering on the key type.
\nReturns the key-value pair corresponding to the supplied key.
\n+Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map\u2019s key type, but the ordering\n on the borrowed form must match the ordering on the key type.
\nReturns the first key-value pair in the map.\n+
Returns the first key-value pair in the map.\n The key in this pair is the minimum key in the map.
\nReturns the first entry in the map for in-place manipulation.\n+
Returns the first entry in the map for in-place manipulation.\n The key of this entry is the minimum key in the map.
\nuse std::collections::BTreeMap;\n \n let mut map = BTreeMap::new();\n map.insert(1, \"a\");\n map.insert(2, \"b\");\n if let Some(mut entry) = map.first_entry() {\n if *entry.key() > 0 {\n entry.insert(\"first\");\n }\n }\n assert_eq!(*map.get(&1).unwrap(), \"first\");\n assert_eq!(*map.get(&2).unwrap(), \"b\");
Removes and returns the first element in the map.\n+
Removes and returns the first element in the map.\n The key of this element is the minimum key that was in the map.
\nDraining elements in ascending order, while keeping a usable map each iteration.
\n \n \n-Returns the last key-value pair in the map.\n+
Returns the last key-value pair in the map.\n The key in this pair is the maximum key in the map.
\nReturns the last entry in the map for in-place manipulation.\n+
Returns the last entry in the map for in-place manipulation.\n The key of this entry is the maximum key in the map.
\nuse std::collections::BTreeMap;\n \n let mut map = BTreeMap::new();\n map.insert(1, \"a\");\n map.insert(2, \"b\");\n if let Some(mut entry) = map.last_entry() {\n if *entry.key() > 0 {\n entry.insert(\"last\");\n }\n }\n assert_eq!(*map.get(&1).unwrap(), \"a\");\n assert_eq!(*map.get(&2).unwrap(), \"last\");
Removes and returns the last element in the map.\n+
Removes and returns the last element in the map.\n The key of this element is the maximum key that was in the map.
\nDraining elements in descending order, while keeping a usable map each iteration.
\n \n \n-Returns true
if the map contains a value for the specified key.
Returns true
if the map contains a value for the specified key.
The key may be any borrowed form of the map\u2019s key type, but the ordering\n on the borrowed form must match the ordering on the key type.
\nReturns a mutable reference to the value corresponding to the key.
\n+Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map\u2019s key type, but the ordering\n on the borrowed form must match the ordering on the key type.
\nInserts a key-value pair into the map.
\n+Inserts a key-value pair into the map.
\nIf the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old\n value is returned. The key is not updated, though; this matters for\n types that can be ==
without being identical. See the module-level\n documentation for more.
map_try_insert
#82766)Tries to insert a key-value pair into the map, and returns\n+) -> Result<&mut V, OccupiedError<'_, K, V, A>>
map_try_insert
#82766)Tries to insert a key-value pair into the map, and returns\n a mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\n an error containing the occupied entry and the value is returned.
\n#![feature(map_try_insert)]\n \n use std::collections::BTreeMap;\n@@ -299,55 +299,55 @@\n let mut map = BTreeMap::new();\n assert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n \n let err = map.try_insert(37, \"b\").unwrap_err();\n assert_eq!(err.entry.key(), &37);\n assert_eq!(err.entry.get(), &\"a\");\n assert_eq!(err.value, \"b\");
Removes a key from the map, returning the value at the key if the key\n+
Removes a key from the map, returning the value at the key if the key\n was previously in the map.
\nThe key may be any borrowed form of the map\u2019s key type, but the ordering\n on the borrowed form must match the ordering on the key type.
\nRemoves a key from the map, returning the stored key and value if the key\n+
Removes a key from the map, returning the stored key and value if the key\n was previously in the map.
\nThe key may be any borrowed form of the map\u2019s key type, but the ordering\n on the borrowed form must match the ordering on the key type.
\nRetains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\n The elements are visited in ascending key order.
Moves all elements from other
into self
, leaving other
empty.
If a key from other
is already present in self
, the respective\n value from self
will be overwritten with the respective value from other
.
Constructs a double-ended iterator over a sub-range of elements in the map.\n+ T: Ord + ?Sized,\n+ K: Borrow<T> + Ord,\n+ R: RangeBounds<T>,
Constructs a double-ended iterator over a sub-range of elements in the map.\n The simplest way is to use the range syntax min..max
, thus range(min..max)
will\n yield elements from min (inclusive) to max (exclusive).\n The range may also be entered as (Bound<T>, Bound<T>)
, so for example\n range((Excluded(4), Included(10)))
will yield a left-exclusive, right-inclusive\n range from 4 to 10.
Panics if range start > end
.\n@@ -390,17 +390,17 @@\n map.insert(5, \"b\");\n map.insert(8, \"c\");\n for (&key, &value) in map.range((Included(&4), Included(&8))) {\n println!(\"{key}: {value}\");\n }\n assert_eq!(Some((&5, &\"b\")), map.range(4..).next());
Constructs a mutable double-ended iterator over a sub-range of elements in the map.\n+ T: Ord + ?Sized,\n+ K: Borrow<T> + Ord,\n+ R: RangeBounds<T>,
Constructs a mutable double-ended iterator over a sub-range of elements in the map.\n The simplest way is to use the range syntax min..max
, thus range(min..max)
will\n yield elements from min (inclusive) to max (exclusive).\n The range may also be entered as (Bound<T>, Bound<T>)
, so for example\n range((Excluded(4), Included(10)))
will yield a left-exclusive, right-inclusive\n range from 4 to 10.
Panics if range start > end
.\n@@ -413,31 +413,31 @@\n for (_, balance) in map.range_mut(\"B\"..\"Cheryl\") {\n *balance += 100;\n }\n for (name, balance) in &map {\n println!(\"{name} => {balance}\");\n }
Gets the given key\u2019s corresponding entry in the map for in-place manipulation.
\n+ K: Ord,Gets the given key\u2019s corresponding entry in the map for in-place manipulation.
\nuse std::collections::BTreeMap;\n \n let mut count: BTreeMap<&str, usize> = BTreeMap::new();\n \n // count the number of occurrences of letters in the vec\n for x in [\"a\", \"b\", \"a\", \"c\", \"a\", \"b\"] {\n count.entry(x).and_modify(|curr| *curr += 1).or_insert(1);\n }\n \n assert_eq!(count[\"a\"], 3);\n assert_eq!(count[\"b\"], 2);\n assert_eq!(count[\"c\"], 1);
Splits the collection into two at the given key. Returns everything after the given key,\n+
Splits the collection into two at the given key. Returns everything after the given key,\n including the key.
\nbtree_extract_if
#70530)Creates an iterator that visits all elements (key-value pairs) in\n+ K: Ord,\n+ F: FnMut(&K, &mut V) -> bool,
btree_extract_if
#70530)Creates an iterator that visits all elements (key-value pairs) in\n ascending key order and uses a closure to determine if an element should\n be removed. If the closure returns true
, the element is removed from\n the map and yielded. If the closure returns false
, or panics, the\n element remains in the map and will not be yielded.
The iterator also lets you mutate the value of each element in the\n closure, regardless of whether you choose to keep or remove it.
\nIf the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\n@@ -499,15 +499,15 @@\n \n let mut a = BTreeMap::new();\n a.insert(1, \"hello\");\n a.insert(2, \"goodbye\");\n \n let values: Vec<&str> = a.into_values().collect();\n assert_eq!(values, [\"hello\", \"goodbye\"]);
Gets an iterator over the entries of the map, sorted by key.
\nuse std::collections::BTreeMap;\n \n let mut map = BTreeMap::new();\n map.insert(3, \"c\");\n map.insert(2, \"b\");\n map.insert(1, \"a\");\n@@ -565,33 +565,33 @@\n for value in a.values_mut() {\n value.push_str(\"!\");\n }\n \n let values: Vec<String> = a.values().cloned().collect();\n assert_eq!(values, [String::from(\"hello!\"),\n String::from(\"goodbye!\")]);
Returns the number of elements in the map.
\n+Returns the number of elements in the map.
\nReturns true
if the map contains no elements.
Returns true
if the map contains no elements.
btree_cursors
#107540)Returns a Cursor
pointing at the gap before the smallest key\n+
btree_cursors
#107540)Returns a Cursor
pointing at the gap before the smallest key\n greater than the given bound.
Passing Bound::Included(x)
will return a cursor pointing to the\n gap before the smallest key greater than or equal to x
.
Passing Bound::Excluded(x)
will return a cursor pointing to the\n gap before the smallest key greater than x
.
Passing Bound::Unbounded
will return a cursor pointing to the\n gap before the smallest key in the map.
btree_cursors
#107540)Returns a CursorMut
pointing at the gap before the smallest key\n+
btree_cursors
#107540)Returns a CursorMut
pointing at the gap before the smallest key\n greater than the given bound.
Passing Bound::Included(x)
will return a cursor pointing to the\n gap before the smallest key greater than or equal to x
.
Passing Bound::Excluded(x)
will return a cursor pointing to the\n gap before the smallest key greater than x
.
Passing Bound::Unbounded
will return a cursor pointing to the\n gap before the smallest key in the map.
btree_cursors
#107540)Returns a Cursor
pointing at the gap after the greatest key\n+
btree_cursors
#107540)Returns a Cursor
pointing at the gap after the greatest key\n smaller than the given bound.
Passing Bound::Included(x)
will return a cursor pointing to the\n gap after the greatest key smaller than or equal to x
.
Passing Bound::Excluded(x)
will return a cursor pointing to the\n gap after the greatest key smaller than x
.
Passing Bound::Unbounded
will return a cursor pointing to the\n gap after the greatest key in the map.
btree_cursors
#107540)Returns a CursorMut
pointing at the gap after the greatest key\n+
btree_cursors
#107540)Returns a CursorMut
pointing at the gap after the greatest key\n smaller than the given bound.
Passing Bound::Included(x)
will return a cursor pointing to the\n gap after the greatest key smaller than or equal to x
.
Passing Bound::Excluded(x)
will return a cursor pointing to the\n gap after the greatest key smaller than x
.
Passing Bound::Unbounded
will return a cursor pointing to the\n gap after the greatest key in the map.
extend_one
#72631)extend_one
#72631)pub struct Cursor<'a, K: 'a, V: 'a> { /* private fields */ }
btree_cursors
#107540)A cursor over a BTreeMap
.
A Cursor
is like an iterator, except that it can freely seek back-and-forth.
Cursors always point to a gap between two elements in the map, and can\n operate on the two immediately adjacent elements.
\nA Cursor
is created with the BTreeMap::lower_bound
and BTreeMap::upper_bound
methods.
btree_cursors
#107540)Advances the cursor to the next gap, returning the key and value of the\n+
btree_cursors
#107540)Advances the cursor to the next gap, returning the key and value of the\n element that it moved over.
\nIf the cursor is already at the end of the map then None
is returned\n and the cursor is not moved.
btree_cursors
#107540)Advances the cursor to the previous gap, returning the key and value of\n+
btree_cursors
#107540)Advances the cursor to the previous gap, returning the key and value of\n the element that it moved over.
\nIf the cursor is already at the start of the map then None
is returned\n and the cursor is not moved.
btree_cursors
#107540)Returns a reference to the key and value of the next element without\n+
btree_cursors
#107540)Returns a reference to the key and value of the next element without\n moving the cursor.
\nIf the cursor is at the end of the map then None
is returned.
Cursors always point to a gap between two elements in the map, and can\n operate on the two immediately adjacent elements.
\nA CursorMut
is created with the BTreeMap::lower_bound_mut
and BTreeMap::upper_bound_mut
\n methods.
btree_cursors
#107540)Advances the cursor to the next gap, returning the key and value of the\n+
btree_cursors
#107540)Advances the cursor to the next gap, returning the key and value of the\n element that it moved over.
\nIf the cursor is already at the end of the map then None
is returned\n and the cursor is not moved.
btree_cursors
#107540)Advances the cursor to the previous gap, returning the key and value of\n+
btree_cursors
#107540)Advances the cursor to the previous gap, returning the key and value of\n the element that it moved over.
\nIf the cursor is already at the start of the map then None
is returned\n and the cursor is not moved.
btree_cursors
#107540)Returns a reference to the key and value of the next element without\n+
btree_cursors
#107540)Returns a reference to the key and value of the next element without\n moving the cursor.
\nIf the cursor is at the end of the map then None
is returned.
btree_cursors
#107540)Returns a reference to the key and value of the previous element\n+
btree_cursors
#107540)Returns a reference to the key and value of the previous element\n without moving the cursor.
\nIf the cursor is at the start of the map then None
is returned.
btree_cursors
#107540)Returns a read-only cursor pointing to the same location as the\n CursorMut
.
The lifetime of the returned Cursor
is bound to that of the\n CursorMut
, which means it cannot outlive the CursorMut
and that the\n CursorMut
is frozen for the lifetime of the Cursor
.
Since this cursor allows mutating keys, you must ensure that the BTreeMap
\n invariants are maintained. Specifically:
btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n+
btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n cursor is currently pointing to.
\nAfter the insertion the cursor will be pointing at the gap after the\n newly inserted element.
\nYou must ensure that the BTreeMap
invariants are maintained.\n Specifically:
btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n+) -> Result<(), UnorderedKeyError>\ud83d\udd2cThis is a nightly-only experimental API. (btree_cursors
#107540)
Inserts a new key-value pair into the map in the gap that the\n cursor is currently pointing to.
\nAfter the insertion the cursor will be pointing at the gap before the\n newly inserted element.
\nIf the inserted key is not greater than the key before the cursor\n (if any), or if it not less than the key after the cursor (if any),\n then an UnorderedKeyError
is returned since this would\n-invalidate the Ord
invariant between the keys of the map.
Ord
invariant between the keys of the map.\n btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n+) -> Result<(), UnorderedKeyError>\ud83d\udd2cThis is a nightly-only experimental API. (btree_cursors
#107540)
Inserts a new key-value pair into the map in the gap that the\n cursor is currently pointing to.
\nAfter the insertion the cursor will be pointing at the gap after the\n newly inserted element.
\nIf the inserted key is not greater than the key before the cursor\n (if any), or if it not less than the key after the cursor (if any),\n then an UnorderedKeyError
is returned since this would\n-invalidate the Ord
invariant between the keys of the map.
btree_cursors
#107540)Removes the next element from the BTreeMap
.
Ord
invariant between the keys of the map.\n+btree_cursors
#107540)Removes the next element from the BTreeMap
.
The element that was removed is returned. The cursor position is\n unchanged (before the removed element).
\n-btree_cursors
#107540)Removes the preceding element from the BTreeMap
.
btree_cursors
#107540)Removes the preceding element from the BTreeMap
.
The element that was removed is returned. The cursor position is\n unchanged (after the removed element).
\n-From<T> for U
chooses to do.\n+Since this cursor allows mutating keys, you must ensure that the BTreeMap
\n invariants are maintained. Specifically:
btree_cursors
#107540)Advances the cursor to the next gap, returning the key and value of the\n+
btree_cursors
#107540)Advances the cursor to the next gap, returning the key and value of the\n element that it moved over.
\nIf the cursor is already at the end of the map then None
is returned\n and the cursor is not moved.
btree_cursors
#107540)Advances the cursor to the previous gap, returning the key and value of\n+
btree_cursors
#107540)Advances the cursor to the previous gap, returning the key and value of\n the element that it moved over.
\nIf the cursor is already at the start of the map then None
is returned\n and the cursor is not moved.
btree_cursors
#107540)Returns a reference to the key and value of the next element without\n+
btree_cursors
#107540)Returns a reference to the key and value of the next element without\n moving the cursor.
\nIf the cursor is at the end of the map then None
is returned.
btree_cursors
#107540)Returns a reference to the key and value of the previous element\n+
btree_cursors
#107540)Returns a reference to the key and value of the previous element\n without moving the cursor.
\nIf the cursor is at the start of the map then None
is returned.
btree_cursors
#107540)Returns a read-only cursor pointing to the same location as the\n CursorMutKey
.
The lifetime of the returned Cursor
is bound to that of the\n CursorMutKey
, which means it cannot outlive the CursorMutKey
and that the\n CursorMutKey
is frozen for the lifetime of the Cursor
.
btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n+
btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n cursor is currently pointing to.
\nAfter the insertion the cursor will be pointing at the gap before the\n newly inserted element.
\nYou must ensure that the BTreeMap
invariants are maintained.\n Specifically:
btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n+) -> Result<(), UnorderedKeyError>\ud83d\udd2cThis is a nightly-only experimental API. (btree_cursors
#107540)
Inserts a new key-value pair into the map in the gap that the\n cursor is currently pointing to.
\nAfter the insertion the cursor will be pointing at the gap before the\n newly inserted element.
\nIf the inserted key is not greater than the key before the cursor\n (if any), or if it not less than the key after the cursor (if any),\n then an UnorderedKeyError
is returned since this would\n-invalidate the Ord
invariant between the keys of the map.
Ord
invariant between the keys of the map.\n btree_cursors
#107540)Inserts a new key-value pair into the map in the gap that the\n+) -> Result<(), UnorderedKeyError>\ud83d\udd2cThis is a nightly-only experimental API. (btree_cursors
#107540)
Inserts a new key-value pair into the map in the gap that the\n cursor is currently pointing to.
\nAfter the insertion the cursor will be pointing at the gap after the\n newly inserted element.
\nIf the inserted key is not greater than the key before the cursor\n (if any), or if it not less than the key after the cursor (if any),\n then an UnorderedKeyError
is returned since this would\n-invalidate the Ord
invariant between the keys of the map.
btree_cursors
#107540)Removes the next element from the BTreeMap
.
Ord
invariant between the keys of the map.\n+btree_cursors
#107540)Removes the next element from the BTreeMap
.
The element that was removed is returned. The cursor position is\n unchanged (before the removed element).
\n-btree_cursors
#107540)Removes the preceding element from the BTreeMap
.
btree_cursors
#107540)Removes the preceding element from the BTreeMap
.
The element that was removed is returned. The cursor position is\n unchanged (after the removed element).
\n-