code
stringlengths 2.5k
150k
| kind
stringclasses 1
value |
---|---|
rust Struct std::os::unix::net::UnixDatagram Struct std::os::unix::net::UnixDatagram
=======================================
```
pub struct UnixDatagram(_);
```
Available on **Unix** only.A Unix datagram socket.
Examples
--------
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let socket = UnixDatagram::bind("/path/to/my/socket")?;
socket.send_to(b"hello world", "/path/to/other/socket")?;
let mut buf = [0; 100];
let (count, address) = socket.recv_from(&mut buf)?;
println!("socket {:?} sent {:?}", address, &buf[..count]);
Ok(())
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#70-964)### impl UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#87-96)#### pub fn bind<P: AsRef<Path>>(path: P) -> Result<UnixDatagram>
Creates a Unix datagram socket bound to the given path.
##### Examples
```
use std::os::unix::net::UnixDatagram;
let sock = match UnixDatagram::bind("/path/to/the/socket") {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't bind: {e:?}");
return
}
};
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#121-131)#### pub fn bind\_addr(socket\_addr: &SocketAddr) -> Result<UnixDatagram>
🔬This is a nightly-only experimental API. (`unix_socket_abstract` [#85410](https://github.com/rust-lang/rust/issues/85410))
Creates a Unix datagram socket bound to an address.
##### Examples
```
#![feature(unix_socket_abstract)]
use std::os::unix::net::{UnixDatagram};
fn main() -> std::io::Result<()> {
let sock1 = UnixDatagram::bind("path/to/socket")?;
let addr = sock1.local_addr()?;
let sock2 = match UnixDatagram::bind_addr(&addr) {
Ok(sock) => sock,
Err(err) => {
println!("Couldn't bind: {err:?}");
return Err(err);
}
};
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#149-152)#### pub fn unbound() -> Result<UnixDatagram>
Creates a Unix Datagram socket which is not bound to any address.
##### Examples
```
use std::os::unix::net::UnixDatagram;
let sock = match UnixDatagram::unbound() {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't unbound: {e:?}");
return
}
};
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#172-175)#### pub fn pair() -> Result<(UnixDatagram, UnixDatagram)>
Creates an unnamed pair of connected sockets.
Returns two `UnixDatagrams`s which are connected to each other.
##### Examples
```
use std::os::unix::net::UnixDatagram;
let (sock1, sock2) = match UnixDatagram::pair() {
Ok((sock1, sock2)) => (sock1, sock2),
Err(e) => {
println!("Couldn't unbound: {e:?}");
return
}
};
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#204-211)#### pub fn connect<P: AsRef<Path>>(&self, path: P) -> Result<()>
Connects the socket to the specified path address.
The [`send`](struct.unixdatagram#method.send) method may be used to send data to the specified address. [`recv`](struct.unixdatagram#method.recv) and [`recv_from`](struct.unixdatagram#method.recv_from) will only receive data from that address.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
match sock.connect("/path/to/the/socket") {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return Err(e)
}
};
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#237-246)#### pub fn connect\_addr(&self, socket\_addr: &SocketAddr) -> Result<()>
🔬This is a nightly-only experimental API. (`unix_socket_abstract` [#85410](https://github.com/rust-lang/rust/issues/85410))
Connects the socket to an address.
##### Examples
```
#![feature(unix_socket_abstract)]
use std::os::unix::net::{UnixDatagram};
fn main() -> std::io::Result<()> {
let bound = UnixDatagram::bind("/path/to/socket")?;
let addr = bound.local_addr()?;
let sock = UnixDatagram::unbound()?;
match sock.connect_addr(&addr) {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return Err(e)
}
};
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#266-268)#### pub fn try\_clone(&self) -> Result<UnixDatagram>
Creates a new independently owned handle to the underlying socket.
The returned `UnixDatagram` is a reference to the same socket that this object references. Both handles can be used to accept incoming connections and options set on one side will affect the other.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::bind("/path/to/the/socket")?;
let sock_copy = sock.try_clone().expect("try_clone failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#284-286)#### pub fn local\_addr(&self) -> Result<SocketAddr>
Returns the address of this socket.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::bind("/path/to/the/socket")?;
let addr = sock.local_addr().expect("Couldn't get local address");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#308-310)#### pub fn peer\_addr(&self) -> Result<SocketAddr>
Returns the address of this socket’s peer.
The [`connect`](struct.unixdatagram#method.connect) method will connect the socket to a peer.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.connect("/path/to/the/socket")?;
let addr = sock.peer_addr().expect("Couldn't get peer address");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#358-360)#### pub fn recv\_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
Receives data from the socket.
On success, returns the number of bytes read and the address from whence the data came.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
let mut buf = vec![0; 10];
let (size, sender) = sock.recv_from(buf.as_mut_slice())?;
println!("received {size} bytes from {sender:?}");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#379-381)#### pub fn recv(&self, buf: &mut [u8]) -> Result<usize>
Receives data from the socket.
On success, returns the number of bytes read.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::bind("/path/to/the/socket")?;
let mut buf = vec![0; 10];
sock.recv(buf.as_mut_slice()).expect("recv function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#422-431)#### pub fn recv\_vectored\_with\_ancillary\_from( &self, bufs: &mut [IoSliceMut<'\_>], ancillary: &mut SocketAncillary<'\_>) -> Result<(usize, bool, SocketAddr)>
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Receives data and ancillary data from socket.
On success, returns the number of bytes read, if the data was truncated and the address from whence the msg came.
##### Examples
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixDatagram, SocketAncillary, AncillaryData};
use std::io::IoSliceMut;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
let mut buf1 = [1; 8];
let mut buf2 = [2; 16];
let mut buf3 = [3; 8];
let mut bufs = &mut [
IoSliceMut::new(&mut buf1),
IoSliceMut::new(&mut buf2),
IoSliceMut::new(&mut buf3),
][..];
let mut fds = [0; 8];
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
let (size, _truncated, sender) = sock.recv_vectored_with_ancillary_from(bufs, &mut ancillary)?;
println!("received {size}");
for ancillary_result in ancillary.messages() {
if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
for fd in scm_rights {
println!("receive file descriptor: {fd}");
}
}
}
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#472-481)#### pub fn recv\_vectored\_with\_ancillary( &self, bufs: &mut [IoSliceMut<'\_>], ancillary: &mut SocketAncillary<'\_>) -> Result<(usize, bool)>
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Receives data and ancillary data from socket.
On success, returns the number of bytes read and if the data was truncated.
##### Examples
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixDatagram, SocketAncillary, AncillaryData};
use std::io::IoSliceMut;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
let mut buf1 = [1; 8];
let mut buf2 = [2; 16];
let mut buf3 = [3; 8];
let mut bufs = &mut [
IoSliceMut::new(&mut buf1),
IoSliceMut::new(&mut buf2),
IoSliceMut::new(&mut buf3),
][..];
let mut fds = [0; 8];
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
let (size, _truncated) = sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?;
println!("received {size}");
for ancillary_result in ancillary.messages() {
if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
for fd in scm_rights {
println!("receive file descriptor: {fd}");
}
}
}
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#499-513)#### pub fn send\_to<P: AsRef<Path>>(&self, buf: &[u8], path: P) -> Result<usize>
Sends data on the socket to the specified address.
On success, returns the number of bytes written.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.send_to(b"omelette au fromage", "/some/sock").expect("send_to function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#537-549)#### pub fn send\_to\_addr(&self, buf: &[u8], socket\_addr: &SocketAddr) -> Result<usize>
🔬This is a nightly-only experimental API. (`unix_socket_abstract` [#85410](https://github.com/rust-lang/rust/issues/85410))
Sends data on the socket to the specified [SocketAddr](struct.socketaddr).
On success, returns the number of bytes written.
##### Examples
```
#![feature(unix_socket_abstract)]
use std::os::unix::net::{UnixDatagram};
fn main() -> std::io::Result<()> {
let bound = UnixDatagram::bind("/path/to/socket")?;
let addr = bound.local_addr()?;
let sock = UnixDatagram::unbound()?;
sock.send_to_addr(b"bacon egg and cheese", &addr).expect("send_to_addr function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#571-573)#### pub fn send(&self, buf: &[u8]) -> Result<usize>
Sends data on the socket to the socket’s peer.
The peer address may be set by the `connect` method, and this method will return an error if the socket has not already been connected.
On success, returns the number of bytes written.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.connect("/some/sock").expect("Couldn't connect");
sock.send(b"omelette au fromage").expect("send_to function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#608-615)#### pub fn send\_vectored\_with\_ancillary\_to<P: AsRef<Path>>( &self, bufs: &[IoSlice<'\_>], ancillary: &mut SocketAncillary<'\_>, path: P) -> Result<usize>
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Sends data and ancillary data on the socket to the specified address.
On success, returns the number of bytes written.
##### Examples
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixDatagram, SocketAncillary};
use std::io::IoSlice;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
let buf1 = [1; 8];
let buf2 = [2; 16];
let buf3 = [3; 8];
let bufs = &[
IoSlice::new(&buf1),
IoSlice::new(&buf2),
IoSlice::new(&buf3),
][..];
let fds = [0, 1, 2];
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
ancillary.add_fds(&fds[..]);
sock.send_vectored_with_ancillary_to(bufs, &mut ancillary, "/some/sock")
.expect("send_vectored_with_ancillary_to function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#650-656)#### pub fn send\_vectored\_with\_ancillary( &self, bufs: &[IoSlice<'\_>], ancillary: &mut SocketAncillary<'\_>) -> Result<usize>
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Sends data and ancillary data on the socket.
On success, returns the number of bytes written.
##### Examples
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixDatagram, SocketAncillary};
use std::io::IoSlice;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
let buf1 = [1; 8];
let buf2 = [2; 16];
let buf3 = [3; 8];
let bufs = &[
IoSlice::new(&buf1),
IoSlice::new(&buf2),
IoSlice::new(&buf3),
][..];
let fds = [0, 1, 2];
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
ancillary.add_fds(&fds[..]);
sock.send_vectored_with_ancillary(bufs, &mut ancillary)
.expect("send_vectored_with_ancillary function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#698-700)#### pub fn set\_read\_timeout(&self, timeout: Option<Duration>) -> Result<()>
Sets the read timeout for the socket.
If the provided value is [`None`](../../../option/enum.option#variant.None "None"), then [`recv`](struct.unixdatagram#method.recv) and [`recv_from`](struct.unixdatagram#method.recv_from) calls will block indefinitely. An [`Err`](../../../result/enum.result#variant.Err "Err") is returned if the zero [`Duration`](../../../time/struct.duration "Duration") is passed to this method.
##### Examples
```
use std::os::unix::net::UnixDatagram;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.set_read_timeout(Some(Duration::new(1, 0)))
.expect("set_read_timeout function failed");
Ok(())
}
```
An [`Err`](../../../result/enum.result#variant.Err "Err") is returned if the zero [`Duration`](../../../time/struct.duration "Duration") is passed to this method:
```
use std::io;
use std::os::unix::net::UnixDatagram;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixDatagram::unbound()?;
let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
let err = result.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#742-744)#### pub fn set\_write\_timeout(&self, timeout: Option<Duration>) -> Result<()>
Sets the write timeout for the socket.
If the provided value is [`None`](../../../option/enum.option#variant.None "None"), then [`send`](struct.unixdatagram#method.send) and [`send_to`](struct.unixdatagram#method.send_to) calls will block indefinitely. An [`Err`](../../../result/enum.result#variant.Err "Err") is returned if the zero [`Duration`](../../../time/struct.duration "Duration") is passed to this method.
##### Examples
```
use std::os::unix::net::UnixDatagram;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.set_write_timeout(Some(Duration::new(1, 0)))
.expect("set_write_timeout function failed");
Ok(())
}
```
An [`Err`](../../../result/enum.result#variant.Err "Err") is returned if the zero [`Duration`](../../../time/struct.duration "Duration") is passed to this method:
```
use std::io;
use std::os::unix::net::UnixDatagram;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixDatagram::unbound()?;
let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
let err = result.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#763-765)#### pub fn read\_timeout(&self) -> Result<Option<Duration>>
Returns the read timeout of this socket.
##### Examples
```
use std::os::unix::net::UnixDatagram;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.set_read_timeout(Some(Duration::new(1, 0)))
.expect("set_read_timeout function failed");
assert_eq!(sock.read_timeout()?, Some(Duration::new(1, 0)));
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#784-786)#### pub fn write\_timeout(&self) -> Result<Option<Duration>>
Returns the write timeout of this socket.
##### Examples
```
use std::os::unix::net::UnixDatagram;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.set_write_timeout(Some(Duration::new(1, 0)))
.expect("set_write_timeout function failed");
assert_eq!(sock.write_timeout()?, Some(Duration::new(1, 0)));
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#802-804)#### pub fn set\_nonblocking(&self, nonblocking: bool) -> Result<()>
Moves the socket into or out of nonblocking mode.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.set_nonblocking(true).expect("set_nonblocking function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#825-827)#### pub fn set\_passcred(&self, passcred: bool) -> Result<()>
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Moves the socket to pass unix credentials as control message in [`SocketAncillary`](struct.socketancillary "SocketAncillary").
Set the socket option `SO_PASSCRED`.
##### Examples
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.set_passcred(true).expect("set_passcred function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#837-839)#### pub fn passcred(&self) -> Result<bool>
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Get the current value of the socket for passing unix credentials in [`SocketAncillary`](struct.socketancillary "SocketAncillary"). This value can be change by [`set_passcred`](struct.unixdatagram#method.set_passcred).
Get the socket option `SO_PASSCRED`.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#862-864)#### pub fn set\_mark(&self, mark: u32) -> Result<()>
🔬This is a nightly-only experimental API. (`unix_set_mark` [#96467](https://github.com/rust-lang/rust/issues/96467))
Set the id of the socket for network filtering purpose
```
#![feature(unix_set_mark)]
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.set_mark(32)?;
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#882-884)#### pub fn take\_error(&self) -> Result<Option<Error>>
Returns the value of the `SO_ERROR` option.
##### Examples
```
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
if let Ok(Some(err)) = sock.take_error() {
println!("Got error: {err:?}");
}
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#903-905)#### pub fn shutdown(&self, how: Shutdown) -> Result<()>
Shut down the read, write, or both halves of this connection.
This function will cause all pending and future I/O calls on the specified portions to immediately return with an appropriate value (see the documentation of [`Shutdown`](../../../net/enum.shutdown "Shutdown")).
```
use std::os::unix::net::UnixDatagram;
use std::net::Shutdown;
fn main() -> std::io::Result<()> {
let sock = UnixDatagram::unbound()?;
sock.shutdown(Shutdown::Both).expect("shutdown function failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#929-931)#### pub fn peek(&self, buf: &mut [u8]) -> Result<usize>
🔬This is a nightly-only experimental API. (`unix_socket_peek` [#76923](https://github.com/rust-lang/rust/issues/76923))
Receives data on the socket from the remote address to which it is connected, without removing that data from the queue. On success, returns the number of bytes peeked.
Successive calls return the same data. This is accomplished by passing `MSG_PEEK` as a flag to the underlying `recv` system call.
##### Examples
```
#![feature(unix_socket_peek)]
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let socket = UnixDatagram::bind("/tmp/sock")?;
let mut buf = [0; 10];
let len = socket.peek(&mut buf).expect("peek failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#961-963)#### pub fn peek\_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
🔬This is a nightly-only experimental API. (`unix_socket_peek` [#76923](https://github.com/rust-lang/rust/issues/76923))
Receives a single datagram message on the socket, without removing it from the queue. On success, returns the number of bytes read and the origin.
The function must be called with valid byte array `buf` of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.
Successive calls return the same data. This is accomplished by passing `MSG_PEEK` as a flag to the underlying `recvfrom` system call.
Do not use this function to implement busy waiting, instead use `libc::poll` to synchronize IO events on one or more sockets.
##### Examples
```
#![feature(unix_socket_peek)]
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let socket = UnixDatagram::bind("/tmp/sock")?;
let mut buf = [0; 10];
let (len, addr) = socket.peek_from(&mut buf).expect("peek failed");
Ok(())
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#991-996)1.63.0 · ### impl AsFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#993-995)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Borrows the file descriptor. [Read more](../io/trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#967-972)### impl AsRawFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#969-971)#### fn as\_raw\_fd(&self) -> RawFd
Extracts the raw file descriptor. [Read more](../io/trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#56-68)### impl Debug for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#57-67)#### fn fmt(&self, fmt: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1007-1012)1.63.0 · ### impl From<OwnedFd> for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1009-1011)#### fn from(owned: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#999-1004)1.63.0 · ### impl From<UnixDatagram> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1001-1003)#### fn from(unix\_datagram: UnixDatagram) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#975-980)### impl FromRawFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#977-979)#### unsafe fn from\_raw\_fd(fd: RawFd) -> UnixDatagram
Constructs a new instance of `Self` from the given raw file descriptor. [Read more](../io/trait.fromrawfd#tymethod.from_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#983-988)### impl IntoRawFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#985-987)#### fn into\_raw\_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor. [Read more](../io/trait.intorawfd#tymethod.into_raw_fd)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for UnixDatagram
### impl Send for UnixDatagram
### impl Sync for UnixDatagram
### impl Unpin for UnixDatagram
### impl UnwindSafe for UnixDatagram
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::os::unix::net::ScmRights Struct std::os::unix::net::ScmRights
====================================
```
pub struct ScmRights<'a>(_);
```
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Available on **(Android or Linux) and Unix** only.This control message contains file descriptors.
The level is equal to `SOL_SOCKET` and the type is equal to `SCM_RIGHTS`.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#311-317)### impl<'a> Iterator for ScmRights<'a>
#### type Item = i32
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#314-316)#### fn next(&mut self) -> Option<RawFd>
Advances the iterator and returns the next value. [Read more](../../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#215)1.0.0 · #### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Notable traits for [Filter](../../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../../iter/struct.peekable#method.peek) and [`peek_mut`](../../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Notable traits for [SkipWhile](../../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Notable traits for [TakeWhile](../../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../../primitive.reference) St, Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../../option/enum.option#variant.None "None"). [Read more](../../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../../default/trait.default "trait std::default::Default") + [Extend](../../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = [()](../../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../../ops/trait.try "trait std::ops::Try")>::[Residual](../../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../../ops/trait.residual "trait std::ops::Residual")<[Option](../../../option/enum.option "enum std::option::Option")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../../primitive.bool)>, <R as [Try](../../../ops/trait.try "trait std::ops::Try")>::[Residual](../../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../../ops/trait.residual "trait std::ops::Residual")<[Option](../../../option/enum.option "enum std::option::Option")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../../default/trait.default "trait std::default::Default") + [Extend](../../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../../default/trait.default "trait std::default::Default") + [Extend](../../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../../primitive.reference) T>,
Notable traits for [Copied](../../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../../primitive.reference) T>,
Notable traits for [Cloned](../../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") with those of another. [Read more](../../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<[Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<[Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../../iter/trait.iterator#method.is_sorted_by_key)
Auto Trait Implementations
--------------------------
### impl<'a> RefUnwindSafe for ScmRights<'a>
### impl<'a> Send for ScmRights<'a>
### impl<'a> Sync for ScmRights<'a>
### impl<'a> Unpin for ScmRights<'a>
### impl<'a> UnwindSafe for ScmRights<'a>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::os::unix::net::SocketAncillary Struct std::os::unix::net::SocketAncillary
==========================================
```
pub struct SocketAncillary<'a> { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Available on **(Android or Linux) and Unix** only.A Unix socket Ancillary data struct.
Example
-------
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixStream, SocketAncillary, AncillaryData};
use std::io::IoSliceMut;
fn main() -> std::io::Result<()> {
let sock = UnixStream::connect("/tmp/sock")?;
let mut fds = [0; 8];
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
let mut buf = [1; 8];
let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..];
sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?;
for ancillary_result in ancillary.messages() {
if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
for fd in scm_rights {
println!("receive file descriptor: {fd}");
}
}
}
Ok(())
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#491-674)### impl<'a> SocketAncillary<'a>
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#504-506)#### pub fn new(buffer: &'a mut [u8]) -> Self
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Create an ancillary data with the given buffer.
##### Example
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::SocketAncillary;
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#511-513)#### pub fn capacity(&self) -> usize
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Returns the capacity of the buffer.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#518-520)#### pub fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Returns `true` if the ancillary data is empty.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#525-527)#### pub fn len(&self) -> usize
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Returns the number of used bytes.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#531-533)#### pub fn messages(&self) -> Messages<'\_>
Notable traits for [Messages](struct.messages "struct std::os::unix::net::Messages")<'a>
```
impl<'a> Iterator for Messages<'a>
type Item = Result<AncillaryData<'a>, AncillaryError>;
```
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Returns the iterator of the control messages.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#560-562)#### pub fn truncated(&self) -> bool
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Is `true` if during a recv operation the ancillary was truncated.
##### Example
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixStream, SocketAncillary};
use std::io::IoSliceMut;
fn main() -> std::io::Result<()> {
let sock = UnixStream::connect("/tmp/sock")?;
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
let mut buf = [1; 8];
let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..];
sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?;
println!("Is truncated: {}", ancillary.truncated());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#593-602)#### pub fn add\_fds(&mut self, fds: &[RawFd]) -> bool
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Add file descriptors to the ancillary data.
The function returns `true` if there was enough space in the buffer. If there was not enough space then no file descriptors was appended. Technically, that means this operation adds a control message with the level `SOL_SOCKET` and type `SCM_RIGHTS`.
##### Example
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixStream, SocketAncillary};
use std::os::unix::io::AsRawFd;
use std::io::IoSlice;
fn main() -> std::io::Result<()> {
let sock = UnixStream::connect("/tmp/sock")?;
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
ancillary.add_fds(&[sock.as_raw_fd()][..]);
let buf = [1; 8];
let mut bufs = &mut [IoSlice::new(&buf[..])][..];
sock.send_vectored_with_ancillary(bufs, &mut ancillary)?;
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#613-625)#### pub fn add\_creds(&mut self, creds: &[SocketCred]) -> bool
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Add credentials to the ancillary data.
The function returns `true` if there was enough space in the buffer. If there was not enough space then no credentials was appended. Technically, that means this operation adds a control message with the level `SOL_SOCKET` and type `SCM_CREDENTIALS` or `SCM_CREDS`.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#670-673)#### pub fn clear(&mut self)
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Clears the ancillary data, removing all values.
##### Example
```
#![feature(unix_socket_ancillary_data)]
use std::os::unix::net::{UnixStream, SocketAncillary, AncillaryData};
use std::io::IoSliceMut;
fn main() -> std::io::Result<()> {
let sock = UnixStream::connect("/tmp/sock")?;
let mut fds1 = [0; 8];
let mut fds2 = [0; 8];
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
let mut buf = [1; 8];
let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..];
sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?;
for ancillary_result in ancillary.messages() {
if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
for fd in scm_rights {
println!("receive file descriptor: {fd}");
}
}
}
ancillary.clear();
sock.recv_vectored_with_ancillary(bufs, &mut ancillary)?;
for ancillary_result in ancillary.messages() {
if let AncillaryData::ScmRights(scm_rights) = ancillary_result.unwrap() {
for fd in scm_rights {
println!("receive file descriptor: {fd}");
}
}
}
Ok(())
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#484)### impl<'a> Debug for SocketAncillary<'a>
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#484)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a> RefUnwindSafe for SocketAncillary<'a>
### impl<'a> Send for SocketAncillary<'a>
### impl<'a> Sync for SocketAncillary<'a>
### impl<'a> Unpin for SocketAncillary<'a>
### impl<'a> !UnwindSafe for SocketAncillary<'a>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Enum std::os::unix::net::AncillaryError Enum std::os::unix::net::AncillaryError
=======================================
```
#[non_exhaustive]
pub enum AncillaryError {
Unknown {
cmsg_level: i32,
cmsg_type: i32,
},
}
```
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Available on **(Android or Linux) and Unix** only.The error type which is returned from parsing the type a control message.
Variants (Non-exhaustive)
-------------------------
This enum is marked as non-exhaustiveNon-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.### `Unknown`
#### Fields
`cmsg_level: [i32](../../../primitive.i32)`
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
`cmsg_type: [i32](../../../primitive.i32)`
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#346)### impl Debug for AncillaryError
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#346)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for AncillaryError
### impl Send for AncillaryError
### impl Sync for AncillaryError
### impl Unpin for AncillaryError
### impl UnwindSafe for AncillaryError
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Enum std::os::unix::net::AncillaryData Enum std::os::unix::net::AncillaryData
======================================
```
pub enum AncillaryData<'a> {
ScmRights(ScmRights<'a>),
ScmCredentials(ScmCredentials<'a>),
}
```
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Available on **(Android or Linux) and Unix** only.This enum represent one control message of variable type.
Variants
--------
### `ScmRights([ScmRights](struct.scmrights "struct std::os::unix::net::ScmRights")<'a>)`
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
### `ScmCredentials([ScmCredentials](struct.scmcredentials "struct std::os::unix::net::ScmCredentials")<'a>)`
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Auto Trait Implementations
--------------------------
### impl<'a> RefUnwindSafe for AncillaryData<'a>
### impl<'a> Send for AncillaryData<'a>
### impl<'a> Sync for AncillaryData<'a>
### impl<'a> Unpin for AncillaryData<'a>
### impl<'a> UnwindSafe for AncillaryData<'a>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::os::unix::net::UnixListener Struct std::os::unix::net::UnixListener
=======================================
```
pub struct UnixListener(_);
```
Available on **Unix** only.A structure representing a Unix domain socket server.
Examples
--------
```
use std::thread;
use std::os::unix::net::{UnixStream, UnixListener};
fn handle_client(stream: UnixStream) {
// ...
}
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
// accept connections and process them, spawning a new thread for each one
for stream in listener.incoming() {
match stream {
Ok(stream) => {
/* connection succeeded */
thread::spawn(|| handle_client(stream));
}
Err(err) => {
/* connection failed */
break;
}
}
}
Ok(())
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#55-283)### impl UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#72-84)#### pub fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener>
Creates a new `UnixListener` bound to the specified socket.
##### Examples
```
use std::os::unix::net::UnixListener;
let listener = match UnixListener::bind("/path/to/the/socket") {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return
}
};
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#111-126)#### pub fn bind\_addr(socket\_addr: &SocketAddr) -> Result<UnixListener>
🔬This is a nightly-only experimental API. (`unix_socket_abstract` [#85410](https://github.com/rust-lang/rust/issues/85410))
Creates a new `UnixListener` bound to the specified [`socket address`](struct.socketaddr).
##### Examples
```
#![feature(unix_socket_abstract)]
use std::os::unix::net::{UnixListener};
fn main() -> std::io::Result<()> {
let listener1 = UnixListener::bind("path/to/socket")?;
let addr = listener1.local_addr()?;
let listener2 = match UnixListener::bind_addr(&addr) {
Ok(sock) => sock,
Err(err) => {
println!("Couldn't bind: {err:?}");
return Err(err);
}
};
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#152-158)#### pub fn accept(&self) -> Result<(UnixStream, SocketAddr)>
Accepts a new incoming connection to this listener.
This function will block the calling thread until a new Unix connection is established. When established, the corresponding [`UnixStream`](struct.unixstream) and the remote peer’s address will be returned.
##### Examples
```
use std::os::unix::net::UnixListener;
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
match listener.accept() {
Ok((socket, addr)) => println!("Got a client: {addr:?}"),
Err(e) => println!("accept function failed: {e:?}"),
}
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#178-180)#### pub fn try\_clone(&self) -> Result<UnixListener>
Creates a new independently owned handle to the underlying socket.
The returned `UnixListener` is a reference to the same socket that this object references. Both handles can be used to accept incoming connections and options set on one listener will affect the other.
##### Examples
```
use std::os::unix::net::UnixListener;
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
let listener_copy = listener.try_clone().expect("try_clone failed");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#196-198)#### pub fn local\_addr(&self) -> Result<SocketAddr>
Returns the local socket address of this listener.
##### Examples
```
use std::os::unix::net::UnixListener;
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
let addr = listener.local_addr().expect("Couldn't get local address");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#220-222)#### pub fn set\_nonblocking(&self, nonblocking: bool) -> Result<()>
Moves the socket into or out of nonblocking mode.
This will result in the `accept` operation becoming nonblocking, i.e., immediately returning from their calls. If the IO operation is successful, `Ok` is returned and no further action is required. If the IO operation could not be completed and needs to be retried, an error with kind [`io::ErrorKind::WouldBlock`](../../../io/enum.errorkind#variant.WouldBlock "io::ErrorKind::WouldBlock") is returned.
##### Examples
```
use std::os::unix::net::UnixListener;
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
listener.set_nonblocking(true).expect("Couldn't set non blocking");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#244-246)#### pub fn take\_error(&self) -> Result<Option<Error>>
Returns the value of the `SO_ERROR` option.
##### Examples
```
use std::os::unix::net::UnixListener;
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/tmp/sock")?;
if let Ok(Some(err)) = listener.take_error() {
println!("Got error: {err:?}");
}
Ok(())
}
```
##### Platform specific
On Redox this always returns `None`.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#280-282)#### pub fn incoming(&self) -> Incoming<'\_>
Notable traits for [Incoming](struct.incoming "struct std::os::unix::net::Incoming")<'a>
```
impl<'a> Iterator for Incoming<'a>
type Item = Result<UnixStream>;
```
Returns an iterator over incoming connections.
The iterator will never return [`None`](../../../option/enum.option#variant.None "None") and will also not yield the peer’s [`SocketAddr`](struct.socketaddr "SocketAddr") structure.
##### Examples
```
use std::thread;
use std::os::unix::net::{UnixStream, UnixListener};
fn handle_client(stream: UnixStream) {
// ...
}
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
for stream in listener.incoming() {
match stream {
Ok(stream) => {
thread::spawn(|| handle_client(stream));
}
Err(err) => {
break;
}
}
}
Ok(())
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#310-315)1.63.0 · ### impl AsFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#312-314)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Borrows the file descriptor. [Read more](../io/trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#286-291)### impl AsRawFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#288-290)#### fn as\_raw\_fd(&self) -> RawFd
Extracts the raw file descriptor. [Read more](../io/trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#44-53)### impl Debug for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#45-52)#### fn fmt(&self, fmt: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#318-323)1.63.0 · ### impl From<OwnedFd> for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#320-322)#### fn from(fd: OwnedFd) -> UnixListener
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#326-331)1.63.0 · ### impl From<UnixListener> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#328-330)#### fn from(listener: UnixListener) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#294-299)### impl FromRawFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#296-298)#### unsafe fn from\_raw\_fd(fd: RawFd) -> UnixListener
Constructs a new instance of `Self` from the given raw file descriptor. [Read more](../io/trait.fromrawfd#tymethod.from_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#334-341)### impl<'a> IntoIterator for &'a UnixListener
#### type Item = Result<UnixStream, Error>
The type of the elements being iterated over.
#### type IntoIter = Incoming<'a>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#338-340)#### fn into\_iter(self) -> Incoming<'a>
Notable traits for [Incoming](struct.incoming "struct std::os::unix::net::Incoming")<'a>
```
impl<'a> Iterator for Incoming<'a>
type Item = Result<UnixStream>;
```
Creates an iterator from a value. [Read more](../../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#302-307)### impl IntoRawFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#304-306)#### fn into\_raw\_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor. [Read more](../io/trait.intorawfd#tymethod.into_raw_fd)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for UnixListener
### impl Send for UnixListener
### impl Sync for UnixListener
### impl Unpin for UnixListener
### impl UnwindSafe for UnixListener
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::os::unix::net::SocketCred Struct std::os::unix::net::SocketCred
=====================================
```
pub struct SocketCred(_);
```
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Available on **(Android or Linux) and Unix** only.Unix credential.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#199-247)### impl SocketCred
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#205-207)#### pub fn new() -> SocketCred
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Create a Unix credential struct.
PID, UID and GID is set to 0.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#211-213)#### pub fn set\_pid(&mut self, pid: pid\_t)
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Set the PID.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#218-220)#### pub fn get\_pid(&self) -> pid\_t
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Get the current PID.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#224-226)#### pub fn set\_uid(&mut self, uid: uid\_t)
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Set the UID.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#231-233)#### pub fn get\_uid(&self) -> uid\_t
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Get the current UID.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#237-239)#### pub fn set\_gid(&mut self, gid: gid\_t)
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Set the GID.
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#244-246)#### pub fn get\_gid(&self) -> gid\_t
🔬This is a nightly-only experimental API. (`unix_socket_ancillary_data` [#76915](https://github.com/rust-lang/rust/issues/76915))
Get the current GID.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#189)### impl Clone for SocketCred
[source](https://doc.rust-lang.org/src/std/os/unix/net/ancillary.rs.html#189)#### fn clone(&self) -> SocketCred
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for SocketCred
### impl Send for SocketCred
### impl Sync for SocketCred
### impl Unpin for SocketCred
### impl UnwindSafe for SocketCred
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Module std::os::unix::io Module std::os::unix::io
========================
Available on **Unix** only.Unix-specific extensions to general I/O primitives.
Just like raw pointers, raw file descriptors point to resources with dynamic lifetimes, and they can dangle if they outlive their resources or be forged if they’re created from invalid values.
This module provides three types for representing file descriptors, with different ownership properties: raw, borrowed, and owned, which are analogous to types used for representing pointers:
| Type | Analogous to |
| --- | --- |
| [`RawFd`](type.rawfd "RawFd") | `*const _` |
| [`BorrowedFd<'a>`](struct.borrowedfd) | `&'a _` |
| [`OwnedFd`](struct.ownedfd "OwnedFd") | `Box<_>` |
Like raw pointers, `RawFd` values are primitive values. And in new code, they should be considered unsafe to do I/O on (analogous to dereferencing them). Rust did not always provide this guidance, so existing code in the Rust ecosystem often doesn’t mark `RawFd` usage as unsafe. Once the `io_safety` feature is stable, libraries will be encouraged to migrate, either by adding `unsafe` to APIs that dereference `RawFd` values, or by using to `BorrowedFd` or `OwnedFd` instead.
Like references, `BorrowedFd` values are tied to a lifetime, to ensure that they don’t outlive the resource they point to. These are safe to use. `BorrowedFd` values may be used in APIs which provide safe access to any system call except for:
* `close`, because that would end the dynamic lifetime of the resource without ending the lifetime of the file descriptor.
* `dup2`/`dup3`, in the second argument, because this argument is closed and assigned a new resource, which may break the assumptions other code using that file descriptor.
`BorrowedFd` values may be used in APIs which provide safe access to `dup` system calls, so types implementing `AsFd` or `From<OwnedFd>` should not assume they always have exclusive access to the underlying file description.
`BorrowedFd` values may also be used with `mmap`, since `mmap` uses the provided file descriptor in a manner similar to `dup` and does not require the `BorrowedFd` passed to it to live for the lifetime of the resulting mapping. That said, `mmap` is unsafe for other reasons: it operates on raw pointers, and it can have undefined behavior if the underlying storage is mutated. Mutations may come from other processes, or from the same process if the API provides `BorrowedFd` access, since as mentioned earlier, `BorrowedFd` values may be used in APIs which provide safe access to any system call. Consequently, code using `mmap` and presenting a safe API must take full responsibility for ensuring that safe Rust code cannot evoke undefined behavior through it.
Like boxes, `OwnedFd` values conceptually own the resource they point to, and free (close) it when they are dropped.
###
`/proc/self/mem` and similar OS features
Some platforms have special files, such as `/proc/self/mem`, which provide read and write access to the process’s memory. Such reads and writes happen outside the control of the Rust compiler, so they do not uphold Rust’s memory safety guarantees.
This does not mean that all APIs that might allow `/proc/self/mem` to be opened and read from or written must be `unsafe`. Rust’s safety guarantees only cover what the program itself can do, and not what entities outside the program can do to it. `/proc/self/mem` is considered to be such an external entity, along with debugging interfaces, and people with physical access to the hardware. This is true even in cases where the program is controlling the external entity.
If you desire to comprehensively prevent programs from reaching out and causing external entities to reach back in and violate memory safety, it’s necessary to use *sandboxing*, which is outside the scope of `std`.
Structs
-------
[BorrowedFd](struct.borrowedfd "std::os::unix::io::BorrowedFd struct")
A borrowed file descriptor.
[OwnedFd](struct.ownedfd "std::os::unix::io::OwnedFd struct")
An owned file descriptor.
Traits
------
[AsFd](trait.asfd "std::os::unix::io::AsFd trait")
A trait to borrow the file descriptor from an underlying object.
[AsRawFd](trait.asrawfd "std::os::unix::io::AsRawFd trait")
A trait to extract the raw file descriptor from an underlying object.
[FromRawFd](trait.fromrawfd "std::os::unix::io::FromRawFd trait")
A trait to express the ability to construct an object from a raw file descriptor.
[IntoRawFd](trait.intorawfd "std::os::unix::io::IntoRawFd trait")
A trait to express the ability to consume an object and acquire ownership of its raw file descriptor.
Type Definitions
----------------
[RawFd](type.rawfd "std::os::unix::io::RawFd type")
Raw file descriptors.
rust Type Definition std::os::unix::io::RawFd Type Definition std::os::unix::io::RawFd
========================================
```
pub type RawFd = c_int;
```
Available on **Unix** only.Raw file descriptors.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#139-144)1.48.0 · ### impl AsRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#141-143)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#153-158)1.48.0 · ### impl FromRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#155-157)#### unsafe fn from\_raw\_fd(fd: RawFd) -> RawFd
Available on **Unix** only.Constructs a new instance of `Self` from the given raw file descriptor. [Read more](trait.fromrawfd#tymethod.from_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#146-151)1.48.0 · ### impl IntoRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#148-150)#### fn into\_raw\_fd(self) -> RawFd
Available on **Unix** only.Consumes this object, returning the raw underlying file descriptor. [Read more](trait.intorawfd#tymethod.into_raw_fd)
rust Struct std::os::unix::io::BorrowedFd Struct std::os::unix::io::BorrowedFd
====================================
```
#[repr(transparent)]pub struct BorrowedFd<'fd> { /* private fields */ }
```
Available on **Unix** only.A borrowed file descriptor.
This has a lifetime parameter to tie it to the lifetime of something that owns the file descriptor.
This uses `repr(transparent)` and has the representation of a host file descriptor, so it can be used in FFI in places where a file descriptor is passed as an argument, it is not captured or consumed, and it never has the value `-1`.
This type’s `.to_owned()` implementation returns another `BorrowedFd` rather than an `OwnedFd`. It just makes a trivial copy of the raw file descriptor, which is then borrowed under the same lifetime.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#62-77)### impl BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#72-76)const: 1.63.0 · #### pub const unsafe fn borrow\_raw(fd: RawFd) -> Self
Return a `BorrowedFd` holding the given raw file descriptor.
##### Safety
The resource pointed to by `fd` must remain open for the duration of the returned `BorrowedFd`, and it must not have the value `-1`.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#88-122)### impl BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#93-110)#### pub fn try\_clone\_to\_owned(&self) -> Result<OwnedFd>
Creates a new `OwnedFd` instance that shares the same underlying file description as the existing `BorrowedFd` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#240-245)### impl AsFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#242-244)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Available on **Unix** only.Borrows the file descriptor. [Read more](trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#125-130)### impl AsRawFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#127-129)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#28)### impl<'fd> Clone for BorrowedFd<'fd>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#28)#### fn clone(&self) -> BorrowedFd<'fd>
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#182-186)### impl Debug for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#183-185)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#28)### impl<'fd> Copy for BorrowedFd<'fd>
Auto Trait Implementations
--------------------------
### impl<'fd> RefUnwindSafe for BorrowedFd<'fd>
### impl<'fd> Send for BorrowedFd<'fd>
### impl<'fd> Sync for BorrowedFd<'fd>
### impl<'fd> Unpin for BorrowedFd<'fd>
### impl<'fd> UnwindSafe for BorrowedFd<'fd>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::os::unix::io::OwnedFd Struct std::os::unix::io::OwnedFd
=================================
```
#[repr(transparent)]pub struct OwnedFd { /* private fields */ }
```
Available on **Unix** only.An owned file descriptor.
This closes the file descriptor on drop.
This uses `repr(transparent)` and has the representation of a host file descriptor, so it can be used in FFI in places where a file descriptor is passed as a consumed argument or returned as an owned value, and it never has the value `-1`.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#79-86)### impl OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#83-85)#### pub fn try\_clone(&self) -> Result<Self>
Creates a new `OwnedFd` instance that shares the same underlying file description as the existing `OwnedFd` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#248-256)### impl AsFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#250-255)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Available on **Unix** only.Borrows the file descriptor. [Read more](trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#133-138)### impl AsRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#135-137)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#189-193)### impl Debug for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#190-192)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#167-179)### impl Drop for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#169-178)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#454-459)### impl From<ChildStderr> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#456-458)#### fn from(child\_stderr: ChildStderr) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#422-427)### impl From<ChildStdin> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#424-426)#### fn from(child\_stdin: ChildStdin) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#438-443)### impl From<ChildStdout> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#440-442)#### fn from(child\_stdout: ChildStdout) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#267-272)### impl From<File> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#269-271)#### fn from(file: File) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#275-280)### impl From<OwnedFd> for File
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#277-279)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#96-100)### impl From<OwnedFd> for PidFd
Available on **Linux** only.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#97-99)#### fn from(fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#356-363)### impl From<OwnedFd> for Stdio
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#358-362)#### fn from(fd: OwnedFd) -> Stdio
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#325-332)### impl From<OwnedFd> for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#327-331)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#299-306)### impl From<OwnedFd> for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#301-305)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#351-358)### impl From<OwnedFd> for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#353-357)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1007-1012)### impl From<OwnedFd> for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1009-1011)#### fn from(owned: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#318-323)### impl From<OwnedFd> for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#320-322)#### fn from(fd: OwnedFd) -> UnixListener
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#731-736)### impl From<OwnedFd> for UnixStream
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#733-735)#### fn from(owned: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#102-106)### impl From<PidFd> for OwnedFd
Available on **Linux** only.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#103-105)#### fn from(pid\_fd: PidFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#317-322)### impl From<TcpListener> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#319-321)#### fn from(tcp\_listener: TcpListener) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#291-296)### impl From<TcpStream> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#293-295)#### fn from(tcp\_stream: TcpStream) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#343-348)### impl From<UdpSocket> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#345-347)#### fn from(udp\_socket: UdpSocket) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#999-1004)### impl From<UnixDatagram> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1001-1003)#### fn from(unix\_datagram: UnixDatagram) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#326-331)### impl From<UnixListener> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#328-330)#### fn from(listener: UnixListener) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#723-728)### impl From<UnixStream> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#725-727)#### fn from(unix\_stream: UnixStream) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#151-164)### impl FromRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#159-163)#### unsafe fn from\_raw\_fd(fd: RawFd) -> Self
Available on **Unix** only.
Constructs a new instance of `Self` from the given raw file descriptor.
##### Safety
The resource pointed to by `fd` must be open and suitable for assuming ownership. The resource must not require any cleanup other than `close`.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#141-148)### impl IntoRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#143-147)#### fn into\_raw\_fd(self) -> RawFd
Available on **Unix** only.Consumes this object, returning the raw underlying file descriptor. [Read more](trait.intorawfd#tymethod.into_raw_fd)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for OwnedFd
### impl Send for OwnedFd
### impl Sync for OwnedFd
### impl Unpin for OwnedFd
### impl UnwindSafe for OwnedFd
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Trait std::os::unix::io::AsFd Trait std::os::unix::io::AsFd
=============================
```
pub trait AsFd {
fn as_fd(&self) -> BorrowedFd<'_>;
}
```
Available on **Unix** only.A trait to borrow the file descriptor from an underlying object.
This is only available on unix platforms and must be imported in order to call the method. Windows platforms have a corresponding `AsHandle` and `AsSocket` set of traits.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#220)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Borrows the file descriptor.
##### Example
```
use std::fs::File;
let mut f = File::open("foo.txt")?;
let borrowed_fd: BorrowedFd<'_> = f.as_fd();
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#259-264)### impl AsFd for File
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#128-133)### impl AsFd for Stderr
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#96-101)### impl AsFd for Stdin
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#112-117)### impl AsFd for Stdout
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#309-314)### impl AsFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#283-288)### impl AsFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#335-340)### impl AsFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#446-451)### impl AsFd for ChildStderr
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#414-419)### impl AsFd for ChildStdin
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#430-435)### impl AsFd for ChildStdout
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#90-94)### impl AsFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#991-996)### impl AsFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#310-315)### impl AsFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#715-720)### impl AsFd for UnixStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#240-245)### impl AsFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#248-256)### impl AsFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#136-141)### impl<'a> AsFd for StderrLock<'a>
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#104-109)### impl<'a> AsFd for StdinLock<'a>
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#120-125)### impl<'a> AsFd for StdoutLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#224-229)### impl<T: AsFd> AsFd for &T
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#232-237)### impl<T: AsFd> AsFd for &mut T
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#384-389)1.64.0 · ### impl<T: AsFd> AsFd for Box<T>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#376-381)1.64.0 · ### impl<T: AsFd> AsFd for Arc<T>
This impl allows implementing traits that require `AsFd` on Arc.
```
use std::net::UdpSocket;
use std::sync::Arc;
trait MyTrait: AsFd {}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}
```
rust Trait std::os::unix::io::IntoRawFd Trait std::os::unix::io::IntoRawFd
==================================
```
pub trait IntoRawFd {
fn into_raw_fd(self) -> RawFd;
}
```
Available on **Unix** only.A trait to express the ability to consume an object and acquire ownership of its raw file descriptor.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#135)#### fn into\_raw\_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor.
This function is typically used to **transfer ownership** of the underlying file descriptor to the caller. When used in this way, callers are then the unique owners of the file descriptor and must close it once it’s no longer needed.
However, transferring ownership is not strictly required. Use a [`Into<OwnedFd>::into`](../../../convert/trait.into#tymethod.into "Into<OwnedFd>::into") implementation for an API which strictly transfers ownership.
##### Example
```
use std::fs::File;
#[cfg(unix)]
use std::os::unix::io::{IntoRawFd, RawFd};
#[cfg(target_os = "wasi")]
use std::os::wasi::io::{IntoRawFd, RawFd};
let f = File::open("foo.txt")?;
#[cfg(any(unix, target_os = "wasi"))]
let raw_fd: RawFd = f.into_raw_fd();
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#175-180)### impl IntoRawFd for File
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#46)### impl IntoRawFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#46)### impl IntoRawFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#46)### impl IntoRawFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#406-411)### impl IntoRawFd for ChildStderr
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#390-395)### impl IntoRawFd for ChildStdin
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#398-403)### impl IntoRawFd for ChildStdout
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#84-88)### impl IntoRawFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#983-988)1.10.0 · ### impl IntoRawFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#302-307)1.10.0 · ### impl IntoRawFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#707-712)1.10.0 · ### impl IntoRawFd for UnixStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#141-148)1.63.0 · ### impl IntoRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#146-151)1.48.0 · ### impl IntoRawFd for RawFd
rust Trait std::os::unix::io::AsRawFd Trait std::os::unix::io::AsRawFd
================================
```
pub trait AsRawFd {
fn as_raw_fd(&self) -> RawFd;
}
```
Available on **Unix** only.A trait to extract the raw file descriptor from an underlying object.
This is only available on unix and WASI platforms and must be imported in order to call the method. Windows platforms have a corresponding `AsRawHandle` and `AsRawSocket` set of traits.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#57)#### fn as\_raw\_fd(&self) -> RawFd
Extracts the raw file descriptor.
This function is typically used to **borrow** an owned file descriptor. When used in this way, this method does **not** pass ownership of the raw file descriptor to the caller, and the file descriptor is only guaranteed to be valid while the original object has not yet been destroyed.
However, borrowing is not strictly required. See [`AsFd::as_fd`](trait.asfd#tymethod.as_fd "AsFd::as_fd") for an API which strictly borrows a file descriptor.
##### Example
```
use std::fs::File;
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(target_os = "wasi")]
use std::os::wasi::io::{AsRawFd, RawFd};
let mut f = File::open("foo.txt")?;
// Note that `raw_fd` is only valid as long as `f` exists.
#[cfg(any(unix, target_os = "wasi"))]
let raw_fd: RawFd = f.as_raw_fd();
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#161-166)### impl AsRawFd for File
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#199-204)1.21.0 · ### impl AsRawFd for Stderr
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#183-188)1.21.0 · ### impl AsRawFd for Stdin
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#191-196)1.21.0 · ### impl AsRawFd for Stdout
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#17)### impl AsRawFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#17)### impl AsRawFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#17)### impl AsRawFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#382-387)1.2.0 · ### impl AsRawFd for ChildStderr
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#366-371)1.2.0 · ### impl AsRawFd for ChildStdin
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#374-379)1.2.0 · ### impl AsRawFd for ChildStdout
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#72-76)### impl AsRawFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#967-972)1.10.0 · ### impl AsRawFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#286-291)1.10.0 · ### impl AsRawFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#691-696)1.10.0 · ### impl AsRawFd for UnixStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#125-130)1.63.0 · ### impl AsRawFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#133-138)1.63.0 · ### impl AsRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#139-144)1.48.0 · ### impl AsRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#223-228)1.35.0 · ### impl<'a> AsRawFd for StderrLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#207-212)1.35.0 · ### impl<'a> AsRawFd for StdinLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#215-220)1.35.0 · ### impl<'a> AsRawFd for StdoutLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#254-259)1.63.0 · ### impl<T: AsRawFd> AsRawFd for Box<T>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#246-251)1.63.0 · ### impl<T: AsRawFd> AsRawFd for Arc<T>
This impl allows implementing traits that require `AsRawFd` on Arc.
```
use std::net::UdpSocket;
use std::sync::Arc;
trait MyTrait: AsRawFd {
}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}
```
rust Trait std::os::unix::io::FromRawFd Trait std::os::unix::io::FromRawFd
==================================
```
pub trait FromRawFd {
unsafe fn from_raw_fd(fd: RawFd) -> Self;
}
```
Available on **Unix** only.A trait to express the ability to construct an object from a raw file descriptor.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#101)#### unsafe fn from\_raw\_fd(fd: RawFd) -> Self
Constructs a new instance of `Self` from the given raw file descriptor.
This function is typically used to **consume ownership** of the specified file descriptor. When used in this way, the returned object will take responsibility for closing it when the object goes out of scope.
However, consuming ownership is not strictly required. Use a [`From<OwnedFd>::from`](../../../convert/trait.from#tymethod.from "From<OwnedFd>::from") implementation for an API which strictly consumes ownership.
##### Safety
The `fd` passed in must be a valid and open file descriptor.
##### Example
```
use std::fs::File;
#[cfg(unix)]
use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
#[cfg(target_os = "wasi")]
use std::os::wasi::io::{FromRawFd, IntoRawFd, RawFd};
let f = File::open("foo.txt")?;
let raw_fd: RawFd = f.into_raw_fd();
// SAFETY: no other functions should call `from_raw_fd`, so there
// is only one owner for the file descriptor.
let f = unsafe { File::from_raw_fd(raw_fd) };
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#168-173)### impl FromRawFd for File
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#33)### impl FromRawFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#33)### impl FromRawFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#33)### impl FromRawFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#346-353)1.2.0 · ### impl FromRawFd for Stdio
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#78-82)### impl FromRawFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#975-980)1.10.0 · ### impl FromRawFd for UnixDatagram
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#294-299)1.10.0 · ### impl FromRawFd for UnixListener
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#699-704)1.10.0 · ### impl FromRawFd for UnixStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#151-164)1.63.0 · ### impl FromRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#153-158)1.48.0 · ### impl FromRawFd for RawFd
rust Trait std::os::unix::ffi::OsStringExt Trait std::os::unix::ffi::OsStringExt
=====================================
```
pub trait OsStringExt: Sealed {
fn from_vec(vec: Vec<u8>) -> Self;
fn into_vec(self) -> Vec<u8>;
}
```
Notable traits for [Vec](../../../vec/struct.vec "struct std::vec::Vec")<[u8](../../../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Available on **Unix** only.Platform-specific extensions to [`OsString`](../../../ffi/struct.osstring "OsString").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/ffi/os_str.rs.html#20)#### fn from\_vec(vec: Vec<u8>) -> Self
Creates an [`OsString`](../../../ffi/struct.osstring "OsString") from a byte vector.
See the module documentation for an example.
[source](https://doc.rust-lang.org/src/std/os/unix/ffi/os_str.rs.html#26)#### fn into\_vec(self) -> Vec<u8>
Notable traits for [Vec](../../../vec/struct.vec "struct std::vec::Vec")<[u8](../../../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Yields the underlying byte vector of this [`OsString`](../../../ffi/struct.osstring "OsString").
See the module documentation for an example.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/ffi/os_str.rs.html#30-39)### impl OsStringExt for OsString
rust Module std::os::unix::ffi Module std::os::unix::ffi
=========================
Available on **Unix** only.Unix-specific extensions to primitives in the [`std::ffi`](../../../ffi/index) module.
Examples
--------
```
use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;
let bytes = b"foo".to_vec();
// OsStringExt::from_vec
let os_string = OsString::from_vec(bytes);
assert_eq!(os_string.to_str(), Some("foo"));
// OsStringExt::into_vec
let bytes = os_string.into_vec();
assert_eq!(bytes, b"foo");
```
```
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
let bytes = b"foo";
// OsStrExt::from_bytes
let os_str = OsStr::from_bytes(bytes);
assert_eq!(os_str.to_str(), Some("foo"));
// OsStrExt::as_bytes
let bytes = os_str.as_bytes();
assert_eq!(bytes, b"foo");
```
Traits
------
[OsStrExt](trait.osstrext "std::os::unix::ffi::OsStrExt trait")
Platform-specific extensions to [`OsStr`](../../../ffi/struct.osstr "OsStr").
[OsStringExt](trait.osstringext "std::os::unix::ffi::OsStringExt trait")
Platform-specific extensions to [`OsString`](../../../ffi/struct.osstring "OsString").
rust Trait std::os::unix::ffi::OsStrExt Trait std::os::unix::ffi::OsStrExt
==================================
```
pub trait OsStrExt: Sealed {
fn from_bytes(slice: &[u8]) -> &Self;
fn as_bytes(&self) -> &[u8];
}
```
Notable traits for &[[u8](../../../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Available on **Unix** only.Platform-specific extensions to [`OsStr`](../../../ffi/struct.osstr "OsStr").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/ffi/os_str.rs.html#51)#### fn from\_bytes(slice: &[u8]) -> &Self
Creates an [`OsStr`](../../../ffi/struct.osstr "OsStr") from a byte slice.
See the module documentation for an example.
[source](https://doc.rust-lang.org/src/std/os/unix/ffi/os_str.rs.html#57)#### fn as\_bytes(&self) -> &[u8]
Notable traits for &[[u8](../../../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Gets the underlying byte view of the [`OsStr`](../../../ffi/struct.osstr "OsStr") slice.
See the module documentation for an example.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/ffi/os_str.rs.html#61-70)### impl OsStrExt for OsStr
rust Module std::os::unix::prelude Module std::os::unix::prelude
=============================
Available on **Unix** only.A prelude for conveniently writing platform-specific code.
Includes all extension traits, and some important type definitions.
Re-exports
----------
`pub use super::ffi::[OsStrExt](../ffi/trait.osstrext "trait std::os::unix::ffi::OsStrExt");`
`pub use super::ffi::[OsStringExt](../ffi/trait.osstringext "trait std::os::unix::ffi::OsStringExt");`
`pub use super::fs::[DirEntryExt](../fs/trait.direntryext "trait std::os::unix::fs::DirEntryExt");`
`pub use super::fs::[FileExt](../fs/trait.fileext "trait std::os::unix::fs::FileExt");`
`pub use super::fs::[FileTypeExt](../fs/trait.filetypeext "trait std::os::unix::fs::FileTypeExt");`
`pub use super::fs::[MetadataExt](../fs/trait.metadataext "trait std::os::unix::fs::MetadataExt");`
`pub use super::fs::[OpenOptionsExt](../fs/trait.openoptionsext "trait std::os::unix::fs::OpenOptionsExt");`
`pub use super::fs::[PermissionsExt](../fs/trait.permissionsext "trait std::os::unix::fs::PermissionsExt");`
`pub use super::io::[AsFd](../io/trait.asfd "trait std::os::unix::io::AsFd");`
`pub use super::io::[AsRawFd](../io/trait.asrawfd "trait std::os::unix::io::AsRawFd");`
`pub use super::io::[BorrowedFd](../io/struct.borrowedfd "struct std::os::unix::io::BorrowedFd");`
`pub use super::io::[FromRawFd](../io/trait.fromrawfd "trait std::os::unix::io::FromRawFd");`
`pub use super::io::[IntoRawFd](../io/trait.intorawfd "trait std::os::unix::io::IntoRawFd");`
`pub use super::io::[OwnedFd](../io/struct.ownedfd "struct std::os::unix::io::OwnedFd");`
`pub use super::io::[RawFd](../io/type.rawfd "type std::os::unix::io::RawFd");`
`pub use super::process::[CommandExt](../process/trait.commandext "trait std::os::unix::process::CommandExt");`
`pub use super::process::[ExitStatusExt](../process/trait.exitstatusext "trait std::os::unix::process::ExitStatusExt");`
`pub use super::thread::[JoinHandleExt](../thread/trait.joinhandleext "trait std::os::unix::thread::JoinHandleExt");`
rust Function std::os::unix::fs::lchown Function std::os::unix::fs::lchown
==================================
```
pub fn lchown<P: AsRef<Path>>( dir: P, uid: Option<u32>, gid: Option<u32>) -> Result<()>
```
🔬This is a nightly-only experimental API. (`unix_chown` [#88989](https://github.com/rust-lang/rust/issues/88989))
Available on **Unix** only.Change the owner and group of the specified path, without dereferencing symbolic links.
Identical to [`chown`](fn.chown "chown"), except that if called on a symbolic link, this will change the owner and group of the link itself rather than the owner and group of the link target.
Examples
--------
```
#![feature(unix_chown)]
use std::os::unix::fs;
fn main() -> std::io::Result<()> {
fs::lchown("/symlink", Some(0), Some(0))?;
Ok(())
}
```
rust Trait std::os::unix::fs::DirBuilderExt Trait std::os::unix::fs::DirBuilderExt
======================================
```
pub trait DirBuilderExt {
fn mode(&mut self, mode: u32) -> &mut Self;
}
```
Available on **Unix** only.Unix-specific extensions to [`fs::DirBuilder`](../../../fs/struct.dirbuilder "fs::DirBuilder").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#919)#### fn mode(&mut self, mode: u32) -> &mut Self
Sets the mode to create new directories with. This option defaults to 0o777.
##### Examples
```
use std::fs::DirBuilder;
use std::os::unix::fs::DirBuilderExt;
let mut builder = DirBuilder::new();
builder.mode(0o755);
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#923-928)### impl DirBuilderExt for DirBuilder
| programming_docs |
rust Trait std::os::unix::fs::FileTypeExt Trait std::os::unix::fs::FileTypeExt
====================================
```
pub trait FileTypeExt {
fn is_block_device(&self) -> bool;
fn is_char_device(&self) -> bool;
fn is_fifo(&self) -> bool;
fn is_socket(&self) -> bool;
}
```
Available on **Unix** only.Unix-specific extensions for [`fs::FileType`](../../../fs/struct.filetype "fs::FileType").
Adds support for special Unix file types such as block/character devices, pipes, and sockets.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#742)#### fn is\_block\_device(&self) -> bool
Returns `true` if this file type is a block device.
##### Examples
```
use std::fs;
use std::os::unix::fs::FileTypeExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("block_device_file")?;
let file_type = meta.file_type();
assert!(file_type.is_block_device());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#760)#### fn is\_char\_device(&self) -> bool
Returns `true` if this file type is a char device.
##### Examples
```
use std::fs;
use std::os::unix::fs::FileTypeExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("char_device_file")?;
let file_type = meta.file_type();
assert!(file_type.is_char_device());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#778)#### fn is\_fifo(&self) -> bool
Returns `true` if this file type is a fifo.
##### Examples
```
use std::fs;
use std::os::unix::fs::FileTypeExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("fifo_file")?;
let file_type = meta.file_type();
assert!(file_type.is_fifo());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#796)#### fn is\_socket(&self) -> bool
Returns `true` if this file type is a socket.
##### Examples
```
use std::fs;
use std::os::unix::fs::FileTypeExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("unix.socket")?;
let file_type = meta.file_type();
assert!(file_type.is_socket());
Ok(())
}
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#800-813)### impl FileTypeExt for FileType
rust Module std::os::unix::fs Module std::os::unix::fs
========================
Available on **Unix** only.Unix-specific extensions to primitives in the [`std::fs`](../../../fs/index) module.
Traits
------
[DirEntryExt2](trait.direntryext2 "std::os::unix::fs::DirEntryExt2 trait")Experimental
Sealed Unix-specific extension methods for [`fs::DirEntry`](../../../fs/struct.direntry "fs::DirEntry").
[DirBuilderExt](trait.dirbuilderext "std::os::unix::fs::DirBuilderExt trait")
Unix-specific extensions to [`fs::DirBuilder`](../../../fs/struct.dirbuilder "fs::DirBuilder").
[DirEntryExt](trait.direntryext "std::os::unix::fs::DirEntryExt trait")
Unix-specific extension methods for [`fs::DirEntry`](../../../fs/struct.direntry "fs::DirEntry").
[FileExt](trait.fileext "std::os::unix::fs::FileExt trait")
Unix-specific extensions to [`fs::File`](../../../fs/struct.file "fs::File").
[FileTypeExt](trait.filetypeext "std::os::unix::fs::FileTypeExt trait")
Unix-specific extensions for [`fs::FileType`](../../../fs/struct.filetype "fs::FileType").
[MetadataExt](trait.metadataext "std::os::unix::fs::MetadataExt trait")
Unix-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata "fs::Metadata").
[OpenOptionsExt](trait.openoptionsext "std::os::unix::fs::OpenOptionsExt trait")
Unix-specific extensions to [`fs::OpenOptions`](../../../fs/struct.openoptions "fs::OpenOptions").
[PermissionsExt](trait.permissionsext "std::os::unix::fs::PermissionsExt trait")
Unix-specific extensions to [`fs::Permissions`](../../../fs/struct.permissions "fs::Permissions").
Functions
---------
[chown](fn.chown "std::os::unix::fs::chown fn")Experimental
Change the owner and group of the specified path.
[fchown](fn.fchown "std::os::unix::fs::fchown fn")Experimental
Change the owner and group of the file referenced by the specified open file descriptor.
[lchown](fn.lchown "std::os::unix::fs::lchown fn")Experimental
Change the owner and group of the specified path, without dereferencing symbolic links.
[chroot](fn.chroot "std::os::unix::fs::chroot fn")
Change the root directory of the current process to the specified path.
[symlink](fn.symlink "std::os::unix::fs::symlink fn")
Creates a new symbolic link on the filesystem.
rust Function std::os::unix::fs::symlink Function std::os::unix::fs::symlink
===================================
```
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>( original: P, link: Q) -> Result<()>
```
Available on **Unix** only.Creates a new symbolic link on the filesystem.
The `link` path will be a symbolic link pointing to the `original` path.
Examples
--------
```
use std::os::unix::fs;
fn main() -> std::io::Result<()> {
fs::symlink("a.txt", "b.txt")?;
Ok(())
}
```
rust Trait std::os::unix::fs::DirEntryExt Trait std::os::unix::fs::DirEntryExt
====================================
```
pub trait DirEntryExt {
fn ino(&self) -> u64;
}
```
Available on **Unix** only.Unix-specific extension methods for [`fs::DirEntry`](../../../fs/struct.direntry "fs::DirEntry").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#837)#### fn ino(&self) -> u64
Returns the underlying `d_ino` field in the contained `dirent` structure.
##### Examples
```
use std::fs;
use std::os::unix::fs::DirEntryExt;
if let Ok(entries) = fs::read_dir(".") {
for entry in entries {
if let Ok(entry) = entry {
// Here, `entry` is a `DirEntry`.
println!("{:?}: {}", entry.file_name(), entry.ino());
}
}
}
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#841-845)### impl DirEntryExt for DirEntry
rust Trait std::os::unix::fs::FileExt Trait std::os::unix::fs::FileExt
================================
```
pub trait FileExt {
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>;
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>;
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()> { ... }
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()> { ... }
}
```
Available on **Unix** only.Unix-specific extensions to [`fs::File`](../../../fs/struct.file "fs::File").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#55)#### fn read\_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
Reads a number of bytes starting from a given offset.
Returns the number of bytes read.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Note that similar to [`File::read`](../../../fs/struct.file#method.read), it is not an error to return with a short read.
##### Examples
```
use std::io;
use std::fs::File;
use std::os::unix::prelude::FileExt;
fn main() -> io::Result<()> {
let mut buf = [0u8; 8];
let file = File::open("foo.txt")?;
// We now read 8 bytes from the offset 10.
let num_bytes_read = file.read_at(&mut buf, 10)?;
println!("read {num_bytes_read} bytes: {buf:?}");
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#156)#### fn write\_at(&self, buf: &[u8], offset: u64) -> Result<usize>
Writes a number of bytes starting from a given offset.
Returns the number of bytes written.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.
Note that similar to [`File::write`](../../../fs/struct.file#method.write), it is not an error to return a short write.
##### Examples
```
use std::fs::File;
use std::io;
use std::os::unix::prelude::FileExt;
fn main() -> io::Result<()> {
let file = File::open("foo.txt")?;
// We now write at the offset 10.
file.write_at(b"sushi", 10)?;
Ok(())
}
```
Provided Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#103-121)1.33.0 · #### fn read\_exact\_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
Reads the exact number of byte required to fill `buf` from the given offset.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Similar to [`io::Read::read_exact`](../../../io/trait.read#method.read_exact "io::Read::read_exact") but uses [`read_at`](trait.fileext#tymethod.read_at) instead of `read`.
##### Errors
If this function encounters an error of the kind [`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") then the error is ignored and the operation will continue.
If this function encounters an “end of file” before completely filling the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`](../../../io/enum.errorkind#variant.UnexpectedEof "io::ErrorKind::UnexpectedEof"). The contents of `buf` are unspecified in this case.
If any other read error is encountered then this function immediately returns. The contents of `buf` are unspecified in this case.
If this function returns an error, it is unspecified how many bytes it has read, but it will never read more than would be necessary to completely fill the buffer.
##### Examples
```
use std::io;
use std::fs::File;
use std::os::unix::prelude::FileExt;
fn main() -> io::Result<()> {
let mut buf = [0u8; 8];
let file = File::open("foo.txt")?;
// We now read exactly 8 bytes from the offset 10.
file.read_exact_at(&mut buf, 10)?;
println!("read {} bytes: {:?}", buf.len(), buf);
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#195-213)1.33.0 · #### fn write\_all\_at(&self, buf: &[u8], offset: u64) -> Result<()>
Attempts to write an entire buffer starting from a given offset.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
This method will continuously call [`write_at`](trait.fileext#tymethod.write_at) until there is no more data to be written or an error of non-[`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") kind is returned. This method will not return until the entire buffer has been successfully written or such an error occurs. The first error that is not of [`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") kind generated from this method will be returned.
##### Errors
This function will return the first error of non-[`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") kind that [`write_at`](trait.fileext#tymethod.write_at) returns.
##### Examples
```
use std::fs::File;
use std::io;
use std::os::unix::prelude::FileExt;
fn main() -> io::Result<()> {
let file = File::open("foo.txt")?;
// We now write at the offset 10.
file.write_all_at(b"sushi", 10)?;
Ok(())
}
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#217-224)### impl FileExt for File
rust Trait std::os::unix::fs::DirEntryExt2 Trait std::os::unix::fs::DirEntryExt2
=====================================
```
pub trait DirEntryExt2: Sealed {
fn file_name_ref(&self) -> &OsStr;
}
```
🔬This is a nightly-only experimental API. (`dir_entry_ext2` [#85573](https://github.com/rust-lang/rust/issues/85573))
Available on **Unix** only.Sealed Unix-specific extension methods for [`fs::DirEntry`](../../../fs/struct.direntry "fs::DirEntry").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#870)#### fn file\_name\_ref(&self) -> &OsStr
🔬This is a nightly-only experimental API. (`dir_entry_ext2` [#85573](https://github.com/rust-lang/rust/issues/85573))
Returns a reference to the underlying `OsStr` of this entry’s filename.
##### Examples
```
#![feature(dir_entry_ext2)]
use std::os::unix::fs::DirEntryExt2;
use std::{fs, io};
fn main() -> io::Result<()> {
let mut entries = fs::read_dir(".")?.collect::<Result<Vec<_>, io::Error>>()?;
entries.sort_unstable_by(|a, b| a.file_name_ref().cmp(b.file_name_ref()));
for p in entries {
println!("{p:?}");
}
Ok(())
}
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#878-882)### impl DirEntryExt2 for DirEntry
rust Function std::os::unix::fs::chown Function std::os::unix::fs::chown
=================================
```
pub fn chown<P: AsRef<Path>>( dir: P, uid: Option<u32>, gid: Option<u32>) -> Result<()>
```
🔬This is a nightly-only experimental API. (`unix_chown` [#88989](https://github.com/rust-lang/rust/issues/88989))
Available on **Unix** only.Change the owner and group of the specified path.
Specifying either the uid or gid as `None` will leave it unchanged.
Changing the owner typically requires privileges, such as root or a specific capability. Changing the group typically requires either being the owner and a member of the group, or having privileges.
If called on a symbolic link, this will change the owner and group of the link target. To change the owner and group of the link itself, see [`lchown`](fn.lchown "lchown").
Examples
--------
```
#![feature(unix_chown)]
use std::os::unix::fs;
fn main() -> std::io::Result<()> {
fs::chown("/sandbox", Some(0), Some(0))?;
Ok(())
}
```
rust Function std::os::unix::fs::fchown Function std::os::unix::fs::fchown
==================================
```
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> Result<()>
```
🔬This is a nightly-only experimental API. (`unix_chown` [#88989](https://github.com/rust-lang/rust/issues/88989))
Available on **Unix** only.Change the owner and group of the file referenced by the specified open file descriptor.
For semantics and required privileges, see [`chown`](fn.chown "chown").
Examples
--------
```
#![feature(unix_chown)]
use std::os::unix::fs;
fn main() -> std::io::Result<()> {
let f = std::fs::File::open("/file")?;
fs::fchown(&f, Some(0), Some(0))?;
Ok(())
}
```
rust Trait std::os::unix::fs::OpenOptionsExt Trait std::os::unix::fs::OpenOptionsExt
=======================================
```
pub trait OpenOptionsExt {
fn mode(&mut self, mode: u32) -> &mut Self;
fn custom_flags(&mut self, flags: i32) -> &mut Self;
}
```
Available on **Unix** only.Unix-specific extensions to [`fs::OpenOptions`](../../../fs/struct.openoptions "fs::OpenOptions").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#327)#### fn mode(&mut self, mode: u32) -> &mut Self
Sets the mode bits that a new file will be created with.
If a new file is created as part of an `OpenOptions::open` call then this specified `mode` will be used as the permission bits for the new file. If no `mode` is set, the default of `0o666` will be used. The operating system masks out bits with the system’s `umask`, to produce the final permissions.
##### Examples
```
use std::fs::OpenOptions;
use std::os::unix::fs::OpenOptionsExt;
let mut options = OpenOptions::new();
options.mode(0o644); // Give read/write for owner and read for others.
let file = options.open("foo.txt");
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#355)1.10.0 · #### fn custom\_flags(&mut self, flags: i32) -> &mut Self
Pass custom flags to the `flags` argument of `open`.
The bits that define the access mode are masked out with `O_ACCMODE`, to ensure they do not interfere with the access mode set by Rusts options.
Custom flags can only set flags, not remove flags set by Rusts options. This options overwrites any previously set custom flags.
##### Examples
```
extern crate libc;
use std::fs::OpenOptions;
use std::os::unix::fs::OpenOptionsExt;
let mut options = OpenOptions::new();
options.write(true);
if cfg!(unix) {
options.custom_flags(libc::O_NOFOLLOW);
}
let file = options.open("foo.txt");
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#359-369)### impl OpenOptionsExt for OpenOptions
rust Trait std::os::unix::fs::PermissionsExt Trait std::os::unix::fs::PermissionsExt
=======================================
```
pub trait PermissionsExt {
fn mode(&self) -> u32;
fn set_mode(&mut self, mode: u32);
fn from_mode(mode: u32) -> Self;
}
```
Available on **Unix** only.Unix-specific extensions to [`fs::Permissions`](../../../fs/struct.permissions "fs::Permissions").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#248)#### fn mode(&self) -> u32
Returns the underlying raw `st_mode` bits that contain the standard Unix permissions for this file.
##### Examples
```
use std::fs::File;
use std::os::unix::fs::PermissionsExt;
fn main() -> std::io::Result<()> {
let f = File::create("foo.txt")?;
let metadata = f.metadata()?;
let permissions = metadata.permissions();
println!("permissions: {:o}", permissions.mode());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#269)#### fn set\_mode(&mut self, mode: u32)
Sets the underlying raw bits for this set of permissions.
##### Examples
```
use std::fs::File;
use std::os::unix::fs::PermissionsExt;
fn main() -> std::io::Result<()> {
let f = File::create("foo.txt")?;
let metadata = f.metadata()?;
let mut permissions = metadata.permissions();
permissions.set_mode(0o644); // Read/write for owner and read for others.
assert_eq!(permissions.mode(), 0o644);
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#285)#### fn from\_mode(mode: u32) -> Self
Creates a new instance of `Permissions` from the given set of Unix permission bits.
##### Examples
```
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;
// Read/write for owner and read for others.
let permissions = Permissions::from_mode(0o644);
assert_eq!(permissions.mode(), 0o644);
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#289-301)### impl PermissionsExt for Permissions
rust Function std::os::unix::fs::chroot Function std::os::unix::fs::chroot
==================================
```
pub fn chroot<P: AsRef<Path>>(dir: P) -> Result<()>
```
Available on **Unix** only.Change the root directory of the current process to the specified path.
This typically requires privileges, such as root or a specific capability.
This does not change the current working directory; you should call [`std::env::set_current_dir`](../../../env/fn.set_current_dir "crate::env::set_current_dir") afterwards.
Examples
--------
```
use std::os::unix::fs;
fn main() -> std::io::Result<()> {
fs::chroot("/sandbox")?;
std::env::set_current_dir("/")?;
// continue working in sandbox
Ok(())
}
```
rust Trait std::os::unix::fs::MetadataExt Trait std::os::unix::fs::MetadataExt
====================================
```
pub trait MetadataExt {
Show 16 methods fn dev(&self) -> u64;
fn ino(&self) -> u64;
fn mode(&self) -> u32;
fn nlink(&self) -> u64;
fn uid(&self) -> u32;
fn gid(&self) -> u32;
fn rdev(&self) -> u64;
fn size(&self) -> u64;
fn atime(&self) -> i64;
fn atime_nsec(&self) -> i64;
fn mtime(&self) -> i64;
fn mtime_nsec(&self) -> i64;
fn ctime(&self) -> i64;
fn ctime_nsec(&self) -> i64;
fn blksize(&self) -> u64;
fn blocks(&self) -> u64;
}
```
Available on **Unix** only.Unix-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata "fs::Metadata").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#390)#### fn dev(&self) -> u64
Returns the ID of the device containing the file.
##### Examples
```
use std::io;
use std::fs;
use std::os::unix::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let dev_id = meta.dev();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#407)#### fn ino(&self) -> u64
Returns the inode number.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let inode = meta.ino();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#428)#### fn mode(&self) -> u32
Returns the rights applied to this file.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let mode = meta.mode();
let user_has_write_access = mode & 0o200;
let user_has_read_write_access = mode & 0o600;
let group_has_read_access = mode & 0o040;
let others_have_exec_access = mode & 0o001;
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#445)#### fn nlink(&self) -> u64
Returns the number of hard links pointing to this file.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nb_hard_links = meta.nlink();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#462)#### fn uid(&self) -> u32
Returns the user ID of the owner of this file.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let user_id = meta.uid();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#479)#### fn gid(&self) -> u32
Returns the group ID of the owner of this file.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let group_id = meta.gid();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#496)#### fn rdev(&self) -> u64
Returns the device ID of this file (if it is a special one).
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let device_id = meta.rdev();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#513)#### fn size(&self) -> u64
Returns the total size of this file in bytes.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let file_size = meta.size();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#530)#### fn atime(&self) -> i64
Returns the last access time of the file, in seconds since Unix Epoch.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let last_access_time = meta.atime();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#549)#### fn atime\_nsec(&self) -> i64
Returns the last access time of the file, in nanoseconds since [`atime`](trait.metadataext#tymethod.atime).
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nano_last_access_time = meta.atime_nsec();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#566)#### fn mtime(&self) -> i64
Returns the last modification time of the file, in seconds since Unix Epoch.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let last_modification_time = meta.mtime();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#585)#### fn mtime\_nsec(&self) -> i64
Returns the last modification time of the file, in nanoseconds since [`mtime`](trait.metadataext#tymethod.mtime).
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nano_last_modification_time = meta.mtime_nsec();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#602)#### fn ctime(&self) -> i64
Returns the last status change time of the file, in seconds since Unix Epoch.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let last_status_change_time = meta.ctime();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#621)#### fn ctime\_nsec(&self) -> i64
Returns the last status change time of the file, in nanoseconds since [`ctime`](trait.metadataext#tymethod.ctime).
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nano_last_status_change_time = meta.ctime_nsec();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#638)#### fn blksize(&self) -> u64
Returns the block size for filesystem I/O.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let block_size = meta.blksize();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#657)#### fn blocks(&self) -> u64
Returns the number of blocks allocated to the file, in 512-byte units.
Please note that this may be smaller than `st_size / 512` when the file has holes.
##### Examples
```
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let blocks = meta.blocks();
Ok(())
}
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/fs.rs.html#664-717)### impl MetadataExt for Metadata
| programming_docs |
rust Module std::os::unix::thread Module std::os::unix::thread
============================
Available on **Unix** only.Unix-specific extensions to primitives in the [`std::thread`](../../../thread/index) module.
Traits
------
[JoinHandleExt](trait.joinhandleext "std::os::unix::thread::JoinHandleExt trait")
Unix-specific extensions to [`JoinHandle`](../../../thread/struct.joinhandle "JoinHandle").
Type Definitions
----------------
[RawPthread](type.rawpthread "std::os::unix::thread::RawPthread type")
rust Trait std::os::unix::thread::JoinHandleExt Trait std::os::unix::thread::JoinHandleExt
==========================================
```
pub trait JoinHandleExt {
fn as_pthread_t(&self) -> RawPthread;
fn into_pthread_t(self) -> RawPthread;
}
```
Available on **Unix** only.Unix-specific extensions to [`JoinHandle`](../../../thread/struct.joinhandle "JoinHandle").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/thread.rs.html#21)#### fn as\_pthread\_t(&self) -> RawPthread
Extracts the raw pthread\_t without taking ownership
[source](https://doc.rust-lang.org/src/std/os/unix/thread.rs.html#29)#### fn into\_pthread\_t(self) -> RawPthread
Consumes the thread, returning the raw pthread\_t
This function **transfers ownership** of the underlying pthread\_t to the caller. Callers are then the unique owners of the pthread\_t and must either detach or join the pthread\_t once it’s no longer needed.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/thread.rs.html#33-41)### impl<T> JoinHandleExt for JoinHandle<T>
rust Type Definition std::os::unix::thread::RawPthread Type Definition std::os::unix::thread::RawPthread
=================================================
```
pub type RawPthread = pthread_t;
```
Available on **Unix** only.
rust Type Definition std::os::unix::raw::off_t Type Definition std::os::unix::raw::off\_t
==========================================
```
pub type off_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Module std::os::unix::raw Module std::os::unix::raw
=========================
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix** only.Unix-specific primitives available on all unix platforms.
Type Definitions
----------------
[blkcnt\_t](type.blkcnt_t "std::os::unix::raw::blkcnt_t type")DeprecatedLinux
[blksize\_t](type.blksize_t "std::os::unix::raw::blksize_t type")DeprecatedLinux
[dev\_t](type.dev_t "std::os::unix::raw::dev_t type")DeprecatedLinux
[gid\_t](type.gid_t "std::os::unix::raw::gid_t type")Deprecated
[ino\_t](type.ino_t "std::os::unix::raw::ino_t type")DeprecatedLinux
[mode\_t](type.mode_t "std::os::unix::raw::mode_t type")DeprecatedLinux
[nlink\_t](type.nlink_t "std::os::unix::raw::nlink_t type")DeprecatedLinux
[off\_t](type.off_t "std::os::unix::raw::off_t type")DeprecatedLinux
[pid\_t](type.pid_t "std::os::unix::raw::pid_t type")Deprecated
[pthread\_t](type.pthread_t "std::os::unix::raw::pthread_t type")DeprecatedLinux
[time\_t](type.time_t "std::os::unix::raw::time_t type")DeprecatedLinux
[uid\_t](type.uid_t "std::os::unix::raw::uid_t type")Deprecated
rust Type Definition std::os::unix::raw::gid_t Type Definition std::os::unix::raw::gid\_t
==========================================
```
pub type gid_t = u32;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix** only.
rust Type Definition std::os::unix::raw::dev_t Type Definition std::os::unix::raw::dev\_t
==========================================
```
pub type dev_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Type Definition std::os::unix::raw::mode_t Type Definition std::os::unix::raw::mode\_t
===========================================
```
pub type mode_t = u32;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Type Definition std::os::unix::raw::nlink_t Type Definition std::os::unix::raw::nlink\_t
============================================
```
pub type nlink_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Type Definition std::os::unix::raw::uid_t Type Definition std::os::unix::raw::uid\_t
==========================================
```
pub type uid_t = u32;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix** only.
rust Type Definition std::os::unix::raw::time_t Type Definition std::os::unix::raw::time\_t
===========================================
```
pub type time_t = i64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Type Definition std::os::unix::raw::pid_t Type Definition std::os::unix::raw::pid\_t
==========================================
```
pub type pid_t = i32;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix** only.
rust Type Definition std::os::unix::raw::ino_t Type Definition std::os::unix::raw::ino\_t
==========================================
```
pub type ino_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Type Definition std::os::unix::raw::blksize_t Type Definition std::os::unix::raw::blksize\_t
==============================================
```
pub type blksize_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Type Definition std::os::unix::raw::pthread_t Type Definition std::os::unix::raw::pthread\_t
==============================================
```
pub type pthread_t = c_ulong;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Type Definition std::os::unix::raw::blkcnt_t Type Definition std::os::unix::raw::blkcnt\_t
=============================================
```
pub type blkcnt_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Unix and Linux** only.
rust Module std::os::unix::ucred Module std::os::unix::ucred
===========================
🔬This is a nightly-only experimental API. (`peer_credentials_unix_socket` [#42839](https://github.com/rust-lang/rust/issues/42839))
Available on **Unix** only.Unix peer credentials.
Re-exports
----------
`pub use self::impl_linux::[peer\_cred](impl_linux/fn.peer_cred "fn std::os::unix::ucred::impl_linux::peer_cred");`
Experimental
Modules
-------
[impl\_linux](impl_linux/index "std::os::unix::ucred::impl_linux mod")Experimental
Structs
-------
[UCred](struct.ucred "std::os::unix::ucred::UCred struct")Experimental
Credentials for a UNIX process for credentials passing.
rust Struct std::os::unix::ucred::UCred Struct std::os::unix::ucred::UCred
==================================
```
pub struct UCred {
pub uid: uid_t,
pub gid: gid_t,
pub pid: Option<pid_t>,
}
```
🔬This is a nightly-only experimental API. (`peer_credentials_unix_socket` [#42839](https://github.com/rust-lang/rust/issues/42839))
Available on **Unix** only.Credentials for a UNIX process for credentials passing.
Fields
------
`uid: [uid\_t](https://doc.rust-lang.org/1.65.0/libc/unix/type.uid_t.html "type libc::unix::uid_t")`
🔬This is a nightly-only experimental API. (`peer_credentials_unix_socket` [#42839](https://github.com/rust-lang/rust/issues/42839))
The UID part of the peer credential. This is the effective UID of the process at the domain socket’s endpoint.
`gid: [gid\_t](https://doc.rust-lang.org/1.65.0/libc/unix/type.gid_t.html "type libc::unix::gid_t")`
🔬This is a nightly-only experimental API. (`peer_credentials_unix_socket` [#42839](https://github.com/rust-lang/rust/issues/42839))
The GID part of the peer credential. This is the effective GID of the process at the domain socket’s endpoint.
`pid: [Option](../../../option/enum.option "enum std::option::Option")<[pid\_t](https://doc.rust-lang.org/1.65.0/libc/unix/type.pid_t.html "type libc::unix::pid_t")>`
🔬This is a nightly-only experimental API. (`peer_credentials_unix_socket` [#42839](https://github.com/rust-lang/rust/issues/42839))
The PID part of the peer credential. This field is optional because the PID part of the peer credentials is not supported on every platform. On platforms where the mechanism to discover the PID exists, this field will be populated to the PID of the process at the domain socket’s endpoint. Otherwise, it will be set to None.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl Clone for UCred
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)#### fn clone(&self) -> UCred
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl Debug for UCred
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl Hash for UCred
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)#### fn hash<\_\_H: Hasher>(&self, state: &mut \_\_H)
Feeds this value into the given [`Hasher`](../../../hash/trait.hasher "Hasher"). [Read more](../../../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../../../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../../../hash/trait.hasher "Hasher"). [Read more](../../../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl PartialEq<UCred> for UCred
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)#### fn eq(&self, other: &UCred) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl Copy for UCred
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl Eq for UCred
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl StructuralEq for UCred
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl StructuralPartialEq for UCred
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for UCred
### impl Send for UCred
### impl Sync for UCred
### impl Unpin for UCred
### impl UnwindSafe for UCred
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Module std::os::unix::ucred::impl_linux Module std::os::unix::ucred::impl\_linux
========================================
🔬This is a nightly-only experimental API. (`peer_credentials_unix_socket` [#42839](https://github.com/rust-lang/rust/issues/42839))
Available on **Unix** only.Functions
---------
[peer\_cred](fn.peer_cred "std::os::unix::ucred::impl_linux::peer_cred fn")Experimental
rust Function std::os::unix::ucred::impl_linux::peer_cred Function std::os::unix::ucred::impl\_linux::peer\_cred
======================================================
```
pub fn peer_cred(socket: &UnixStream) -> Result<UCred>
```
🔬This is a nightly-only experimental API. (`peer_credentials_unix_socket` [#42839](https://github.com/rust-lang/rust/issues/42839))
Available on **Unix** only.
rust Module std::os::unix::process Module std::os::unix::process
=============================
Available on **Unix** only.Unix-specific extensions to primitives in the [`std::process`](../../../process/index) module.
Traits
------
[CommandExt](trait.commandext "std::os::unix::process::CommandExt trait")
Unix-specific extensions to the [`process::Command`](../../../process/struct.command "process::Command") builder.
[ExitStatusExt](trait.exitstatusext "std::os::unix::process::ExitStatusExt trait")
Unix-specific extensions to [`process::ExitStatus`](../../../process/struct.exitstatus "process::ExitStatus") and [`ExitStatusError`](../../../process/struct.exitstatuserror).
Functions
---------
[parent\_id](fn.parent_id "std::os::unix::process::parent_id fn")
Returns the OS-assigned process identifier associated with this process’s parent.
rust Function std::os::unix::process::parent_id Function std::os::unix::process::parent\_id
===========================================
```
pub fn parent_id() -> u32
```
Available on **Unix** only.Returns the OS-assigned process identifier associated with this process’s parent.
rust Trait std::os::unix::process::ExitStatusExt Trait std::os::unix::process::ExitStatusExt
===========================================
```
pub trait ExitStatusExt: Sealed {
fn from_raw(raw: i32) -> Self;
fn signal(&self) -> Option<i32>;
fn core_dumped(&self) -> bool;
fn stopped_signal(&self) -> Option<i32>;
fn continued(&self) -> bool;
fn into_raw(self) -> i32;
}
```
Available on **Unix** only.Unix-specific extensions to [`process::ExitStatus`](../../../process/struct.exitstatus "process::ExitStatus") and [`ExitStatusError`](../../../process/struct.exitstatuserror).
On Unix, `ExitStatus` **does not necessarily represent an exit status**, as passed to the `_exit` system call or returned by [`ExitStatus::code()`](../../../process/struct.exitstatus#method.code). It represents **any wait status** as returned by one of the `wait` family of system calls.
A Unix wait status (a Rust `ExitStatus`) can represent a Unix exit status, but can also represent other kinds of process event.
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#256)1.12.0 · #### fn from\_raw(raw: i32) -> Self
Creates a new `ExitStatus` or `ExitStatusError` from the raw underlying integer status value from `wait`
The value should be a **wait status, not an exit status**.
##### Panics
Panics on an attempt to make an `ExitStatusError` from a wait status of `0`.
Making an `ExitStatus` always succeeds and never panics.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#262)#### fn signal(&self) -> Option<i32>
If the process was terminated by a signal, returns that signal.
In other words, if `WIFSIGNALED`, this returns `WTERMSIG`.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#266)1.58.0 · #### fn core\_dumped(&self) -> bool
If the process was terminated by a signal, says whether it dumped core.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#273)1.58.0 · #### fn stopped\_signal(&self) -> Option<i32>
If the process was stopped by a signal, returns that signal.
In other words, if `WIFSTOPPED`, this returns `WSTOPSIG`. This is only possible if the status came from a `wait` system call which was passed `WUNTRACED`, and was then converted into an `ExitStatus`.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#280)1.58.0 · #### fn continued(&self) -> bool
Whether the process was continued from a stopped status.
Ie, `WIFCONTINUED`. This is only possible if the status came from a `wait` system call which was passed `WCONTINUED`, and was then converted into an `ExitStatus`.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#286)1.58.0 · #### fn into\_raw(self) -> i32
Returns the underlying raw `wait` status.
The returned integer is a **wait status, not an exit status**.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#290-314)### impl ExitStatusExt for ExitStatus
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#317-343)### impl ExitStatusExt for ExitStatusError
| programming_docs |
rust Trait std::os::unix::process::CommandExt Trait std::os::unix::process::CommandExt
========================================
```
pub trait CommandExt: Sealed {
fn uid(&mut self, id: u32) -> &mut Command;
fn gid(&mut self, id: u32) -> &mut Command;
fn groups(&mut self, groups: &[u32]) -> &mut Command;
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Command where F: FnMut() -> Result<()> + Send + Sync + 'static;
fn exec(&mut self) -> Error;
fn arg0<S>(&mut self, arg: S) -> &mut Command where S: AsRef<OsStr>;
fn process_group(&mut self, pgroup: i32) -> &mut Command;
fn before_exec<F>(&mut self, f: F) -> &mut Command where F: FnMut() -> Result<()> + Send + Sync + 'static,
{ ... }
}
```
Available on **Unix** only.Unix-specific extensions to the [`process::Command`](../../../process/struct.command "process::Command") builder.
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#35)#### fn uid(&mut self, id: u32) -> &mut Command
Sets the child process’s user ID. This translates to a `setuid` call in the child process. Failure in the `setuid` call will cause the spawn to fail.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#40)#### fn gid(&mut self, id: u32) -> &mut Command
Similar to `uid`, but sets the group ID of the child process. This has the same semantics as the `uid` field.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#45)#### fn groups(&mut self, groups: &[u32]) -> &mut Command
🔬This is a nightly-only experimental API. (`setgroups` [#90747](https://github.com/rust-lang/rust/issues/90747))
Sets the supplementary group IDs for the calling process. Translates to a `setgroups` call in the child process.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#92-94)1.34.0 · #### unsafe fn pre\_exec<F>(&mut self, f: F) -> &mut Commandwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")() -> [Result](../../../io/type.result "type std::io::Result")<[()](../../../primitive.unit)> + [Send](../../../marker/trait.send "trait std::marker::Send") + [Sync](../../../marker/trait.sync "trait std::marker::Sync") + 'static,
Schedules a closure to be run just before the `exec` function is invoked.
The closure is allowed to return an I/O error whose OS error code will be communicated back to the parent and returned as an error from when the spawn was requested.
Multiple closures can be registered and they will be called in order of their registration. If a closure returns `Err` then no further closures will be called and the spawn operation will immediately return with a failure.
##### Notes and Safety
This closure will be run in the context of the child process after a `fork`. This primarily means that any modifications made to memory on behalf of this closure will **not** be visible to the parent process. This is often a very constrained environment where normal operations like `malloc`, accessing environment variables through [`std::env`](../../../env/index) or acquiring a mutex are not guaranteed to work (due to other threads perhaps still running when the `fork` was run).
For further details refer to the [POSIX fork() specification](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html) and the equivalent documentation for any targeted platform, especially the requirements around *async-signal-safety*.
This also means that all resources such as file descriptors and memory-mapped regions got duplicated. It is your responsibility to make sure that the closure does not violate library invariants by making invalid use of these duplicates.
Panicking in the closure is safe only if all the format arguments for the panic message can be safely formatted; this is because although `Command` calls [`std::panic::always_abort`](../../../panic/fn.always_abort) before calling the pre\_exec hook, panic will still try to format the panic message.
When this closure is run, aspects such as the stdio file descriptors and working directory have successfully been changed, so output to these locations might not appear where intended.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#140)1.9.0 · #### fn exec(&mut self) -> Error
Performs all the required setup by this `Command`, followed by calling the `execvp` syscall.
On success this function will not return, and otherwise it will return an error indicating why the exec (or another part of the setup of the `Command`) failed.
`exec` not returning has the same implications as calling [`process::exit`](../../../process/fn.exit "process::exit") – no destructors on the current stack or any other thread’s stack will be run. Therefore, it is recommended to only call `exec` at a point where it is fine to not run any destructors. Note, that the `execvp` syscall independently guarantees that all memory is freed and all file descriptors with the `CLOEXEC` option (set by default on all file descriptors opened by the standard library) are closed.
This function, unlike `spawn`, will **not** `fork` the process to create a new child. Like spawn, however, the default behavior for the stdio descriptors will be to inherited from the current process.
##### Notes
The process may be in a “broken state” if this function returns in error. For example the working directory, environment variables, signal handling settings, various user/group information, or aspects of stdio file descriptors may have changed. If a “transactional spawn” is required to gracefully handle errors it is recommended to use the cross-platform `spawn` instead.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#147-149)1.45.0 · #### fn arg0<S>(&mut self, arg: S) -> &mut Commandwhere S: [AsRef](../../../convert/trait.asref "trait std::convert::AsRef")<[OsStr](../../../ffi/struct.osstr "struct std::ffi::OsStr")>,
Set executable argument
Set the first process argument, `argv[0]`, to something other than the default executable path.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#181)1.64.0 · #### fn process\_group(&mut self, pgroup: i32) -> &mut Command
Sets the process group ID (PGID) of the child process. Equivalent to a `setpgid` call in the child process, but may be more efficient.
Process groups determine which processes receive signals.
##### Examples
Pressing Ctrl-C in a terminal will send SIGINT to all processes in the current foreground process group. By spawning the `sleep` subprocess in a new process group, it will not receive SIGINT from the terminal.
The parent process could install a signal handler and manage the subprocess on its own terms.
A process group ID of 0 will use the process ID as the PGID.
```
use std::process::Command;
use std::os::unix::process::CommandExt;
Command::new("sleep")
.arg("10")
.process_group(0)
.spawn()?
.wait()?;
```
Provided Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#105-110)1.15.0 · #### fn before\_exec<F>(&mut self, f: F) -> &mut Commandwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")() -> [Result](../../../io/type.result "type std::io::Result")<[()](../../../primitive.unit)> + [Send](../../../marker/trait.send "trait std::marker::Send") + [Sync](../../../marker/trait.sync "trait std::marker::Sync") + 'static,
👎Deprecated since 1.37.0: should be unsafe, use `pre_exec` instead
Schedules a closure to be run just before the `exec` function is invoked.
This method is stable and usable, but it should be unsafe. To fix that, it got deprecated in favor of the unsafe [`pre_exec`](trait.commandext#tymethod.pre_exec).
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#185-227)### impl CommandExt for Command
rust Module std::os::linux Module std::os::linux
=====================
Available on **Linux** only.Linux-specific definitions.
Modules
-------
[net](net/index "std::os::linux::net mod")Experimental
Linux and Android-specific definitions for socket options.
[process](process/index "std::os::linux::process mod")Experimental
Linux-specific extensions to primitives in the [`std::process`](../../process/index) module.
[fs](fs/index "std::os::linux::fs mod")
Linux-specific extensions to primitives in the [`std::fs`](../../fs/index) module.
[raw](raw/index "std::os::linux::raw mod")Deprecated
Linux-specific raw type definitions.
rust Module std::os::linux::net Module std::os::linux::net
==========================
🔬This is a nightly-only experimental API. (`tcp_quickack` [#96256](https://github.com/rust-lang/rust/issues/96256))
Available on **Linux** only.Linux and Android-specific definitions for socket options.
Traits
------
[TcpStreamExt](trait.tcpstreamext "std::os::linux::net::TcpStreamExt trait")ExperimentalLinux or Android
Os-specific extensions for [`TcpStream`](../../../net/struct.tcpstream)
rust Trait std::os::linux::net::TcpStreamExt Trait std::os::linux::net::TcpStreamExt
=======================================
```
pub trait TcpStreamExt: Sealed {
fn set_quickack(&self, quickack: bool) -> Result<()>;
fn quickack(&self) -> Result<bool>;
}
```
🔬This is a nightly-only experimental API. (`tcp_quickack` [#96256](https://github.com/rust-lang/rust/issues/96256))
Available on **Linux and (Linux or Android)** only.Os-specific extensions for [`TcpStream`](../../../net/struct.tcpstream)
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/net/tcp.rs.html#36)#### fn set\_quickack(&self, quickack: bool) -> Result<()>
🔬This is a nightly-only experimental API. (`tcp_quickack` [#96256](https://github.com/rust-lang/rust/issues/96256))
Enable or disable `TCP_QUICKACK`.
This flag causes Linux to eagerly send ACKs rather than delaying them. Linux may reset this flag after further operations on the socket.
See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html) and [TCP delayed acknowledgement](https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment) for more information.
##### Examples
```
#![feature(tcp_quickack)]
use std::net::TcpStream;
use std::os::linux::net::TcpStreamExt;
let stream = TcpStream::connect("127.0.0.1:8080")
.expect("Couldn't connect to the server...");
stream.set_quickack(true).expect("set_quickack call failed");
```
[source](https://doc.rust-lang.org/src/std/os/net/tcp.rs.html#55)#### fn quickack(&self) -> Result<bool>
🔬This is a nightly-only experimental API. (`tcp_quickack` [#96256](https://github.com/rust-lang/rust/issues/96256))
Gets the value of the `TCP_QUICKACK` option on this socket.
For more information about this option, see [`TcpStreamExt::set_quickack`](trait.tcpstreamext#tymethod.set_quickack "TcpStreamExt::set_quickack").
##### Examples
```
#![feature(tcp_quickack)]
use std::net::TcpStream;
use std::os::linux::net::TcpStreamExt;
let stream = TcpStream::connect("127.0.0.1:8080")
.expect("Couldn't connect to the server...");
stream.set_quickack(true).expect("set_quickack call failed");
assert_eq!(stream.quickack().unwrap_or(false), true);
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/net/tcp.rs.html#62-70)### impl TcpStreamExt for TcpStream
rust Module std::os::linux::fs Module std::os::linux::fs
=========================
Available on **Linux** only.Linux-specific extensions to primitives in the [`std::fs`](../../../fs/index) module.
Traits
------
[MetadataExt](trait.metadataext "std::os::linux::fs::MetadataExt trait")
OS-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata).
rust Trait std::os::linux::fs::MetadataExt Trait std::os::linux::fs::MetadataExt
=====================================
```
pub trait MetadataExt {
Show 17 methods fn as_raw_stat(&self) -> &stat;
fn st_dev(&self) -> u64;
fn st_ino(&self) -> u64;
fn st_mode(&self) -> u32;
fn st_nlink(&self) -> u64;
fn st_uid(&self) -> u32;
fn st_gid(&self) -> u32;
fn st_rdev(&self) -> u64;
fn st_size(&self) -> u64;
fn st_atime(&self) -> i64;
fn st_atime_nsec(&self) -> i64;
fn st_mtime(&self) -> i64;
fn st_mtime_nsec(&self) -> i64;
fn st_ctime(&self) -> i64;
fn st_ctime_nsec(&self) -> i64;
fn st_blksize(&self) -> u64;
fn st_blocks(&self) -> u64;
}
```
Available on **Linux** only.OS-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata).
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#43)#### fn as\_raw\_stat(&self) -> &stat
👎Deprecated since 1.8.0: other methods of this trait are now preferred
Gain a reference to the underlying `stat` structure which contains the raw information returned by the OS.
The contents of the returned [`stat`](../raw/struct.stat) are **not** consistent across Unix platforms. The `os::unix::fs::MetadataExt` trait contains the cross-Unix abstractions contained within the raw stat.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let stat = meta.as_raw_stat();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#61)1.8.0 · #### fn st\_dev(&self) -> u64
Returns the device ID on which this file resides.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_dev());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#78)1.8.0 · #### fn st\_ino(&self) -> u64
Returns the inode number.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_ino());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#95)1.8.0 · #### fn st\_mode(&self) -> u32
Returns the file type and mode.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_mode());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#112)1.8.0 · #### fn st\_nlink(&self) -> u64
Returns the number of hard links to file.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_nlink());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#129)1.8.0 · #### fn st\_uid(&self) -> u32
Returns the user ID of the file owner.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_uid());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#146)1.8.0 · #### fn st\_gid(&self) -> u32
Returns the group ID of the file owner.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_gid());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#163)1.8.0 · #### fn st\_rdev(&self) -> u64
Returns the device ID that this file represents. Only relevant for special file.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_rdev());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#183)1.8.0 · #### fn st\_size(&self) -> u64
Returns the size of the file (if it is a regular file or a symbolic link) in bytes.
The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_size());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#200)1.8.0 · #### fn st\_atime(&self) -> i64
Returns the last access time of the file, in seconds since Unix Epoch.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_atime());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#219)1.8.0 · #### fn st\_atime\_nsec(&self) -> i64
Returns the last access time of the file, in nanoseconds since [`st_atime`](trait.metadataext#tymethod.st_atime).
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_atime_nsec());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#236)1.8.0 · #### fn st\_mtime(&self) -> i64
Returns the last modification time of the file, in seconds since Unix Epoch.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_mtime());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#255)1.8.0 · #### fn st\_mtime\_nsec(&self) -> i64
Returns the last modification time of the file, in nanoseconds since [`st_mtime`](trait.metadataext#tymethod.st_mtime).
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_mtime_nsec());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#272)1.8.0 · #### fn st\_ctime(&self) -> i64
Returns the last status change time of the file, in seconds since Unix Epoch.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_ctime());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#291)1.8.0 · #### fn st\_ctime\_nsec(&self) -> i64
Returns the last status change time of the file, in nanoseconds since [`st_ctime`](trait.metadataext#tymethod.st_ctime).
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_ctime_nsec());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#308)1.8.0 · #### fn st\_blksize(&self) -> u64
Returns the “preferred” block size for efficient filesystem I/O.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_blksize());
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#325)1.8.0 · #### fn st\_blocks(&self) -> u64
Returns the number of blocks allocated to the file, 512-byte units.
##### Examples
```
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
println!("{}", meta.st_blocks());
Ok(())
}
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/linux/fs.rs.html#329-397)### impl MetadataExt for Metadata
| programming_docs |
rust Type Definition std::os::linux::raw::off_t Type Definition std::os::linux::raw::off\_t
===========================================
```
pub type off_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Module std::os::linux::raw Module std::os::linux::raw
==========================
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.Linux-specific raw type definitions.
Structs
-------
[stat](struct.stat "std::os::linux::raw::stat struct")Deprecated
Type Definitions
----------------
[blkcnt\_t](type.blkcnt_t "std::os::linux::raw::blkcnt_t type")Deprecated
[blksize\_t](type.blksize_t "std::os::linux::raw::blksize_t type")Deprecated
[dev\_t](type.dev_t "std::os::linux::raw::dev_t type")Deprecated
[ino\_t](type.ino_t "std::os::linux::raw::ino_t type")Deprecated
[mode\_t](type.mode_t "std::os::linux::raw::mode_t type")Deprecated
[nlink\_t](type.nlink_t "std::os::linux::raw::nlink_t type")Deprecated
[off\_t](type.off_t "std::os::linux::raw::off_t type")Deprecated
[pthread\_t](type.pthread_t "std::os::linux::raw::pthread_t type")Deprecated
[time\_t](type.time_t "std::os::linux::raw::time_t type")Deprecated
rust Struct std::os::linux::raw::stat Struct std::os::linux::raw::stat
================================
```
#[repr(C)]pub struct stat {Show 18 fields
pub st_dev: u64,
pub st_ino: u64,
pub st_nlink: u64,
pub st_mode: u32,
pub st_uid: u32,
pub st_gid: u32,
pub __pad0: c_int,
pub st_rdev: u64,
pub st_size: i64,
pub st_blksize: i64,
pub st_blocks: i64,
pub st_atime: i64,
pub st_atime_nsec: c_long,
pub st_mtime: i64,
pub st_mtime_nsec: c_long,
pub st_ctime: i64,
pub st_ctime_nsec: c_long,
pub __unused: [c_long; 3],
}
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.Fields
------
`st_dev: [u64](../../../primitive.u64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_ino: [u64](../../../primitive.u64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_nlink: [u64](../../../primitive.u64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_mode: [u32](../../../primitive.u32)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_uid: [u32](../../../primitive.u32)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_gid: [u32](../../../primitive.u32)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`__pad0: [c\_int](../../raw/type.c_int "type std::os::raw::c_int")`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_rdev: [u64](../../../primitive.u64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_size: [i64](../../../primitive.i64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_blksize: [i64](../../../primitive.i64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_blocks: [i64](../../../primitive.i64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_atime: [i64](../../../primitive.i64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_atime_nsec: [c\_long](../../raw/type.c_long "type std::os::raw::c_long")`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_mtime: [i64](../../../primitive.i64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_mtime_nsec: [c\_long](../../raw/type.c_long "type std::os::raw::c_long")`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_ctime: [i64](../../../primitive.i64)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`st_ctime_nsec: [c\_long](../../raw/type.c_long "type std::os::raw::c_long")`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
`__unused: [[](../../../primitive.array)[c\_long](../../raw/type.c_long "type std::os::raw::c_long")[; 3]](../../../primitive.array)`
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/linux/raw.rs.html#326)### impl Clone for stat
[source](https://doc.rust-lang.org/src/std/os/linux/raw.rs.html#326)#### fn clone(&self) -> stat
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for stat
### impl Send for stat
### impl Sync for stat
### impl Unpin for stat
### impl UnwindSafe for stat
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Type Definition std::os::linux::raw::dev_t Type Definition std::os::linux::raw::dev\_t
===========================================
```
pub type dev_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Type Definition std::os::linux::raw::mode_t Type Definition std::os::linux::raw::mode\_t
============================================
```
pub type mode_t = u32;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Type Definition std::os::linux::raw::nlink_t Type Definition std::os::linux::raw::nlink\_t
=============================================
```
pub type nlink_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Type Definition std::os::linux::raw::time_t Type Definition std::os::linux::raw::time\_t
============================================
```
pub type time_t = i64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Type Definition std::os::linux::raw::ino_t Type Definition std::os::linux::raw::ino\_t
===========================================
```
pub type ino_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Type Definition std::os::linux::raw::blksize_t Type Definition std::os::linux::raw::blksize\_t
===============================================
```
pub type blksize_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Type Definition std::os::linux::raw::pthread_t Type Definition std::os::linux::raw::pthread\_t
===============================================
```
pub type pthread_t = c_ulong;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Type Definition std::os::linux::raw::blkcnt_t Type Definition std::os::linux::raw::blkcnt\_t
==============================================
```
pub type blkcnt_t = u64;
```
👎Deprecated since 1.8.0: these type aliases are no longer supported by the standard library, the `libc` crate on crates.io should be used instead for the correct definitions
Available on **Linux** only.
rust Module std::os::linux::process Module std::os::linux::process
==============================
🔬This is a nightly-only experimental API. (`linux_pidfd` [#82971](https://github.com/rust-lang/rust/issues/82971))
Available on **Linux** only.Linux-specific extensions to primitives in the [`std::process`](../../../process/index) module.
Structs
-------
[PidFd](struct.pidfd "std::os::linux::process::PidFd struct")Experimental
This type represents a file descriptor that refers to a process.
Traits
------
[ChildExt](trait.childext "std::os::linux::process::ChildExt trait")Experimental
Os-specific extensions for [`Child`](../../../process/struct.child)
[CommandExt](trait.commandext "std::os::linux::process::CommandExt trait")Experimental
Os-specific extensions for [`Command`](../../../process/struct.command)
rust Struct std::os::linux::process::PidFd Struct std::os::linux::process::PidFd
=====================================
```
pub struct PidFd { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`linux_pidfd` [#82971](https://github.com/rust-lang/rust/issues/82971))
Available on **Linux** only.This type represents a file descriptor that refers to a process.
A `PidFd` can be obtained by setting the corresponding option on [`Command`](../../../process/struct.command) with [`create_pidfd`](trait.commandext#tymethod.create_pidfd). Subsequently, the created pidfd can be retrieved from the [`Child`](../../../process/struct.child) by calling [`pidfd`](trait.childext#tymethod.pidfd) or [`take_pidfd`](trait.childext#tymethod.take_pidfd).
Example:
```
#![feature(linux_pidfd)]
use std::os::linux::process::{CommandExt, ChildExt};
use std::process::Command;
let mut child = Command::new("echo")
.create_pidfd(true)
.spawn()
.expect("Failed to spawn child");
let pidfd = child
.take_pidfd()
.expect("Failed to retrieve pidfd");
// The file descriptor will be closed when `pidfd` is dropped.
```
Refer to the man page of [`pidfd_open(2)`](https://man7.org/linux/man-pages/man2/pidfd_open.2.html) for further details.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#90-94)### impl AsFd for PidFd
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#91-93)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Available on **Unix** only.Borrows the file descriptor. [Read more](../../unix/io/trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#72-76)### impl AsRawFd for PidFd
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#73-75)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](../../unix/io/trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#49)### impl Debug for PidFd
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#49)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#96-100)### impl From<OwnedFd> for PidFd
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#97-99)#### fn from(fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#102-106)### impl From<PidFd> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#103-105)#### fn from(pid\_fd: PidFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#78-82)### impl FromRawFd for PidFd
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#79-81)#### unsafe fn from\_raw\_fd(fd: RawFd) -> Self
Available on **Unix** only.Constructs a new instance of `Self` from the given raw file descriptor. [Read more](../../unix/io/trait.fromrawfd#tymethod.from_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#84-88)### impl IntoRawFd for PidFd
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#85-87)#### fn into\_raw\_fd(self) -> RawFd
Available on **Unix** only.Consumes this object, returning the raw underlying file descriptor. [Read more](../../unix/io/trait.intorawfd#tymethod.into_raw_fd)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for PidFd
### impl Send for PidFd
### impl Sync for PidFd
### impl Unpin for PidFd
### impl UnwindSafe for PidFd
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Trait std::os::linux::process::ChildExt Trait std::os::linux::process::ChildExt
=======================================
```
pub trait ChildExt: Sealed {
fn pidfd(&self) -> Result<&PidFd>;
fn take_pidfd(&mut self) -> Result<PidFd>;
}
```
🔬This is a nightly-only experimental API. (`linux_pidfd` [#82971](https://github.com/rust-lang/rust/issues/82971))
Available on **Linux** only.Os-specific extensions for [`Child`](../../../process/struct.child)
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#123)#### fn pidfd(&self) -> Result<&PidFd>
🔬This is a nightly-only experimental API. (`linux_pidfd` [#82971](https://github.com/rust-lang/rust/issues/82971))
Obtains a reference to the [`PidFd`](struct.pidfd "PidFd") created for this [`Child`](../../../process/struct.child), if available.
A pidfd will only be available if its creation was requested with [`create_pidfd`](trait.commandext#tymethod.create_pidfd) when the corresponding [`Command`](../../../process/struct.command) was created.
Even if requested, a pidfd may not be available due to an older version of Linux being in use, or if some other error occurred.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#136)#### fn take\_pidfd(&mut self) -> Result<PidFd>
🔬This is a nightly-only experimental API. (`linux_pidfd` [#82971](https://github.com/rust-lang/rust/issues/82971))
Takes ownership of the [`PidFd`](struct.pidfd "PidFd") created for this [`Child`](../../../process/struct.child), if available.
A pidfd will only be available if its creation was requested with [`create_pidfd`](trait.commandext#tymethod.create_pidfd) when the corresponding [`Command`](../../../process/struct.command) was created.
Even if requested, a pidfd may not be available due to an older version of Linux being in use, or if some other error occurred.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/sys/unix/process/process_unix.rs.html#820-834)### impl ChildExt for Child
rust Trait std::os::linux::process::CommandExt Trait std::os::linux::process::CommandExt
=========================================
```
pub trait CommandExt: Sealed {
fn create_pidfd(&mut self, val: bool) -> &mut Command;
}
```
🔬This is a nightly-only experimental API. (`linux_pidfd` [#82971](https://github.com/rust-lang/rust/issues/82971))
Available on **Linux** only.Os-specific extensions for [`Command`](../../../process/struct.command)
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#157)#### fn create\_pidfd(&mut self, val: bool) -> &mut Command
🔬This is a nightly-only experimental API. (`linux_pidfd` [#82971](https://github.com/rust-lang/rust/issues/82971))
Sets whether a [`PidFd`](struct.pidfd) should be created for the [`Child`](../../../process/struct.child) spawned by this [`Command`](../../../process/struct.command). By default, no pidfd will be created.
The pidfd can be retrieved from the child with [`pidfd`](trait.childext#tymethod.pidfd) or [`take_pidfd`](trait.childext#tymethod.take_pidfd).
A pidfd will only be created if it is possible to do so in a guaranteed race-free manner (e.g. if the `clone3` system call is supported). Otherwise, [`pidfd`](trait.childext#tymethod.pidfd) will return an error.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#160-165)### impl CommandExt for Command
rust Module std::os::wasi Module std::os::wasi
====================
Available on **WASI** only.Platform-specific extensions to `std` for the WebAssembly System Interface (WASI).
Provides access to platform-level information on WASI, and exposes WASI-specific functions that would otherwise be inappropriate as part of the core `std` library.
It exposes more ways to deal with platform-specific strings (`OsStr`, `OsString`), allows to set permissions more granularly, extract low-level file descriptors from files and sockets, and has platform-specific helpers for spawning processes.
Examples
--------
```
use std::fs::File;
use std::os::wasi::prelude::*;
fn main() -> std::io::Result<()> {
let f = File::create("foo.txt")?;
let fd = f.as_raw_fd();
// use fd with native WASI bindings
Ok(())
}
```
Modules
-------
[fs](fs/index "std::os::wasi::fs mod")Experimental
WASI-specific extensions to primitives in the [`std::fs`](../../fs/index) module.
[net](net/index "std::os::wasi::net mod")Experimental
WASI-specific networking functionality
[ffi](ffi/index "std::os::wasi::ffi mod")
WASI-specific extensions to primitives in the [`std::ffi`](../../ffi/index) module
[io](io/index "std::os::wasi::io mod")
WASI-specific extensions to general I/O primitives.
[prelude](prelude/index "std::os::wasi::prelude mod")
A prelude for conveniently writing platform-specific code.
rust Module std::os::wasi::net Module std::os::wasi::net
=========================
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific networking functionality
Traits
------
[TcpListenerExt](trait.tcplistenerext "std::os::wasi::net::TcpListenerExt trait")Experimental
WASI-specific extensions to [`std::net::TcpListener`](../../../net/struct.tcplistener).
rust Trait std::os::wasi::net::TcpListenerExt Trait std::os::wasi::net::TcpListenerExt
========================================
```
pub trait TcpListenerExt {
fn sock_accept(&self, flags: u16) -> Result<u32>;
}
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific extensions to [`std::net::TcpListener`](../../../net/struct.tcplistener).
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/net/mod.rs.html#16)#### fn sock\_accept(&self, flags: u16) -> Result<u32>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Accept a socket.
This corresponds to the `sock_accept` syscall.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/net/mod.rs.html#19-23)### impl TcpListenerExt for TcpListener
rust Module std::os::wasi::io Module std::os::wasi::io
========================
Available on **WASI** only.WASI-specific extensions to general I/O primitives.
Structs
-------
[BorrowedFd](struct.borrowedfd "std::os::wasi::io::BorrowedFd struct")
A borrowed file descriptor.
[OwnedFd](struct.ownedfd "std::os::wasi::io::OwnedFd struct")
An owned file descriptor.
Traits
------
[AsFd](trait.asfd "std::os::wasi::io::AsFd trait")
A trait to borrow the file descriptor from an underlying object.
[AsRawFd](trait.asrawfd "std::os::wasi::io::AsRawFd trait")
A trait to extract the raw file descriptor from an underlying object.
[FromRawFd](trait.fromrawfd "std::os::wasi::io::FromRawFd trait")
A trait to express the ability to construct an object from a raw file descriptor.
[IntoRawFd](trait.intorawfd "std::os::wasi::io::IntoRawFd trait")
A trait to express the ability to consume an object and acquire ownership of its raw file descriptor.
Type Definitions
----------------
[RawFd](type.rawfd "std::os::wasi::io::RawFd type")
Raw file descriptors.
rust Type Definition std::os::wasi::io::RawFd Type Definition std::os::wasi::io::RawFd
========================================
```
pub type RawFd = c_int;
```
Available on **WASI** only.Raw file descriptors.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#139-144)1.48.0 · ### impl AsRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#141-143)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](../../unix/io/trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#153-158)1.48.0 · ### impl FromRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#155-157)#### unsafe fn from\_raw\_fd(fd: RawFd) -> RawFd
Available on **Unix** only.Constructs a new instance of `Self` from the given raw file descriptor. [Read more](../../unix/io/trait.fromrawfd#tymethod.from_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#146-151)1.48.0 · ### impl IntoRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#148-150)#### fn into\_raw\_fd(self) -> RawFd
Available on **Unix** only.Consumes this object, returning the raw underlying file descriptor. [Read more](../../unix/io/trait.intorawfd#tymethod.into_raw_fd)
rust Struct std::os::wasi::io::BorrowedFd Struct std::os::wasi::io::BorrowedFd
====================================
```
#[repr(transparent)]pub struct BorrowedFd<'fd> { /* private fields */ }
```
Available on **WASI** only.A borrowed file descriptor.
This has a lifetime parameter to tie it to the lifetime of something that owns the file descriptor.
This uses `repr(transparent)` and has the representation of a host file descriptor, so it can be used in FFI in places where a file descriptor is passed as an argument, it is not captured or consumed, and it never has the value `-1`.
This type’s `.to_owned()` implementation returns another `BorrowedFd` rather than an `OwnedFd`. It just makes a trivial copy of the raw file descriptor, which is then borrowed under the same lifetime.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#62-77)### impl BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#72-76)const: 1.63.0 · #### pub const unsafe fn borrow\_raw(fd: RawFd) -> Self
Return a `BorrowedFd` holding the given raw file descriptor.
##### Safety
The resource pointed to by `fd` must remain open for the duration of the returned `BorrowedFd`, and it must not have the value `-1`.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#88-122)### impl BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#93-110)#### pub fn try\_clone\_to\_owned(&self) -> Result<OwnedFd>
Creates a new `OwnedFd` instance that shares the same underlying file description as the existing `BorrowedFd` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#240-245)### impl AsFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#242-244)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Available on **Unix** only.Borrows the file descriptor. [Read more](../../unix/io/trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#125-130)### impl AsRawFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#127-129)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](../../unix/io/trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#28)### impl<'fd> Clone for BorrowedFd<'fd>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#28)#### fn clone(&self) -> BorrowedFd<'fd>
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#182-186)### impl Debug for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#183-185)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#28)### impl<'fd> Copy for BorrowedFd<'fd>
Auto Trait Implementations
--------------------------
### impl<'fd> RefUnwindSafe for BorrowedFd<'fd>
### impl<'fd> Send for BorrowedFd<'fd>
### impl<'fd> Sync for BorrowedFd<'fd>
### impl<'fd> Unpin for BorrowedFd<'fd>
### impl<'fd> UnwindSafe for BorrowedFd<'fd>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::os::wasi::io::OwnedFd Struct std::os::wasi::io::OwnedFd
=================================
```
#[repr(transparent)]pub struct OwnedFd { /* private fields */ }
```
Available on **WASI** only.An owned file descriptor.
This closes the file descriptor on drop.
This uses `repr(transparent)` and has the representation of a host file descriptor, so it can be used in FFI in places where a file descriptor is passed as a consumed argument or returned as an owned value, and it never has the value `-1`.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#79-86)### impl OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#83-85)#### pub fn try\_clone(&self) -> Result<Self>
Creates a new `OwnedFd` instance that shares the same underlying file description as the existing `OwnedFd` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#248-256)### impl AsFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#250-255)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Available on **Unix** only.Borrows the file descriptor. [Read more](../../unix/io/trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#133-138)### impl AsRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#135-137)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](../../unix/io/trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#189-193)### impl Debug for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#190-192)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#167-179)### impl Drop for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#169-178)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#454-459)### impl From<ChildStderr> for OwnedFd
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#456-458)#### fn from(child\_stderr: ChildStderr) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#422-427)### impl From<ChildStdin> for OwnedFd
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#424-426)#### fn from(child\_stdin: ChildStdin) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#438-443)### impl From<ChildStdout> for OwnedFd
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#440-442)#### fn from(child\_stdout: ChildStdout) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#267-272)### impl From<File> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#269-271)#### fn from(file: File) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#275-280)### impl From<OwnedFd> for File
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#277-279)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#96-100)### impl From<OwnedFd> for PidFd
Available on **Linux** only.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#97-99)#### fn from(fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#356-363)### impl From<OwnedFd> for Stdio
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#358-362)#### fn from(fd: OwnedFd) -> Stdio
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#325-332)### impl From<OwnedFd> for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#327-331)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#299-306)### impl From<OwnedFd> for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#301-305)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#351-358)### impl From<OwnedFd> for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#353-357)#### fn from(owned\_fd: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1007-1012)### impl From<OwnedFd> for UnixDatagram
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1009-1011)#### fn from(owned: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#318-323)### impl From<OwnedFd> for UnixListener
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#320-322)#### fn from(fd: OwnedFd) -> UnixListener
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#731-736)### impl From<OwnedFd> for UnixStream
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#733-735)#### fn from(owned: OwnedFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#102-106)### impl From<PidFd> for OwnedFd
Available on **Linux** only.
[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#103-105)#### fn from(pid\_fd: PidFd) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#317-322)### impl From<TcpListener> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#319-321)#### fn from(tcp\_listener: TcpListener) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#291-296)### impl From<TcpStream> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#293-295)#### fn from(tcp\_stream: TcpStream) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#343-348)### impl From<UdpSocket> for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#345-347)#### fn from(udp\_socket: UdpSocket) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#999-1004)### impl From<UnixDatagram> for OwnedFd
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#1001-1003)#### fn from(unix\_datagram: UnixDatagram) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#326-331)### impl From<UnixListener> for OwnedFd
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#328-330)#### fn from(listener: UnixListener) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#723-728)### impl From<UnixStream> for OwnedFd
Available on **Unix** only.
[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#725-727)#### fn from(unix\_stream: UnixStream) -> OwnedFd
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#151-164)### impl FromRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#159-163)#### unsafe fn from\_raw\_fd(fd: RawFd) -> Self
Available on **Unix** only.
Constructs a new instance of `Self` from the given raw file descriptor.
##### Safety
The resource pointed to by `fd` must be open and suitable for assuming ownership. The resource must not require any cleanup other than `close`.
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#141-148)### impl IntoRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#143-147)#### fn into\_raw\_fd(self) -> RawFd
Available on **Unix** only.Consumes this object, returning the raw underlying file descriptor. [Read more](../../unix/io/trait.intorawfd#tymethod.into_raw_fd)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for OwnedFd
### impl Send for OwnedFd
### impl Sync for OwnedFd
### impl Unpin for OwnedFd
### impl UnwindSafe for OwnedFd
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Trait std::os::wasi::io::AsFd Trait std::os::wasi::io::AsFd
=============================
```
pub trait AsFd {
fn as_fd(&self) -> BorrowedFd<'_>;
}
```
Available on **WASI** only.A trait to borrow the file descriptor from an underlying object.
This is only available on unix platforms and must be imported in order to call the method. Windows platforms have a corresponding `AsHandle` and `AsSocket` set of traits.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#220)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Borrows the file descriptor.
##### Example
```
use std::fs::File;
let mut f = File::open("foo.txt")?;
let borrowed_fd: BorrowedFd<'_> = f.as_fd();
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#259-264)### impl AsFd for File
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#128-133)### impl AsFd for Stderr
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#96-101)### impl AsFd for Stdin
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#112-117)### impl AsFd for Stdout
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#309-314)### impl AsFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#283-288)### impl AsFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#335-340)### impl AsFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#446-451)### impl AsFd for ChildStderr
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#414-419)### impl AsFd for ChildStdin
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#430-435)### impl AsFd for ChildStdout
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#90-94)### impl AsFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#240-245)### impl AsFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#248-256)### impl AsFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#991-996)### impl AsFd for UnixDatagram
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#310-315)### impl AsFd for UnixListener
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#715-720)### impl AsFd for UnixStream
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#136-141)### impl<'a> AsFd for StderrLock<'a>
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#104-109)### impl<'a> AsFd for StdinLock<'a>
[source](https://doc.rust-lang.org/src/std/sys/unix/stdio.rs.html#120-125)### impl<'a> AsFd for StdoutLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#224-229)### impl<T: AsFd> AsFd for &T
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#232-237)### impl<T: AsFd> AsFd for &mut T
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#384-389)1.64.0 · ### impl<T: AsFd> AsFd for Box<T>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#376-381)1.64.0 · ### impl<T: AsFd> AsFd for Arc<T>
This impl allows implementing traits that require `AsFd` on Arc.
```
use std::net::UdpSocket;
use std::sync::Arc;
trait MyTrait: AsFd {}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}
```
rust Trait std::os::wasi::io::IntoRawFd Trait std::os::wasi::io::IntoRawFd
==================================
```
pub trait IntoRawFd {
fn into_raw_fd(self) -> RawFd;
}
```
Available on **WASI** only.A trait to express the ability to consume an object and acquire ownership of its raw file descriptor.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#135)#### fn into\_raw\_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor.
This function is typically used to **transfer ownership** of the underlying file descriptor to the caller. When used in this way, callers are then the unique owners of the file descriptor and must close it once it’s no longer needed.
However, transferring ownership is not strictly required. Use a [`Into<OwnedFd>::into`](../../../convert/trait.into#tymethod.into "Into<OwnedFd>::into") implementation for an API which strictly transfers ownership.
##### Example
```
use std::fs::File;
#[cfg(unix)]
use std::os::unix::io::{IntoRawFd, RawFd};
#[cfg(target_os = "wasi")]
use std::os::wasi::io::{IntoRawFd, RawFd};
let f = File::open("foo.txt")?;
#[cfg(any(unix, target_os = "wasi"))]
let raw_fd: RawFd = f.into_raw_fd();
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#175-180)### impl IntoRawFd for File
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#46)### impl IntoRawFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#46)### impl IntoRawFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#46)### impl IntoRawFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#406-411)### impl IntoRawFd for ChildStderr
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#390-395)### impl IntoRawFd for ChildStdin
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#398-403)### impl IntoRawFd for ChildStdout
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#84-88)### impl IntoRawFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#141-148)1.63.0 · ### impl IntoRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#983-988)1.10.0 · ### impl IntoRawFd for UnixDatagram
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#302-307)1.10.0 · ### impl IntoRawFd for UnixListener
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#707-712)1.10.0 · ### impl IntoRawFd for UnixStream
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#146-151)1.48.0 · ### impl IntoRawFd for RawFd
rust Trait std::os::wasi::io::AsRawFd Trait std::os::wasi::io::AsRawFd
================================
```
pub trait AsRawFd {
fn as_raw_fd(&self) -> RawFd;
}
```
Available on **WASI** only.A trait to extract the raw file descriptor from an underlying object.
This is only available on unix and WASI platforms and must be imported in order to call the method. Windows platforms have a corresponding `AsRawHandle` and `AsRawSocket` set of traits.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#57)#### fn as\_raw\_fd(&self) -> RawFd
Extracts the raw file descriptor.
This function is typically used to **borrow** an owned file descriptor. When used in this way, this method does **not** pass ownership of the raw file descriptor to the caller, and the file descriptor is only guaranteed to be valid while the original object has not yet been destroyed.
However, borrowing is not strictly required. See [`AsFd::as_fd`](../../unix/io/trait.asfd#tymethod.as_fd "AsFd::as_fd") for an API which strictly borrows a file descriptor.
##### Example
```
use std::fs::File;
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(target_os = "wasi")]
use std::os::wasi::io::{AsRawFd, RawFd};
let mut f = File::open("foo.txt")?;
// Note that `raw_fd` is only valid as long as `f` exists.
#[cfg(any(unix, target_os = "wasi"))]
let raw_fd: RawFd = f.as_raw_fd();
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#161-166)### impl AsRawFd for File
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#199-204)1.21.0 · ### impl AsRawFd for Stderr
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#183-188)1.21.0 · ### impl AsRawFd for Stdin
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#191-196)1.21.0 · ### impl AsRawFd for Stdout
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#17)### impl AsRawFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#17)### impl AsRawFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#17)### impl AsRawFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#382-387)1.2.0 · ### impl AsRawFd for ChildStderr
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#366-371)1.2.0 · ### impl AsRawFd for ChildStdin
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#374-379)1.2.0 · ### impl AsRawFd for ChildStdout
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#72-76)### impl AsRawFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#125-130)1.63.0 · ### impl AsRawFd for BorrowedFd<'\_>
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#133-138)1.63.0 · ### impl AsRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#967-972)1.10.0 · ### impl AsRawFd for UnixDatagram
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#286-291)1.10.0 · ### impl AsRawFd for UnixListener
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#691-696)1.10.0 · ### impl AsRawFd for UnixStream
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#139-144)1.48.0 · ### impl AsRawFd for RawFd
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#223-228)1.35.0 · ### impl<'a> AsRawFd for StderrLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#207-212)1.35.0 · ### impl<'a> AsRawFd for StdinLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#215-220)1.35.0 · ### impl<'a> AsRawFd for StdoutLock<'a>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#254-259)1.63.0 · ### impl<T: AsRawFd> AsRawFd for Box<T>
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#246-251)1.63.0 · ### impl<T: AsRawFd> AsRawFd for Arc<T>
This impl allows implementing traits that require `AsRawFd` on Arc.
```
use std::net::UdpSocket;
use std::sync::Arc;
trait MyTrait: AsRawFd {
}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}
```
rust Trait std::os::wasi::io::FromRawFd Trait std::os::wasi::io::FromRawFd
==================================
```
pub trait FromRawFd {
unsafe fn from_raw_fd(fd: RawFd) -> Self;
}
```
Available on **WASI** only.A trait to express the ability to construct an object from a raw file descriptor.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#101)#### unsafe fn from\_raw\_fd(fd: RawFd) -> Self
Constructs a new instance of `Self` from the given raw file descriptor.
This function is typically used to **consume ownership** of the specified file descriptor. When used in this way, the returned object will take responsibility for closing it when the object goes out of scope.
However, consuming ownership is not strictly required. Use a [`From<OwnedFd>::from`](../../../convert/trait.from#tymethod.from "From<OwnedFd>::from") implementation for an API which strictly consumes ownership.
##### Safety
The `fd` passed in must be a valid and open file descriptor.
##### Example
```
use std::fs::File;
#[cfg(unix)]
use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
#[cfg(target_os = "wasi")]
use std::os::wasi::io::{FromRawFd, IntoRawFd, RawFd};
let f = File::open("foo.txt")?;
let raw_fd: RawFd = f.into_raw_fd();
// SAFETY: no other functions should call `from_raw_fd`, so there
// is only one owner for the file descriptor.
let f = unsafe { File::from_raw_fd(raw_fd) };
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#168-173)### impl FromRawFd for File
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#33)### impl FromRawFd for TcpListener
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#33)### impl FromRawFd for TcpStream
[source](https://doc.rust-lang.org/src/std/os/fd/net.rs.html#33)### impl FromRawFd for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/unix/process.rs.html#346-353)1.2.0 · ### impl FromRawFd for Stdio
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/linux/process.rs.html#78-82)### impl FromRawFd for PidFd
Available on **Linux** only.[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#151-164)1.63.0 · ### impl FromRawFd for OwnedFd
[source](https://doc.rust-lang.org/src/std/os/unix/net/datagram.rs.html#975-980)1.10.0 · ### impl FromRawFd for UnixDatagram
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/listener.rs.html#294-299)1.10.0 · ### impl FromRawFd for UnixListener
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/unix/net/stream.rs.html#699-704)1.10.0 · ### impl FromRawFd for UnixStream
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#153-158)1.48.0 · ### impl FromRawFd for RawFd
rust Trait std::os::wasi::ffi::OsStringExt Trait std::os::wasi::ffi::OsStringExt
=====================================
```
pub trait OsStringExt: Sealed {
fn from_vec(vec: Vec<u8>) -> Self;
fn into_vec(self) -> Vec<u8>;
}
```
Notable traits for [Vec](../../../vec/struct.vec "struct std::vec::Vec")<[u8](../../../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Available on **WASI** only.Platform-specific extensions to [`OsString`](../../../ffi/struct.osstring "OsString").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/up/unix/ffi/os_str.rs.html#20)#### fn from\_vec(vec: Vec<u8>) -> Self
Creates an [`OsString`](../../../ffi/struct.osstring "OsString") from a byte vector.
See the module documentation for an example.
[source](https://doc.rust-lang.org/src/std/os/wasi/up/unix/ffi/os_str.rs.html#26)#### fn into\_vec(self) -> Vec<u8>
Notable traits for [Vec](../../../vec/struct.vec "struct std::vec::Vec")<[u8](../../../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Yields the underlying byte vector of this [`OsString`](../../../ffi/struct.osstring "OsString").
See the module documentation for an example.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/up/unix/ffi/os_str.rs.html#30-39)### impl OsStringExt for OsString
rust Module std::os::wasi::ffi Module std::os::wasi::ffi
=========================
Available on **WASI** only.WASI-specific extensions to primitives in the [`std::ffi`](../../../ffi/index) module
Traits
------
[OsStrExt](trait.osstrext "std::os::wasi::ffi::OsStrExt trait")
Platform-specific extensions to [`OsStr`](../../../ffi/struct.osstr "OsStr").
[OsStringExt](trait.osstringext "std::os::wasi::ffi::OsStringExt trait")
Platform-specific extensions to [`OsString`](../../../ffi/struct.osstring "OsString").
rust Trait std::os::wasi::ffi::OsStrExt Trait std::os::wasi::ffi::OsStrExt
==================================
```
pub trait OsStrExt: Sealed {
fn from_bytes(slice: &[u8]) -> &Self;
fn as_bytes(&self) -> &[u8];
}
```
Notable traits for &[[u8](../../../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Available on **WASI** only.Platform-specific extensions to [`OsStr`](../../../ffi/struct.osstr "OsStr").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/up/unix/ffi/os_str.rs.html#51)#### fn from\_bytes(slice: &[u8]) -> &Self
Creates an [`OsStr`](../../../ffi/struct.osstr "OsStr") from a byte slice.
See the module documentation for an example.
[source](https://doc.rust-lang.org/src/std/os/wasi/up/unix/ffi/os_str.rs.html#57)#### fn as\_bytes(&self) -> &[u8]
Notable traits for &[[u8](../../../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Gets the underlying byte view of the [`OsStr`](../../../ffi/struct.osstr "OsStr") slice.
See the module documentation for an example.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/up/unix/ffi/os_str.rs.html#61-70)### impl OsStrExt for OsStr
rust Module std::os::wasi::prelude Module std::os::wasi::prelude
=============================
Available on **WASI** only.A prelude for conveniently writing platform-specific code.
Includes all extension traits, and some important type definitions.
Re-exports
----------
`pub use super::ffi::[OsStrExt](../ffi/trait.osstrext "trait std::os::wasi::ffi::OsStrExt");`
`pub use super::ffi::[OsStringExt](../ffi/trait.osstringext "trait std::os::wasi::ffi::OsStringExt");`
`pub use super::fs::[FileTypeExt](../fs/trait.filetypeext "trait std::os::wasi::fs::FileTypeExt");`
Experimental
`pub use super::fs::[DirEntryExt](../fs/trait.direntryext "trait std::os::wasi::fs::DirEntryExt");`
Experimental
`pub use super::fs::[FileExt](../fs/trait.fileext "trait std::os::wasi::fs::FileExt");`
Experimental
`pub use super::fs::[MetadataExt](../fs/trait.metadataext "trait std::os::wasi::fs::MetadataExt");`
Experimental
`pub use super::fs::[OpenOptionsExt](../fs/trait.openoptionsext "trait std::os::wasi::fs::OpenOptionsExt");`
Experimental
`pub use super::io::[AsFd](../../unix/io/trait.asfd "trait std::os::unix::io::AsFd");`
`pub use super::io::[AsRawFd](../../unix/io/trait.asrawfd "trait std::os::unix::io::AsRawFd");`
`pub use super::io::[BorrowedFd](../../unix/io/struct.borrowedfd "struct std::os::unix::io::BorrowedFd");`
`pub use super::io::[FromRawFd](../../unix/io/trait.fromrawfd "trait std::os::unix::io::FromRawFd");`
`pub use super::io::[IntoRawFd](../../unix/io/trait.intorawfd "trait std::os::unix::io::IntoRawFd");`
`pub use super::io::[OwnedFd](../../unix/io/struct.ownedfd "struct std::os::unix::io::OwnedFd");`
`pub use super::io::[RawFd](../../unix/io/type.rawfd "type std::os::unix::io::RawFd");`
rust Trait std::os::wasi::fs::FileTypeExt Trait std::os::wasi::fs::FileTypeExt
====================================
```
pub trait FileTypeExt {
fn is_block_device(&self) -> bool;
fn is_char_device(&self) -> bool;
fn is_socket_dgram(&self) -> bool;
fn is_socket_stream(&self) -> bool;
fn is_socket(&self) -> bool { ... }
}
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific extensions for [`fs::FileType`](../../../fs/struct.filetype "fs::FileType").
Adds support for special WASI file types such as block/character devices, pipes, and sockets.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#460)#### fn is\_block\_device(&self) -> bool
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns `true` if this file type is a block device.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#462)#### fn is\_char\_device(&self) -> bool
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns `true` if this file type is a character device.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#464)#### fn is\_socket\_dgram(&self) -> bool
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns `true` if this file type is a socket datagram.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#466)#### fn is\_socket\_stream(&self) -> bool
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns `true` if this file type is a socket stream.
Provided Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#468-470)#### fn is\_socket(&self) -> bool
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns `true` if this file type is any type of socket.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#473-486)### impl FileTypeExt for FileType
| programming_docs |
rust Module std::os::wasi::fs Module std::os::wasi::fs
========================
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific extensions to primitives in the [`std::fs`](../../../fs/index) module.
Traits
------
[DirEntryExt](trait.direntryext "std::os::wasi::fs::DirEntryExt trait")Experimental
WASI-specific extension methods for [`fs::DirEntry`](../../../fs/struct.direntry "fs::DirEntry").
[FileExt](trait.fileext "std::os::wasi::fs::FileExt trait")Experimental
WASI-specific extensions to [`File`](../../../fs/struct.file "File").
[FileTypeExt](trait.filetypeext "std::os::wasi::fs::FileTypeExt trait")Experimental
WASI-specific extensions for [`fs::FileType`](../../../fs/struct.filetype "fs::FileType").
[MetadataExt](trait.metadataext "std::os::wasi::fs::MetadataExt trait")Experimental
WASI-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata "fs::Metadata").
[OpenOptionsExt](trait.openoptionsext "std::os::wasi::fs::OpenOptionsExt trait")Experimental
WASI-specific extensions to [`fs::OpenOptions`](../../../fs/struct.openoptions "fs::OpenOptions").
Functions
---------
[link](fn.link "std::os::wasi::fs::link fn")Experimental
Create a hard link.
[rename](fn.rename "std::os::wasi::fs::rename fn")Experimental
Rename a file or directory.
[symlink](fn.symlink "std::os::wasi::fs::symlink fn")Experimental
Create a symbolic link.
[symlink\_path](fn.symlink_path "std::os::wasi::fs::symlink_path fn")Experimental
Create a symbolic link.
rust Function std::os::wasi::fs::link Function std::os::wasi::fs::link
================================
```
pub fn link<P: AsRef<Path>, U: AsRef<Path>>( old_fd: &File, old_flags: u32, old_path: P, new_fd: &File, new_path: U) -> Result<()>
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.Create a hard link.
This corresponds to the `path_link` syscall.
rust Function std::os::wasi::fs::symlink Function std::os::wasi::fs::symlink
===================================
```
pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>( old_path: P, fd: &File, new_path: U) -> Result<()>
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.Create a symbolic link.
This corresponds to the `path_symlink` syscall.
rust Trait std::os::wasi::fs::DirEntryExt Trait std::os::wasi::fs::DirEntryExt
====================================
```
pub trait DirEntryExt {
fn ino(&self) -> u64;
}
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific extension methods for [`fs::DirEntry`](../../../fs/struct.direntry "fs::DirEntry").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#491)#### fn ino(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the underlying `d_ino` field of the `dirent_t`
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#494-498)### impl DirEntryExt for DirEntry
rust Trait std::os::wasi::fs::FileExt Trait std::os::wasi::fs::FileExt
================================
```
pub trait FileExt {
Show 16 methods fn read_vectored_at( &self, bufs: &mut [IoSliceMut<'_>], offset: u64 ) -> Result<usize>;
fn write_vectored_at( &self, bufs: &[IoSlice<'_>], offset: u64 ) -> Result<usize>;
fn tell(&self) -> Result<u64>;
fn fdstat_set_flags(&self, flags: u16) -> Result<()>;
fn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> Result<()>;
fn advise(&self, offset: u64, len: u64, advice: u8) -> Result<()>;
fn allocate(&self, offset: u64, len: u64) -> Result<()>;
fn create_directory<P: AsRef<Path>>(&self, dir: P) -> Result<()>;
fn read_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>;
fn metadata_at<P: AsRef<Path>>( &self, lookup_flags: u32, path: P ) -> Result<Metadata>;
fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn remove_directory<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize> { ... }
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()> { ... }
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize> { ... }
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()> { ... }
}
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific extensions to [`File`](../../../fs/struct.file "File").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#46)#### fn read\_vectored\_at( &self, bufs: &mut [IoSliceMut<'\_>], offset: u64) -> Result<usize>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Reads a number of bytes starting from a given offset.
Returns the number of bytes read.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Note that similar to [`File::read_vectored`](../../../fs/struct.file#method.read_vectored "File::read_vectored"), it is not an error to return with a short read.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#129)#### fn write\_vectored\_at(&self, bufs: &[IoSlice<'\_>], offset: u64) -> Result<usize>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Writes a number of bytes starting from a given offset.
Returns the number of bytes written.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.
Note that similar to [`File::write_vectored`](../../../fs/struct.file#method.write_vectored "File::write_vectored"), it is not an error to return a short write.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#176)#### fn tell(&self) -> Result<u64>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the current position within the file.
This corresponds to the `fd_tell` syscall and is similar to `seek` where you offset 0 bytes from the current position.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#181)#### fn fdstat\_set\_flags(&self, flags: u16) -> Result<()>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Adjust the flags associated with this file.
This corresponds to the `fd_fdstat_set_flags` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#186)#### fn fdstat\_set\_rights(&self, rights: u64, inheriting: u64) -> Result<()>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Adjust the rights associated with this file.
This corresponds to the `fd_fdstat_set_rights` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#191)#### fn advise(&self, offset: u64, len: u64, advice: u8) -> Result<()>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Provide file advisory information on a file descriptor.
This corresponds to the `fd_advise` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#196)#### fn allocate(&self, offset: u64, len: u64) -> Result<()>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Force the allocation of space in a file.
This corresponds to the `fd_allocate` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#201)#### fn create\_directory<P: AsRef<Path>>(&self, dir: P) -> Result<()>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Create a directory.
This corresponds to the `path_create_directory` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#206)#### fn read\_link<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Read the contents of a symbolic link.
This corresponds to the `path_readlink` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#211)#### fn metadata\_at<P: AsRef<Path>>( &self, lookup\_flags: u32, path: P) -> Result<Metadata>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Return the attributes of a file or directory.
This corresponds to the `path_filestat_get` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#216)#### fn remove\_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Unlink a file.
This corresponds to the `path_unlink_file` syscall.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#221)#### fn remove\_directory<P: AsRef<Path>>(&self, path: P) -> Result<()>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Remove a directory.
This corresponds to the `path_remove_directory` syscall.
Provided Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#30-33)#### fn read\_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Reads a number of bytes starting from a given offset.
Returns the number of bytes read.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Note that similar to [`File::read`](../../../fs/struct.file#method.read "File::read"), it is not an error to return with a short read.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#76-94)1.33.0 · #### fn read\_exact\_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
Reads the exact number of byte required to fill `buf` from the given offset.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
Similar to [`Read::read_exact`](../../../io/trait.read#method.read_exact "Read::read_exact") but uses [`read_at`](trait.fileext#method.read_at) instead of `read`.
##### Errors
If this function encounters an error of the kind [`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") then the error is ignored and the operation will continue.
If this function encounters an “end of file” before completely filling the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`](../../../io/enum.errorkind#variant.UnexpectedEof "io::ErrorKind::UnexpectedEof"). The contents of `buf` are unspecified in this case.
If any other read error is encountered then this function immediately returns. The contents of `buf` are unspecified in this case.
If this function returns an error, it is unspecified how many bytes it has read, but it will never read more than would be necessary to completely fill the buffer.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#110-113)#### fn write\_at(&self, buf: &[u8], offset: u64) -> Result<usize>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Writes a number of bytes starting from a given offset.
Returns the number of bytes written.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.
Note that similar to [`File::write`](../../../fs/struct.file#method.write "File::write"), it is not an error to return a short write.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#152-170)1.33.0 · #### fn write\_all\_at(&self, buf: &[u8], offset: u64) -> Result<()>
Attempts to write an entire buffer starting from a given offset.
The offset is relative to the start of the file and thus independent from the current cursor.
The current file cursor is not affected by this function.
This method will continuously call [`write_at`](trait.fileext#method.write_at) until there is no more data to be written or an error of non-[`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") kind is returned. This method will not return until the entire buffer has been successfully written or such an error occurs. The first error that is not of [`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") kind generated from this method will be returned.
##### Errors
This function will return the first error of non-[`io::ErrorKind::Interrupted`](../../../io/enum.errorkind#variant.Interrupted "io::ErrorKind::Interrupted") kind that [`write_at`](trait.fileext#method.write_at) returns.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#231-295)### impl FileExt for File
rust Function std::os::wasi::fs::symlink_path Function std::os::wasi::fs::symlink\_path
=========================================
```
pub fn symlink_path<P: AsRef<Path>, U: AsRef<Path>>( old_path: P, new_path: U) -> Result<()>
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.Create a symbolic link.
This is a convenience API similar to `std::os::unix::fs::symlink` and `std::os::windows::fs::symlink_file` and `std::os::windows::fs::symlink_dir`.
rust Trait std::os::wasi::fs::OpenOptionsExt Trait std::os::wasi::fs::OpenOptionsExt
=======================================
```
pub trait OpenOptionsExt {
fn lookup_flags(&mut self, flags: u32) -> &mut Self;
fn directory(&mut self, dir: bool) -> &mut Self;
fn dsync(&mut self, dsync: bool) -> &mut Self;
fn nonblock(&mut self, nonblock: bool) -> &mut Self;
fn rsync(&mut self, rsync: bool) -> &mut Self;
fn sync(&mut self, sync: bool) -> &mut Self;
fn fs_rights_base(&mut self, rights: u64) -> &mut Self;
fn fs_rights_inheriting(&mut self, rights: u64) -> &mut Self;
fn open_at<P: AsRef<Path>>(&self, file: &File, path: P) -> Result<File>;
}
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific extensions to [`fs::OpenOptions`](../../../fs/struct.openoptions "fs::OpenOptions").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#308)#### fn lookup\_flags(&mut self, flags: u32) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Pass custom `dirflags` argument to `path_open`.
This option configures the `dirflags` argument to the `path_open` syscall which `OpenOptions` will eventually call. The `dirflags` argument configures how the file is looked up, currently primarily affecting whether symlinks are followed or not.
By default this value is `__WASI_LOOKUP_SYMLINK_FOLLOW`, or symlinks are followed. You can call this method with 0 to disable following symlinks
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#317)#### fn directory(&mut self, dir: bool) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Indicates whether `OpenOptions` must open a directory or not.
This method will configure whether the `__WASI_O_DIRECTORY` flag is passed when opening a file. When passed it will require that the opened path is a directory.
This option is by default `false`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#323)#### fn dsync(&mut self, dsync: bool) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Indicates whether `__WASI_FDFLAG_DSYNC` is passed in the `fs_flags` field of `path_open`.
This option is by default `false`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#329)#### fn nonblock(&mut self, nonblock: bool) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Indicates whether `__WASI_FDFLAG_NONBLOCK` is passed in the `fs_flags` field of `path_open`.
This option is by default `false`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#335)#### fn rsync(&mut self, rsync: bool) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Indicates whether `__WASI_FDFLAG_RSYNC` is passed in the `fs_flags` field of `path_open`.
This option is by default `false`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#341)#### fn sync(&mut self, sync: bool) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Indicates whether `__WASI_FDFLAG_SYNC` is passed in the `fs_flags` field of `path_open`.
This option is by default `false`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#349)#### fn fs\_rights\_base(&mut self, rights: u64) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Indicates the value that should be passed in for the `fs_rights_base` parameter of `path_open`.
This option defaults based on the `read` and `write` configuration of this `OpenOptions` builder. If this method is called, however, the exact mask passed in will be used instead.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#357)#### fn fs\_rights\_inheriting(&mut self, rights: u64) -> &mut Self
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Indicates the value that should be passed in for the `fs_rights_inheriting` parameter of `path_open`.
The default for this option is the same value as what will be passed for the `fs_rights_base` parameter but if this method is called then the specified value will be used instead.
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#362)#### fn open\_at<P: AsRef<Path>>(&self, file: &File, path: P) -> Result<File>
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Open a file or directory.
This corresponds to the `path_open` syscall.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#365-410)### impl OpenOptionsExt for OpenOptions
rust Trait std::os::wasi::fs::MetadataExt Trait std::os::wasi::fs::MetadataExt
====================================
```
pub trait MetadataExt {
fn dev(&self) -> u64;
fn ino(&self) -> u64;
fn nlink(&self) -> u64;
fn size(&self) -> u64;
fn atim(&self) -> u64;
fn mtim(&self) -> u64;
fn ctim(&self) -> u64;
}
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.WASI-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata "fs::Metadata").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#415)#### fn dev(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the `st_dev` field of the internal `filestat_t`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#417)#### fn ino(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the `st_ino` field of the internal `filestat_t`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#419)#### fn nlink(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the `st_nlink` field of the internal `filestat_t`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#421)#### fn size(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the `st_size` field of the internal `filestat_t`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#423)#### fn atim(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the `st_atim` field of the internal `filestat_t`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#425)#### fn mtim(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the `st_mtim` field of the internal `filestat_t`
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#427)#### fn ctim(&self) -> u64
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Returns the `st_ctim` field of the internal `filestat_t`
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/wasi/fs.rs.html#430-452)### impl MetadataExt for Metadata
| programming_docs |
rust Function std::os::wasi::fs::rename Function std::os::wasi::fs::rename
==================================
```
pub fn rename<P: AsRef<Path>, U: AsRef<Path>>( old_fd: &File, old_path: P, new_fd: &File, new_path: U) -> Result<()>
```
🔬This is a nightly-only experimental API. (`wasi_ext` [#71213](https://github.com/rust-lang/rust/issues/71213))
Available on **WASI** only.Rename a file or directory.
This corresponds to the `path_rename` syscall.
rust Module std::os::windows Module std::os::windows
=======================
Available on **Windows** only.Platform-specific extensions to `std` for Windows.
Provides access to platform-level information for Windows, and exposes Windows-specific idioms that would otherwise be inappropriate as part the core `std` library. These extensions allow developers to use `std` types and idioms with Windows in a way that the normal platform-agnostic idioms would not normally support.
Examples
--------
```
use std::fs::File;
use std::os::windows::prelude::*;
fn main() -> std::io::Result<()> {
let f = File::create("foo.txt")?;
let handle = f.as_raw_handle();
// use handle with native windows bindings
Ok(())
}
```
Modules
-------
[ffi](ffi/index "std::os::windows::ffi mod")
Windows-specific extensions to primitives in the [`std::ffi`](../../ffi/index) module.
[fs](fs/index "std::os::windows::fs mod")
Windows-specific extensions to primitives in the [`std::fs`](../../fs/index) module.
[io](io/index "std::os::windows::io mod")
Windows-specific extensions to general I/O primitives.
[prelude](prelude/index "std::os::windows::prelude mod")
A prelude for conveniently writing platform-specific code.
[process](process/index "std::os::windows::process mod")
Windows-specific extensions to primitives in the [`std::process`](../../process/index) module.
[raw](raw/index "std::os::windows::raw mod")
Windows-specific primitives.
[thread](thread/index "std::os::windows::thread mod")
Windows-specific extensions to primitives in the [`std::thread`](../../thread/index) module.
rust Trait std::os::windows::io::FromRawHandle Trait std::os::windows::io::FromRawHandle
=========================================
```
pub trait FromRawHandle {
unsafe fn from_raw_handle(handle: RawHandle) -> Self;
}
```
Available on **Windows** only.Construct I/O objects from raw handles.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#76)#### unsafe fn from\_raw\_handle(handle: RawHandle) -> Self
Constructs a new I/O object from the specified raw handle.
This function is typically used to **consume ownership** of the handle given, passing responsibility for closing the handle to the returned object. When used in this way, the returned object will take responsibility for closing it when the object goes out of scope.
However, consuming ownership is not strictly required. Use a `From<OwnedHandle>::from` implementation for an API which strictly consumes ownership.
##### Safety
The `handle` passed in must:
* be a valid an open handle,
* be a handle for a resource that may be freed via [`CloseHandle`](https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle) (as opposed to `RegCloseKey` or other close functions).
Note that the handle *may* have the value `INVALID_HANDLE_VALUE` (-1), which is sometimes a valid handle value. See [here](https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443) for the full story.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#159-167)### impl FromRawHandle for File
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#17-23)1.2.0 · ### impl FromRawHandle for Stdio
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#311-316)1.63.0 · ### impl FromRawHandle for OwnedHandle
rust Trait std::os::windows::io::AsRawSocket Trait std::os::windows::io::AsRawSocket
=======================================
```
pub trait AsRawSocket {
fn as_raw_socket(&self) -> RawSocket;
}
```
Available on **Windows** only.Extracts raw sockets.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#190)#### fn as\_raw\_socket(&self) -> RawSocket
Extracts the raw socket.
This function is typically used to **borrow** an owned socket. When used in this way, this method does **not** pass ownership of the raw socket to the caller, and the socket is only guaranteed to be valid while the original object has not yet been destroyed.
However, borrowing is not strictly required. See [`AsSocket::as_socket`](trait.assocket#tymethod.as_socket "AsSocket::as_socket") for an API which strictly borrows a socket.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#244-249)### impl AsRawSocket for TcpListener
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#237-242)### impl AsRawSocket for TcpStream
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#251-256)### impl AsRawSocket for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#167-172)1.63.0 · ### impl AsRawSocket for BorrowedSocket<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#175-180)1.63.0 · ### impl AsRawSocket for OwnedSocket
rust Struct std::os::windows::io::InvalidHandleError Struct std::os::windows::io::InvalidHandleError
===============================================
```
pub struct InvalidHandleError(_);
```
Available on **Windows** only.This is the error type used by [`HandleOrInvalid`](struct.handleorinvalid "HandleOrInvalid") when attempting to convert into a handle, to indicate that the value is `INVALID_HANDLE_VALUE`.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)### impl Clone for InvalidHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)#### fn clone(&self) -> InvalidHandleError
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)### impl Debug for InvalidHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#274-279)### impl Display for InvalidHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#275-278)#### fn fmt(&self, fmt: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#282)### impl Error for InvalidHandleError
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#109)1.0.0 · #### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)1.0.0 · #### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)### impl PartialEq<InvalidHandleError> for InvalidHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)#### fn eq(&self, other: &InvalidHandleError) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)### impl Eq for InvalidHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)### impl StructuralEq for InvalidHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)### impl StructuralPartialEq for InvalidHandleError
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for InvalidHandleError
### impl Send for InvalidHandleError
### impl Sync for InvalidHandleError
### impl Unpin for InvalidHandleError
### impl UnwindSafe for InvalidHandleError
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../../error/trait.error "trait std::error::Error") + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Type Definition std::os::windows::io::RawSocket Type Definition std::os::windows::io::RawSocket
===============================================
```
pub type RawSocket = SOCKET;
```
Available on **Windows** only.Raw SOCKETs.
rust Struct std::os::windows::io::BorrowedHandle Struct std::os::windows::io::BorrowedHandle
===========================================
```
#[repr(transparent)]pub struct BorrowedHandle<'handle> { /* private fields */ }
```
Available on **Windows** only.A borrowed handle.
This has a lifetime parameter to tie it to the lifetime of something that owns the handle.
This uses `repr(transparent)` and has the representation of a host handle, so it can be used in FFI in places where a handle is passed as an argument, it is not captured or consumed.
Note that it *may* have the value `-1`, which in `BorrowedHandle` always represents a valid handle value, such as [the current process handle](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks), and not `INVALID_HANDLE_VALUE`, despite the two having the same value. See [here](https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443) for the full story.
And, it *may* have the value `NULL` (0), which can occur when consoles are detached from processes, or when `windows_subsystem` is used.
This type’s `.to_owned()` implementation returns another `BorrowedHandle` rather than an `OwnedHandle`. It just makes a trivial copy of the raw handle, which is then borrowed under the same lifetime.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#137-158)### impl BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#155-157)const: 1.63.0 · #### pub const unsafe fn borrow\_raw(handle: RawHandle) -> Self
Return a `BorrowedHandle` holding the given raw handle.
##### Safety
The resource pointed to by `handle` must be a valid open handle, it must remain open for the duration of the returned `BorrowedHandle`.
Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is sometimes a valid handle value. See [here](https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443) for the full story.
And, it *may* have the value `NULL` (0), which can occur when consoles are detached from processes, or when `windows_subsystem` is used.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#188-227)### impl BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#192-194)#### pub fn try\_clone\_to\_owned(&self) -> Result<OwnedHandle>
Creates a new `OwnedHandle` instance that shares the same underlying object as the existing `BorrowedHandle` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#424-429)### impl AsHandle for BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#426-428)#### fn as\_handle(&self) -> BorrowedHandle<'\_>
Borrows the handle. [Read more](trait.ashandle#tymethod.as_handle)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#285-290)### impl AsRawHandle for BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#287-289)#### fn as\_raw\_handle(&self) -> RawHandle
Extracts the raw handle. [Read more](trait.asrawhandle#tymethod.as_raw_handle)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#39)### impl<'handle> Clone for BorrowedHandle<'handle>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#39)#### fn clone(&self) -> BorrowedHandle<'handle>
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#374-378)### impl Debug for BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#375-377)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#39)### impl<'handle> Copy for BorrowedHandle<'handle>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#127)### impl Send for BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#135)### impl Sync for BorrowedHandle<'\_>
Auto Trait Implementations
--------------------------
### impl<'handle> RefUnwindSafe for BorrowedHandle<'handle>
### impl<'handle> Unpin for BorrowedHandle<'handle>
### impl<'handle> UnwindSafe for BorrowedHandle<'handle>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Module std::os::windows::io Module std::os::windows::io
===========================
Available on **Windows** only.Windows-specific extensions to general I/O primitives.
Just like raw pointers, raw Windows handles and sockets point to resources with dynamic lifetimes, and they can dangle if they outlive their resources or be forged if they’re created from invalid values.
This module provides three types for representing raw handles and sockets with different ownership properties: raw, borrowed, and owned, which are analogous to types used for representing pointers:
| Type | Analogous to |
| --- | --- |
| [`RawHandle`](type.rawhandle "RawHandle") | `*const _` |
| [`RawSocket`](type.rawsocket "RawSocket") | `*const _` |
| | |
| [`BorrowedHandle<'a>`](struct.borrowedhandle) | `&'a _` |
| [`BorrowedSocket<'a>`](struct.borrowedsocket) | `&'a _` |
| | |
| [`OwnedHandle`](struct.ownedhandle "OwnedHandle") | `Box<_>` |
| [`OwnedSocket`](struct.ownedsocket "OwnedSocket") | `Box<_>` |
Like raw pointers, `RawHandle` and `RawSocket` values are primitive values. And in new code, they should be considered unsafe to do I/O on (analogous to dereferencing them). Rust did not always provide this guidance, so existing code in the Rust ecosystem often doesn’t mark `RawHandle` and `RawSocket` usage as unsafe. Once the `io_safety` feature is stable, libraries will be encouraged to migrate, either by adding `unsafe` to APIs that dereference `RawHandle` and `RawSocket` values, or by using to `BorrowedHandle`, `BorrowedSocket`, `OwnedHandle`, or `OwnedSocket`.
Like references, `BorrowedHandle` and `BorrowedSocket` values are tied to a lifetime, to ensure that they don’t outlive the resource they point to. These are safe to use. `BorrowedHandle` and `BorrowedSocket` values may be used in APIs which provide safe access to any system call except for `CloseHandle`, `closesocket`, or any other call that would end the dynamic lifetime of the resource without ending the lifetime of the handle or socket.
`BorrowedHandle` and `BorrowedSocket` values may be used in APIs which provide safe access to `DuplicateHandle` and `WSADuplicateSocketW` and related functions, so types implementing `AsHandle`, `AsSocket`, `From<OwnedHandle>`, or `From<OwnedSocket>` should not assume they always have exclusive access to the underlying object.
Like boxes, `OwnedHandle` and `OwnedSocket` values conceptually own the resource they point to, and free (close) it when they are dropped.
Structs
-------
[BorrowedHandle](struct.borrowedhandle "std::os::windows::io::BorrowedHandle struct")
A borrowed handle.
[BorrowedSocket](struct.borrowedsocket "std::os::windows::io::BorrowedSocket struct")
A borrowed socket.
[HandleOrInvalid](struct.handleorinvalid "std::os::windows::io::HandleOrInvalid struct")
FFI type for handles in return values or out parameters, where `INVALID_HANDLE_VALUE` is used as a sentry value to indicate errors, such as in the return value of `CreateFileW`. This uses `repr(transparent)` and has the representation of a host handle, so that it can be used in such FFI declarations.
[HandleOrNull](struct.handleornull "std::os::windows::io::HandleOrNull struct")
FFI type for handles in return values or out parameters, where `NULL` is used as a sentry value to indicate errors, such as in the return value of `CreateThread`. This uses `repr(transparent)` and has the representation of a host handle, so that it can be used in such FFI declarations.
[InvalidHandleError](struct.invalidhandleerror "std::os::windows::io::InvalidHandleError struct")
This is the error type used by [`HandleOrInvalid`](struct.handleorinvalid "HandleOrInvalid") when attempting to convert into a handle, to indicate that the value is `INVALID_HANDLE_VALUE`.
[NullHandleError](struct.nullhandleerror "std::os::windows::io::NullHandleError struct")
This is the error type used by [`HandleOrNull`](struct.handleornull "HandleOrNull") when attempting to convert into a handle, to indicate that the value is null.
[OwnedHandle](struct.ownedhandle "std::os::windows::io::OwnedHandle struct")
An owned handle.
[OwnedSocket](struct.ownedsocket "std::os::windows::io::OwnedSocket struct")
An owned socket.
Traits
------
[AsHandle](trait.ashandle "std::os::windows::io::AsHandle trait")
A trait to borrow the handle from an underlying object.
[AsRawHandle](trait.asrawhandle "std::os::windows::io::AsRawHandle trait")
Extracts raw handles.
[AsRawSocket](trait.asrawsocket "std::os::windows::io::AsRawSocket trait")
Extracts raw sockets.
[AsSocket](trait.assocket "std::os::windows::io::AsSocket trait")
A trait to borrow the socket from an underlying object.
[FromRawHandle](trait.fromrawhandle "std::os::windows::io::FromRawHandle trait")
Construct I/O objects from raw handles.
[FromRawSocket](trait.fromrawsocket "std::os::windows::io::FromRawSocket trait")
Creates I/O objects from raw sockets.
[IntoRawHandle](trait.intorawhandle "std::os::windows::io::IntoRawHandle trait")
A trait to express the ability to consume an object and acquire ownership of its raw `HANDLE`.
[IntoRawSocket](trait.intorawsocket "std::os::windows::io::IntoRawSocket trait")
A trait to express the ability to consume an object and acquire ownership of its raw `SOCKET`.
Type Definitions
----------------
[RawHandle](type.rawhandle "std::os::windows::io::RawHandle type")
Raw HANDLEs.
[RawSocket](type.rawsocket "std::os::windows::io::RawSocket type")
Raw SOCKETs.
rust Trait std::os::windows::io::IntoRawSocket Trait std::os::windows::io::IntoRawSocket
=========================================
```
pub trait IntoRawSocket {
fn into_raw_socket(self) -> RawSocket;
}
```
Available on **Windows** only.A trait to express the ability to consume an object and acquire ownership of its raw `SOCKET`.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#233)#### fn into\_raw\_socket(self) -> RawSocket
Consumes this object, returning the raw underlying socket.
This function is typically used to **transfer ownership** of the underlying socket to the caller. When used in this way, callers are then the unique owners of the socket and must close it once it’s no longer needed.
However, transferring ownership is not strictly required. Use a `Into<OwnedSocket>::into` implementation for an API which strictly transfers ownership.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#292-297)### impl IntoRawSocket for TcpListener
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#284-289)### impl IntoRawSocket for TcpStream
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#300-305)### impl IntoRawSocket for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#183-190)1.63.0 · ### impl IntoRawSocket for OwnedSocket
rust Trait std::os::windows::io::IntoRawHandle Trait std::os::windows::io::IntoRawHandle
=========================================
```
pub trait IntoRawHandle {
fn into_raw_handle(self) -> RawHandle;
}
```
Available on **Windows** only.A trait to express the ability to consume an object and acquire ownership of its raw `HANDLE`.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#93)#### fn into\_raw\_handle(self) -> RawHandle
Consumes this object, returning the raw underlying handle.
This function is typically used to **transfer ownership** of the underlying handle to the caller. When used in this way, callers are then the unique owners of the handle and must close it once it’s no longer needed.
However, transferring ownership is not strictly required. Use a `Into<OwnedHandle>::into` implementation for an API which strictly transfers ownership.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#170-175)### impl IntoRawHandle for File
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#51-55)### impl IntoRawHandle for Child
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#103-107)### impl IntoRawHandle for ChildStderr
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#89-93)### impl IntoRawHandle for ChildStdin
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#96-100)### impl IntoRawHandle for ChildStdout
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#301-308)1.63.0 · ### impl IntoRawHandle for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/thread.rs.html#20-25)1.9.0 · ### impl<T> IntoRawHandle for JoinHandle<T>
rust Struct std::os::windows::io::HandleOrNull Struct std::os::windows::io::HandleOrNull
=========================================
```
#[repr(transparent)]pub struct HandleOrNull(_);
```
Available on **Windows** only.FFI type for handles in return values or out parameters, where `NULL` is used as a sentry value to indicate errors, such as in the return value of `CreateThread`. This uses `repr(transparent)` and has the representation of a host handle, so that it can be used in such FFI declarations.
The only thing you can usefully do with a `HandleOrNull` is to convert it into an `OwnedHandle` using its [`TryFrom`](../../../convert/trait.tryfrom "TryFrom") implementation; this conversion takes care of the check for `NULL`. This ensures that such FFI calls cannot start using the handle without checking for `NULL` first.
This type may hold any handle value that [`OwnedHandle`](struct.ownedhandle "OwnedHandle") may hold. As with `OwnedHandle`, when it holds `-1`, that value is interpreted as a valid handle value, such as [the current process handle](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks), and not `INVALID_HANDLE_VALUE`.
If this holds a non-null handle, it will close the handle on drop.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#318-338)### impl HandleOrNull
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#335-337)#### pub unsafe fn from\_raw\_handle(handle: RawHandle) -> Self
Constructs a new instance of `Self` from the given `RawHandle` returned from a Windows API that uses null to indicate failure, such as `CreateThread`.
Use `HandleOrInvalid` instead of `HandleOrNull` for APIs that use `INVALID_HANDLE_VALUE` to indicate failure.
##### Safety
The passed `handle` value must either satisfy the safety requirements of [`FromRawHandle::from_raw_handle`](trait.fromrawhandle#tymethod.from_raw_handle "FromRawHandle::from_raw_handle"), or be null. Note that not all Windows APIs use null for errors; see [here](https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443) for the full story.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#93)### impl Debug for HandleOrNull
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#93)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#161-177)### impl TryFrom<HandleOrNull> for OwnedHandle
#### type Error = NullHandleError
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#165-176)#### fn try\_from(handle\_or\_null: HandleOrNull) -> Result<Self, NullHandleError>
Performs the conversion.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#123)### impl Send for HandleOrNull
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#131)### impl Sync for HandleOrNull
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for HandleOrNull
### impl Unpin for HandleOrNull
### impl UnwindSafe for HandleOrNull
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Trait std::os::windows::io::FromRawSocket Trait std::os::windows::io::FromRawSocket
=========================================
```
pub trait FromRawSocket {
unsafe fn from_raw_socket(sock: RawSocket) -> Self;
}
```
Available on **Windows** only.Creates I/O objects from raw sockets.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#216)#### unsafe fn from\_raw\_socket(sock: RawSocket) -> Self
Constructs a new I/O object from the specified raw socket.
This function is typically used to **consume ownership** of the socket given, passing responsibility for closing the socket to the returned object. When used in this way, the returned object will take responsibility for closing it when the object goes out of scope.
However, consuming ownership is not strictly required. Use a `From<OwnedSocket>::from` implementation for an API which strictly consumes ownership.
##### Safety
The `socket` passed in must:
* be a valid an open socket,
* be a socket that may be freed via [`closesocket`](https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket).
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#267-273)### impl FromRawSocket for TcpListener
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#259-265)### impl FromRawSocket for TcpStream
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#275-281)### impl FromRawSocket for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#193-199)1.63.0 · ### impl FromRawSocket for OwnedSocket
rust Struct std::os::windows::io::BorrowedSocket Struct std::os::windows::io::BorrowedSocket
===========================================
```
#[repr(transparent)]pub struct BorrowedSocket<'socket> { /* private fields */ }
```
Available on **Windows** only.A borrowed socket.
This has a lifetime parameter to tie it to the lifetime of something that owns the socket.
This uses `repr(transparent)` and has the representation of a host socket, so it can be used in FFI in places where a socket is passed as an argument, it is not captured or consumed, and it never has the value `INVALID_SOCKET`.
This type’s `.to_owned()` implementation returns another `BorrowedSocket` rather than an `OwnedSocket`. It just makes a trivial copy of the raw socket, which is then borrowed under the same lifetime.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#67-82)### impl BorrowedSocket<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#78-81)const: 1.63.0 · #### pub const unsafe fn borrow\_raw(socket: RawSocket) -> Self
Return a `BorrowedSocket` holding the given raw socket.
##### Safety
The resource pointed to by `raw` must remain open for the duration of the returned `BorrowedSocket`, and it must not have the value `INVALID_SOCKET`.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#107-159)### impl BorrowedSocket<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#111-158)#### pub fn try\_clone\_to\_owned(&self) -> Result<OwnedSocket>
Creates a new `OwnedSocket` instance that shares the same underlying object as the existing `BorrowedSocket` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#167-172)### impl AsRawSocket for BorrowedSocket<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#169-171)#### fn as\_raw\_socket(&self) -> RawSocket
Extracts the raw socket. [Read more](trait.asrawsocket#tymethod.as_raw_socket)
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#250-255)### impl AsSocket for BorrowedSocket<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#252-254)#### fn as\_socket(&self) -> BorrowedSocket<'\_>
Borrows the socket.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#29)### impl<'socket> Clone for BorrowedSocket<'socket>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#29)#### fn clone(&self) -> BorrowedSocket<'socket>
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#212-216)### impl Debug for BorrowedSocket<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#213-215)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#29)### impl<'socket> Copy for BorrowedSocket<'socket>
Auto Trait Implementations
--------------------------
### impl<'socket> RefUnwindSafe for BorrowedSocket<'socket>
### impl<'socket> Send for BorrowedSocket<'socket>
### impl<'socket> Sync for BorrowedSocket<'socket>
### impl<'socket> Unpin for BorrowedSocket<'socket>
### impl<'socket> UnwindSafe for BorrowedSocket<'socket>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Trait std::os::windows::io::AsRawHandle Trait std::os::windows::io::AsRawHandle
=======================================
```
pub trait AsRawHandle {
fn as_raw_handle(&self) -> RawHandle;
}
```
Available on **Windows** only.Extracts raw handles.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#45)#### fn as\_raw\_handle(&self) -> RawHandle
Extracts the raw handle.
This function is typically used to **borrow** an owned handle. When used in this way, this method does **not** pass ownership of the raw handle to the caller, and the handle is only guaranteed to be valid while the original object has not yet been destroyed.
This function may return null, such as when called on [`Stdin`](../../../io/struct.stdin), [`Stdout`](../../../io/struct.stdout), or [`Stderr`](../../../io/struct.stderr) when the console is detached.
However, borrowing is not strictly required. See [`AsHandle::as_handle`](trait.ashandle#tymethod.as_handle "AsHandle::as_handle") for an API which strictly borrows a handle.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#97-102)### impl AsRawHandle for File
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#119-123)1.21.0 · ### impl AsRawHandle for Stderr
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#105-109)1.21.0 · ### impl AsRawHandle for Stdin
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#112-116)1.21.0 · ### impl AsRawHandle for Stdout
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#35-40)1.2.0 · ### impl AsRawHandle for Child
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#81-86)1.2.0 · ### impl AsRawHandle for ChildStderr
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#65-70)1.2.0 · ### impl AsRawHandle for ChildStdin
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#73-78)1.2.0 · ### impl AsRawHandle for ChildStdout
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#285-290)1.63.0 · ### impl AsRawHandle for BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#293-298)1.63.0 · ### impl AsRawHandle for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#140-144)1.35.0 · ### impl<'a> AsRawHandle for StderrLock<'a>
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#126-130)1.35.0 · ### impl<'a> AsRawHandle for StdinLock<'a>
[source](https://doc.rust-lang.org/src/std/os/windows/io/raw.rs.html#133-137)1.35.0 · ### impl<'a> AsRawHandle for StdoutLock<'a>
[source](https://doc.rust-lang.org/src/std/os/windows/thread.rs.html#12-17)1.9.0 · ### impl<T> AsRawHandle for JoinHandle<T>
rust Type Definition std::os::windows::io::RawHandle Type Definition std::os::windows::io::RawHandle
===============================================
```
pub type RawHandle = HANDLE;
```
Available on **Windows** only.Raw HANDLEs.
rust Struct std::os::windows::io::OwnedSocket Struct std::os::windows::io::OwnedSocket
========================================
```
#[repr(transparent)]pub struct OwnedSocket { /* private fields */ }
```
Available on **Windows** only.An owned socket.
This closes the socket on drop.
This uses `repr(transparent)` and has the representation of a host socket, so it can be used in FFI in places where a socket is passed as a consumed argument or returned as an owned value, and it never has the value `INVALID_SOCKET`.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#84-105)### impl OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#88-90)#### pub fn try\_clone(&self) -> Result<Self>
Creates a new `OwnedSocket` instance that shares the same underlying object as the existing `OwnedSocket` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#175-180)### impl AsRawSocket for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#177-179)#### fn as\_raw\_socket(&self) -> RawSocket
Extracts the raw socket. [Read more](trait.asrawsocket#tymethod.as_raw_socket)
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#258-266)### impl AsSocket for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#260-265)#### fn as\_socket(&self) -> BorrowedSocket<'\_>
Borrows the socket.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#219-223)### impl Debug for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#220-222)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#202-209)### impl Drop for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#204-208)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#309-314)### impl From<OwnedSocket> for TcpListener
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#311-313)#### fn from(owned: OwnedSocket) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#285-290)### impl From<OwnedSocket> for TcpStream
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#287-289)#### fn from(owned: OwnedSocket) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#333-338)### impl From<OwnedSocket> for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#335-337)#### fn from(owned: OwnedSocket) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#301-306)### impl From<TcpListener> for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#303-305)#### fn from(tcp\_listener: TcpListener) -> OwnedSocket
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#277-282)### impl From<TcpStream> for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#279-281)#### fn from(tcp\_stream: TcpStream) -> OwnedSocket
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#325-330)### impl From<UdpSocket> for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#327-329)#### fn from(udp\_socket: UdpSocket) -> OwnedSocket
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#193-199)### impl FromRawSocket for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#195-198)#### unsafe fn from\_raw\_socket(socket: RawSocket) -> Self
Constructs a new I/O object from the specified raw socket. [Read more](trait.fromrawsocket#tymethod.from_raw_socket)
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#183-190)### impl IntoRawSocket for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#185-189)#### fn into\_raw\_socket(self) -> RawSocket
Consumes this object, returning the raw underlying socket. [Read more](trait.intorawsocket#tymethod.into_raw_socket)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for OwnedSocket
### impl Send for OwnedSocket
### impl Sync for OwnedSocket
### impl Unpin for OwnedSocket
### impl UnwindSafe for OwnedSocket
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::os::windows::io::HandleOrInvalid Struct std::os::windows::io::HandleOrInvalid
============================================
```
#[repr(transparent)]pub struct HandleOrInvalid(_);
```
Available on **Windows** only.FFI type for handles in return values or out parameters, where `INVALID_HANDLE_VALUE` is used as a sentry value to indicate errors, such as in the return value of `CreateFileW`. This uses `repr(transparent)` and has the representation of a host handle, so that it can be used in such FFI declarations.
The only thing you can usefully do with a `HandleOrInvalid` is to convert it into an `OwnedHandle` using its [`TryFrom`](../../../convert/trait.tryfrom "TryFrom") implementation; this conversion takes care of the check for `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without checking for `INVALID_HANDLE_VALUE` first.
This type may hold any handle value that [`OwnedHandle`](struct.ownedhandle "OwnedHandle") may hold, except that when it holds `-1`, that value is interpreted to mean `INVALID_HANDLE_VALUE`.
If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#340-361)### impl HandleOrInvalid
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#358-360)#### pub unsafe fn from\_raw\_handle(handle: RawHandle) -> Self
Constructs a new instance of `Self` from the given `RawHandle` returned from a Windows API that uses `INVALID_HANDLE_VALUE` to indicate failure, such as `CreateFileW`.
Use `HandleOrNull` instead of `HandleOrInvalid` for APIs that use null to indicate failure.
##### Safety
The passed `handle` value must either satisfy the safety requirements of [`FromRawHandle::from_raw_handle`](trait.fromrawhandle#tymethod.from_raw_handle "FromRawHandle::from_raw_handle"), or be `INVALID_HANDLE_VALUE` (-1). Note that not all Windows APIs use `INVALID_HANDLE_VALUE` for errors; see [here](https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443) for the full story.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#112)### impl Debug for HandleOrInvalid
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#112)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#230-246)### impl TryFrom<HandleOrInvalid> for OwnedHandle
#### type Error = InvalidHandleError
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#234-245)#### fn try\_from( handle\_or\_invalid: HandleOrInvalid) -> Result<Self, InvalidHandleError>
Performs the conversion.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#125)### impl Send for HandleOrInvalid
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#133)### impl Sync for HandleOrInvalid
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for HandleOrInvalid
### impl Unpin for HandleOrInvalid
### impl UnwindSafe for HandleOrInvalid
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Trait std::os::windows::io::AsSocket Trait std::os::windows::io::AsSocket
====================================
```
pub trait AsSocket {
fn as_socket(&self) -> BorrowedSocket<'_>;
}
```
Available on **Windows** only.A trait to borrow the socket from an underlying object.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#230)#### fn as\_socket(&self) -> BorrowedSocket<'\_>
Borrows the socket.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#293-298)### impl AsSocket for TcpListener
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#269-274)### impl AsSocket for TcpStream
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#317-322)### impl AsSocket for UdpSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#250-255)### impl AsSocket for BorrowedSocket<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#258-266)### impl AsSocket for OwnedSocket
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#234-239)### impl<T: AsSocket> AsSocket for &T
[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#242-247)### impl<T: AsSocket> AsSocket for &mut T
rust Struct std::os::windows::io::OwnedHandle Struct std::os::windows::io::OwnedHandle
========================================
```
#[repr(transparent)]pub struct OwnedHandle { /* private fields */ }
```
Available on **Windows** only.An owned handle.
This closes the handle on drop.
Note that it *may* have the value `-1`, which in `OwnedHandle` always represents a valid handle value, such as [the current process handle](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks), and not `INVALID_HANDLE_VALUE`, despite the two having the same value. See [here](https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443) for the full story.
And, it *may* have the value `NULL` (0), which can occur when consoles are detached from processes, or when `windows_subsystem` is used.
`OwnedHandle` uses [`CloseHandle`](https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle) to close its handle on drop. As such, it must not be used with handles to open registry keys which need to be closed with [`RegCloseKey`](https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey) instead.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#179-186)### impl OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#183-185)#### pub fn try\_clone(&self) -> Result<Self>
Creates a new `OwnedHandle` instance that shares the same underlying object as the existing `OwnedHandle` instance.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#432-440)### impl AsHandle for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#434-439)#### fn as\_handle(&self) -> BorrowedHandle<'\_>
Borrows the handle. [Read more](trait.ashandle#tymethod.as_handle)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#293-298)### impl AsRawHandle for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#295-297)#### fn as\_raw\_handle(&self) -> RawHandle
Extracts the raw handle. [Read more](trait.asrawhandle#tymethod.as_raw_handle)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#381-385)### impl Debug for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#382-384)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#364-371)### impl Drop for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#366-370)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#58-62)### impl From<Child> for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#59-61)#### fn from(child: Child) -> OwnedHandle
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#555-560)### impl From<ChildStderr> for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#557-559)#### fn from(child\_stderr: ChildStderr) -> OwnedHandle
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#523-528)### impl From<ChildStdin> for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#525-527)#### fn from(child\_stdin: ChildStdin) -> OwnedHandle
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#539-544)### impl From<ChildStdout> for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#541-543)#### fn from(child\_stdout: ChildStdout) -> OwnedHandle
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#451-456)### impl From<File> for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#453-455)#### fn from(file: File) -> OwnedHandle
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#571-576)### impl<T> From<JoinHandle<T>> for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#573-575)#### fn from(join\_handle: JoinHandle<T>) -> OwnedHandle
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#459-464)### impl From<OwnedHandle> for File
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#461-463)#### fn from(owned: OwnedHandle) -> Self
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#26-32)### impl From<OwnedHandle> for Stdio
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#27-31)#### fn from(handle: OwnedHandle) -> Stdio
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#311-316)### impl FromRawHandle for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#313-315)#### unsafe fn from\_raw\_handle(handle: RawHandle) -> Self
Constructs a new I/O object from the specified raw handle. [Read more](trait.fromrawhandle#tymethod.from_raw_handle)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#301-308)### impl IntoRawHandle for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#303-307)#### fn into\_raw\_handle(self) -> RawHandle
Consumes this object, returning the raw underlying handle. [Read more](trait.intorawhandle#tymethod.into_raw_handle)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#230-246)### impl TryFrom<HandleOrInvalid> for OwnedHandle
#### type Error = InvalidHandleError
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#234-245)#### fn try\_from( handle\_or\_invalid: HandleOrInvalid) -> Result<Self, InvalidHandleError>
Performs the conversion.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#161-177)### impl TryFrom<HandleOrNull> for OwnedHandle
#### type Error = NullHandleError
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#165-176)#### fn try\_from(handle\_or\_null: HandleOrNull) -> Result<Self, NullHandleError>
Performs the conversion.
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#121)### impl Send for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#129)### impl Sync for OwnedHandle
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for OwnedHandle
### impl Unpin for OwnedHandle
### impl UnwindSafe for OwnedHandle
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Trait std::os::windows::io::AsHandle Trait std::os::windows::io::AsHandle
====================================
```
pub trait AsHandle {
fn as_handle(&self) -> BorrowedHandle<'_>;
}
```
Available on **Windows** only.A trait to borrow the handle from an underlying object.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#404)#### fn as\_handle(&self) -> BorrowedHandle<'\_>
Borrows the handle.
##### Example
```
use std::fs::File;
use std::os::windows::io::{AsHandle, BorrowedHandle};
let mut f = File::open("foo.txt")?;
let borrowed_handle: BorrowedHandle<'_> = f.as_handle();
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#443-448)### impl AsHandle for File
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#499-504)### impl AsHandle for Stderr
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#467-472)### impl AsHandle for Stdin
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#483-488)### impl AsHandle for Stdout
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#43-48)### impl AsHandle for Child
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#547-552)### impl AsHandle for ChildStderr
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#515-520)### impl AsHandle for ChildStdin
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#531-536)### impl AsHandle for ChildStdout
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#424-429)### impl AsHandle for BorrowedHandle<'\_>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#432-440)### impl AsHandle for OwnedHandle
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#507-512)### impl<'a> AsHandle for StderrLock<'a>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#475-480)### impl<'a> AsHandle for StdinLock<'a>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#491-496)### impl<'a> AsHandle for StdoutLock<'a>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#563-568)### impl<T> AsHandle for JoinHandle<T>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#408-413)### impl<T: AsHandle> AsHandle for &T
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#416-421)### impl<T: AsHandle> AsHandle for &mut T
rust Struct std::os::windows::io::NullHandleError Struct std::os::windows::io::NullHandleError
============================================
```
pub struct NullHandleError(_);
```
Available on **Windows** only.This is the error type used by [`HandleOrNull`](struct.handleornull "HandleOrNull") when attempting to convert into a handle, to indicate that the value is null.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)### impl Clone for NullHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)#### fn clone(&self) -> NullHandleError
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)### impl Debug for NullHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#256-260)### impl Display for NullHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#257-259)#### fn fmt(&self, fmt: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#263)### impl Error for NullHandleError
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#109)1.0.0 · #### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)1.0.0 · #### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)### impl PartialEq<NullHandleError> for NullHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)#### fn eq(&self, other: &NullHandleError) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)### impl Eq for NullHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)### impl StructuralEq for NullHandleError
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)### impl StructuralPartialEq for NullHandleError
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for NullHandleError
### impl Send for NullHandleError
### impl Sync for NullHandleError
### impl Unpin for NullHandleError
### impl UnwindSafe for NullHandleError
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../../error/trait.error "trait std::error::Error") + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Trait std::os::windows::ffi::OsStringExt Trait std::os::windows::ffi::OsStringExt
========================================
```
pub trait OsStringExt: Sealed {
fn from_wide(wide: &[u16]) -> Self;
}
```
Available on **Windows** only.Windows-specific extensions to [`OsString`](../../../ffi/struct.osstring "OsString").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/ffi.rs.html#89)#### fn from\_wide(wide: &[u16]) -> Self
Creates an `OsString` from a potentially ill-formed UTF-16 slice of 16-bit code units.
This is lossless: calling [`OsStrExt::encode_wide`](trait.osstrext#tymethod.encode_wide "OsStrExt::encode_wide") on the resulting string will always return the original code units.
##### Examples
```
use std::ffi::OsString;
use std::os::windows::prelude::*;
// UTF-16 encoding for "Unicode".
let source = [0x0055, 0x006E, 0x0069, 0x0063, 0x006F, 0x0064, 0x0065];
let string = OsString::from_wide(&source[..]);
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/ffi.rs.html#93-97)### impl OsStringExt for OsString
rust Module std::os::windows::ffi Module std::os::windows::ffi
============================
Available on **Windows** only.Windows-specific extensions to primitives in the [`std::ffi`](../../../ffi/index) module.
Overview
--------
For historical reasons, the Windows API uses a form of potentially ill-formed UTF-16 encoding for strings. Specifically, the 16-bit code units in Windows strings may contain [isolated surrogate code points which are not paired together](https://simonsapin.github.io/wtf-8/#ill-formed-utf-16). The Unicode standard requires that surrogate code points (those in the range U+D800 to U+DFFF) always be *paired*, because in the UTF-16 encoding a *surrogate code unit pair* is used to encode a single character. For compatibility with code that does not enforce these pairings, Windows does not enforce them, either.
While it is not always possible to convert such a string losslessly into a valid UTF-16 string (or even UTF-8), it is often desirable to be able to round-trip such a string from and to Windows APIs losslessly. For example, some Rust code may be “bridging” some Windows APIs together, just passing `WCHAR` strings among those APIs without ever really looking into the strings.
If Rust code *does* need to look into those strings, it can convert them to valid UTF-8, possibly lossily, by substituting invalid sequences with [`U+FFFD REPLACEMENT CHARACTER`](../../../char/constant.replacement_character), as is conventionally done in other Rust APIs that deal with string encodings.
`OsStringExt` and `OsStrExt`
-----------------------------
[`OsString`](../../../ffi/struct.osstring "OsString") is the Rust wrapper for owned strings in the preferred representation of the operating system. On Windows, this struct gets augmented with an implementation of the [`OsStringExt`](trait.osstringext "OsStringExt") trait, which has an [`OsStringExt::from_wide`](trait.osstringext#tymethod.from_wide "OsStringExt::from_wide") method. This lets you create an [`OsString`](../../../ffi/struct.osstring "OsString") from a `&[u16]` slice; presumably you get such a slice out of a `WCHAR` Windows API.
Similarly, [`OsStr`](../../../ffi/struct.osstr "OsStr") is the Rust wrapper for borrowed strings from preferred representation of the operating system. On Windows, the [`OsStrExt`](trait.osstrext "OsStrExt") trait provides the [`OsStrExt::encode_wide`](trait.osstrext#tymethod.encode_wide "OsStrExt::encode_wide") method, which outputs an [`EncodeWide`](struct.encodewide "EncodeWide") iterator. You can [`collect`](../../../iter/trait.iterator#method.collect) this iterator, for example, to obtain a `Vec<u16>`; you can later get a pointer to this vector’s contents and feed it to Windows APIs.
These traits, along with [`OsString`](../../../ffi/struct.osstring "OsString") and [`OsStr`](../../../ffi/struct.osstr "OsStr"), work in conjunction so that it is possible to **round-trip** strings from Windows and back, with no loss of data, even if the strings are ill-formed UTF-16.
Structs
-------
[EncodeWide](struct.encodewide "std::os::windows::ffi::EncodeWide struct")
Generates a wide character sequence for potentially ill-formed UTF-16.
Traits
------
[OsStrExt](trait.osstrext "std::os::windows::ffi::OsStrExt trait")
Windows-specific extensions to [`OsStr`](../../../ffi/struct.osstr "OsStr").
[OsStringExt](trait.osstringext "std::os::windows::ffi::OsStringExt trait")
Windows-specific extensions to [`OsString`](../../../ffi/struct.osstring "OsString").
rust Struct std::os::windows::ffi::EncodeWide Struct std::os::windows::ffi::EncodeWide
========================================
```
pub struct EncodeWide<'a> { /* private fields */ }
```
Available on **Windows** only.Generates a wide character sequence for potentially ill-formed UTF-16.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sys_common/wtf8.rs.html#921)### impl<'a> Clone for EncodeWide<'a>
[source](https://doc.rust-lang.org/src/std/sys_common/wtf8.rs.html#921)#### fn clone(&self) -> EncodeWide<'a>
Notable traits for [EncodeWide](struct.encodewide "struct std::os::windows::ffi::EncodeWide")<'a>
```
impl<'a> Iterator for EncodeWide<'a>
type Item = u16;
```
Returns a copy of the value. [Read more](../../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sys_common/wtf8.rs.html#929-959)### impl<'a> Iterator for EncodeWide<'a>
#### type Item = u16
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/sys_common/wtf8.rs.html#933-948)#### fn next(&mut self) -> Option<u16>
Advances the iterator and returns the next value. [Read more](../../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/sys_common/wtf8.rs.html#951-958)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Notable traits for [Filter](../../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../../iter/struct.peekable#method.peek) and [`peek_mut`](../../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Notable traits for [SkipWhile](../../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Notable traits for [TakeWhile](../../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../../primitive.reference) St, Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../../option/enum.option#variant.None "None"). [Read more](../../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../../default/trait.default "trait std::default::Default") + [Extend](../../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = [()](../../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../../ops/trait.try "trait std::ops::Try")>::[Residual](../../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../../ops/trait.residual "trait std::ops::Residual")<[Option](../../../option/enum.option "enum std::option::Option")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../../primitive.bool)>, <R as [Try](../../../ops/trait.try "trait std::ops::Try")>::[Residual](../../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../../ops/trait.residual "trait std::ops::Residual")<[Option](../../../option/enum.option "enum std::option::Option")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../../default/trait.default "trait std::default::Default") + [Extend](../../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../../default/trait.default "trait std::default::Default") + [Extend](../../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../../primitive.reference) T>,
Notable traits for [Copied](../../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../../primitive.reference) T>,
Notable traits for [Cloned](../../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") with those of another. [Read more](../../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<[Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../../iter/trait.iterator "Iterator") are [lexicographically](../../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../../option/enum.option "enum std::option::Option")<[Ordering](../../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/sys_common/wtf8.rs.html#962)1.62.0 · ### impl FusedIterator for EncodeWide<'\_>
Auto Trait Implementations
--------------------------
### impl<'a> RefUnwindSafe for EncodeWide<'a>
### impl<'a> Send for EncodeWide<'a>
### impl<'a> Sync for EncodeWide<'a>
### impl<'a> Unpin for EncodeWide<'a>
### impl<'a> UnwindSafe for EncodeWide<'a>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Trait std::os::windows::ffi::OsStrExt Trait std::os::windows::ffi::OsStrExt
=====================================
```
pub trait OsStrExt: Sealed {
fn encode_wide(&self) -> EncodeWide<'_>;
}
```
Notable traits for [EncodeWide](struct.encodewide "struct std::os::windows::ffi::EncodeWide")<'a>
```
impl<'a> Iterator for EncodeWide<'a>
type Item = u16;
```
Available on **Windows** only.Windows-specific extensions to [`OsStr`](../../../ffi/struct.osstr "OsStr").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/ffi.rs.html#127)#### fn encode\_wide(&self) -> EncodeWide<'\_>
Notable traits for [EncodeWide](struct.encodewide "struct std::os::windows::ffi::EncodeWide")<'a>
```
impl<'a> Iterator for EncodeWide<'a>
type Item = u16;
```
Re-encodes an `OsStr` as a wide character sequence, i.e., potentially ill-formed UTF-16.
This is lossless: calling [`OsStringExt::from_wide`](trait.osstringext#tymethod.from_wide "OsStringExt::from_wide") and then `encode_wide` on the result will yield the original code units. Note that the encoding does not add a final null terminator.
##### Examples
```
use std::ffi::OsString;
use std::os::windows::prelude::*;
// UTF-16 encoding for "Unicode".
let source = [0x0055, 0x006E, 0x0069, 0x0063, 0x006F, 0x0064, 0x0065];
let string = OsString::from_wide(&source[..]);
let result: Vec<u16> = string.encode_wide().collect();
assert_eq!(&source[..], &result[..]);
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/ffi.rs.html#131-136)### impl OsStrExt for OsStr
rust Module std::os::windows::prelude Module std::os::windows::prelude
================================
Available on **Windows** only.A prelude for conveniently writing platform-specific code.
Includes all extension traits, and some important type definitions.
Re-exports
----------
`pub use super::ffi::[OsStrExt](../ffi/trait.osstrext "trait std::os::windows::ffi::OsStrExt");`
`pub use super::ffi::[OsStringExt](../ffi/trait.osstringext "trait std::os::windows::ffi::OsStringExt");`
`pub use super::fs::[FileExt](../fs/trait.fileext "trait std::os::windows::fs::FileExt");`
`pub use super::fs::[MetadataExt](../fs/trait.metadataext "trait std::os::windows::fs::MetadataExt");`
`pub use super::fs::[OpenOptionsExt](../fs/trait.openoptionsext "trait std::os::windows::fs::OpenOptionsExt");`
`pub use super::io::[AsHandle](../io/trait.ashandle "trait std::os::windows::io::AsHandle");`
`pub use super::io::[AsSocket](../io/trait.assocket "trait std::os::windows::io::AsSocket");`
`pub use super::io::[BorrowedHandle](../io/struct.borrowedhandle "struct std::os::windows::io::BorrowedHandle");`
`pub use super::io::[BorrowedSocket](../io/struct.borrowedsocket "struct std::os::windows::io::BorrowedSocket");`
`pub use super::io::[FromRawHandle](../io/trait.fromrawhandle "trait std::os::windows::io::FromRawHandle");`
`pub use super::io::[FromRawSocket](../io/trait.fromrawsocket "trait std::os::windows::io::FromRawSocket");`
`pub use super::io::[HandleOrInvalid](../io/struct.handleorinvalid "struct std::os::windows::io::HandleOrInvalid");`
`pub use super::io::[IntoRawHandle](../io/trait.intorawhandle "trait std::os::windows::io::IntoRawHandle");`
`pub use super::io::[IntoRawSocket](../io/trait.intorawsocket "trait std::os::windows::io::IntoRawSocket");`
`pub use super::io::[OwnedHandle](../io/struct.ownedhandle "struct std::os::windows::io::OwnedHandle");`
`pub use super::io::[OwnedSocket](../io/struct.ownedsocket "struct std::os::windows::io::OwnedSocket");`
`pub use super::io::[AsRawHandle](../io/trait.asrawhandle "trait std::os::windows::io::AsRawHandle");`
`pub use super::io::[AsRawSocket](../io/trait.asrawsocket "trait std::os::windows::io::AsRawSocket");`
`pub use super::io::[RawHandle](../io/type.rawhandle "type std::os::windows::io::RawHandle");`
`pub use super::io::[RawSocket](../io/type.rawsocket "type std::os::windows::io::RawSocket");`
rust Trait std::os::windows::fs::FileTypeExt Trait std::os::windows::fs::FileTypeExt
=======================================
```
pub trait FileTypeExt: Sealed {
fn is_symlink_dir(&self) -> bool;
fn is_symlink_file(&self) -> bool;
}
```
Available on **Windows** only.Windows-specific extensions to [`fs::FileType`](../../../fs/struct.filetype "fs::FileType").
On Windows, a symbolic link knows whether it is a file or directory.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#510)#### fn is\_symlink\_dir(&self) -> bool
Returns `true` if this file type is a symbolic link that is also a directory.
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#513)#### fn is\_symlink\_file(&self) -> bool
Returns `true` if this file type is a symbolic link that is also a file.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#520-527)### impl FileTypeExt for FileType
rust Module std::os::windows::fs Module std::os::windows::fs
===========================
Available on **Windows** only.Windows-specific extensions to primitives in the [`std::fs`](../../../fs/index) module.
Traits
------
[FileExt](trait.fileext "std::os::windows::fs::FileExt trait")
Windows-specific extensions to [`fs::File`](../../../fs/struct.file "fs::File").
[FileTypeExt](trait.filetypeext "std::os::windows::fs::FileTypeExt trait")
Windows-specific extensions to [`fs::FileType`](../../../fs/struct.filetype "fs::FileType").
[MetadataExt](trait.metadataext "std::os::windows::fs::MetadataExt trait")
Windows-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata "fs::Metadata").
[OpenOptionsExt](trait.openoptionsext "std::os::windows::fs::OpenOptionsExt trait")
Windows-specific extensions to [`fs::OpenOptions`](../../../fs/struct.openoptions "fs::OpenOptions").
Functions
---------
[symlink\_dir](fn.symlink_dir "std::os::windows::fs::symlink_dir fn")
Creates a new symlink to a directory on the filesystem.
[symlink\_file](fn.symlink_file "std::os::windows::fs::symlink_file fn")
Creates a new symlink to a non-directory file on the filesystem.
rust Function std::os::windows::fs::symlink_file Function std::os::windows::fs::symlink\_file
============================================
```
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>( original: P, link: Q) -> Result<()>
```
Available on **Windows** only.Creates a new symlink to a non-directory file on the filesystem.
The `link` path will be a file symbolic link pointing to the `original` path.
The `original` path should not be a directory or a symlink to a directory, otherwise the symlink will be broken. Use [`symlink_dir`](fn.symlink_dir "symlink_dir") for directories.
This function currently corresponds to [`CreateSymbolicLinkW`](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw). Note that this [may change in the future](../../../io/index#platform-specific-behavior).
Examples
--------
```
use std::os::windows::fs;
fn main() -> std::io::Result<()> {
fs::symlink_file("a.txt", "b.txt")?;
Ok(())
}
```
Limitations
-----------
Windows treats symlink creation as a [privileged action](https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links), therefore this function is likely to fail unless the user makes changes to their system to permit symlink creation. Users can try enabling Developer Mode, granting the `SeCreateSymbolicLinkPrivilege` privilege, or running the process as an administrator.
rust Trait std::os::windows::fs::FileExt Trait std::os::windows::fs::FileExt
===================================
```
pub trait FileExt {
fn seek_read(&self, buf: &mut [u8], offset: u64) -> Result<usize>;
fn seek_write(&self, buf: &[u8], offset: u64) -> Result<usize>;
}
```
Available on **Windows** only.Windows-specific extensions to [`fs::File`](../../../fs/struct.file "fs::File").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#50)#### fn seek\_read(&self, buf: &mut [u8], offset: u64) -> Result<usize>
Seeks to a given position and reads a number of bytes.
Returns the number of bytes read.
The offset is relative to the start of the file and thus independent from the current cursor. The current cursor **is** affected by this function, it is set to the end of the read.
Reading beyond the end of the file will always return with a length of 0.
Note that similar to `File::read`, it is not an error to return with a short read. When returning from such a short read, the file pointer is still updated.
##### Examples
```
use std::io;
use std::fs::File;
use std::os::windows::prelude::*;
fn main() -> io::Result<()> {
let mut file = File::open("foo.txt")?;
let mut buffer = [0; 10];
// Read 10 bytes, starting 72 bytes from the
// start of the file.
file.seek_read(&mut buffer[..], 72)?;
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#83)#### fn seek\_write(&self, buf: &[u8], offset: u64) -> Result<usize>
Seeks to a given position and writes a number of bytes.
Returns the number of bytes written.
The offset is relative to the start of the file and thus independent from the current cursor. The current cursor **is** affected by this function, it is set to the end of the write.
When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are left uninitialized.
Note that similar to `File::write`, it is not an error to return a short write. When returning from such a short write, the file pointer is still updated.
##### Examples
```
use std::fs::File;
use std::os::windows::prelude::*;
fn main() -> std::io::Result<()> {
let mut buffer = File::create("foo.txt")?;
// Write a byte string starting 72 bytes from
// the start of the file.
buffer.seek_write(b"some bytes", 72)?;
Ok(())
}
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#87-95)### impl FileExt for File
rust Trait std::os::windows::fs::OpenOptionsExt Trait std::os::windows::fs::OpenOptionsExt
==========================================
```
pub trait OpenOptionsExt {
fn access_mode(&mut self, access: u32) -> &mut Self;
fn share_mode(&mut self, val: u32) -> &mut Self;
fn custom_flags(&mut self, flags: u32) -> &mut Self;
fn attributes(&mut self, val: u32) -> &mut Self;
fn security_qos_flags(&mut self, flags: u32) -> &mut Self;
}
```
Available on **Windows** only.Windows-specific extensions to [`fs::OpenOptions`](../../../fs/struct.openoptions "fs::OpenOptions").
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#121)#### fn access\_mode(&mut self, access: u32) -> &mut Self
Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea) with the specified value.
This will override the `read`, `write`, and `append` flags on the `OpenOptions` structure. This method provides fine-grained control over the permissions to read, write and append data, attributes (like hidden and system), and extended attributes.
##### Examples
```
use std::fs::OpenOptions;
use std::os::windows::prelude::*;
// Open without read and write permission, for example if you only need
// to call `stat` on the file
let file = OpenOptions::new().access_mode(0).open("foo.txt");
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#149)#### fn share\_mode(&mut self, val: u32) -> &mut Self
Overrides the `dwShareMode` argument to the call to [`CreateFile`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea) with the specified value.
By default `share_mode` is set to `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`. This allows other processes to read, write, and delete/rename the same file while it is open. Removing any of the flags will prevent other processes from performing the corresponding operation until the file handle is closed.
##### Examples
```
use std::fs::OpenOptions;
use std::os::windows::prelude::*;
// Do not allow others to read or modify this file while we have it open
// for writing.
let file = OpenOptions::new()
.write(true)
.share_mode(0)
.open("foo.txt");
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#180)#### fn custom\_flags(&mut self, flags: u32) -> &mut Self
Sets extra flags for the `dwFileFlags` argument to the call to [`CreateFile2`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2) to the specified value (or combines it with `attributes` and `security_qos_flags` to set the `dwFlagsAndAttributes` for [`CreateFile`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea)).
Custom flags can only set flags, not remove flags set by Rust’s options. This option overwrites any previously set custom flags.
##### Examples
```
extern crate winapi;
use std::fs::OpenOptions;
use std::os::windows::prelude::*;
let file = OpenOptions::new()
.create(true)
.write(true)
.custom_flags(winapi::FILE_FLAG_DELETE_ON_CLOSE)
.open("foo.txt");
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#218)#### fn attributes(&mut self, val: u32) -> &mut Self
Sets the `dwFileAttributes` argument to the call to [`CreateFile2`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2) to the specified value (or combines it with `custom_flags` and `security_qos_flags` to set the `dwFlagsAndAttributes` for [`CreateFile`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea)).
If a *new* file is created because it does not yet exist and `.create(true)` or `.create_new(true)` are specified, the new file is given the attributes declared with `.attributes()`.
If an *existing* file is opened with `.create(true).truncate(true)`, its existing attributes are preserved and combined with the ones declared with `.attributes()`.
In all other cases the attributes get ignored.
##### Examples
```
extern crate winapi;
use std::fs::OpenOptions;
use std::os::windows::prelude::*;
let file = OpenOptions::new()
.write(true)
.create(true)
.attributes(winapi::FILE_ATTRIBUTE_HIDDEN)
.open("foo.txt");
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#264)#### fn security\_qos\_flags(&mut self, flags: u32) -> &mut Self
Sets the `dwSecurityQosFlags` argument to the call to [`CreateFile2`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2) to the specified value (or combines it with `custom_flags` and `attributes` to set the `dwFlagsAndAttributes` for [`CreateFile`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea)).
By default `security_qos_flags` is not set. It should be specified when opening a named pipe, to control to which degree a server process can act on behalf of a client process (security impersonation level).
When `security_qos_flags` is not set, a malicious program can gain the elevated privileges of a privileged Rust process when it allows opening user-specified paths, by tricking it into opening a named pipe. So arguably `security_qos_flags` should also be set when opening arbitrary paths. However the bits can then conflict with other flags, specifically `FILE_FLAG_OPEN_NO_RECALL`.
For information about possible values, see [Impersonation Levels](https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-security_impersonation_level) on the Windows Dev Center site. The `SECURITY_SQOS_PRESENT` flag is set automatically when using this method.
##### Examples
```
extern crate winapi;
use std::fs::OpenOptions;
use std::os::windows::prelude::*;
let file = OpenOptions::new()
.write(true)
.create(true)
// Sets the flag value to `SecurityIdentification`.
.security_qos_flags(winapi::SECURITY_IDENTIFICATION)
.open(r"\\.\pipe\MyPipe");
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#268-293)### impl OpenOptionsExt for OpenOptions
rust Trait std::os::windows::fs::MetadataExt Trait std::os::windows::fs::MetadataExt
=======================================
```
pub trait MetadataExt {
fn file_attributes(&self) -> u32;
fn creation_time(&self) -> u64;
fn last_access_time(&self) -> u64;
fn last_write_time(&self) -> u64;
fn file_size(&self) -> u64;
fn volume_serial_number(&self) -> Option<u32>;
fn number_of_links(&self) -> Option<u32>;
fn file_index(&self) -> Option<u64>;
}
```
Available on **Windows** only.Windows-specific extensions to [`fs::Metadata`](../../../fs/struct.metadata "fs::Metadata").
The data members that this trait exposes correspond to the members of the [`BY_HANDLE_FILE_INFORMATION`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information) structure.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#327)#### fn file\_attributes(&self) -> u32
Returns the value of the `dwFileAttributes` field of this metadata.
This field contains the file system attribute information for a file or directory. For possible values and their descriptions, see [File Attribute Constants](https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants) in the Windows Dev Center.
##### Examples
```
use std::io;
use std::fs;
use std::os::windows::prelude::*;
fn main() -> io::Result<()> {
let metadata = fs::metadata("foo.txt")?;
let attributes = metadata.file_attributes();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#356)#### fn creation\_time(&self) -> u64
Returns the value of the `ftCreationTime` field of this metadata.
The returned 64-bit value is equivalent to a [`FILETIME`](https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime) struct, which represents the number of 100-nanosecond intervals since January 1, 1601 (UTC). The struct is automatically converted to a `u64` value, as that is the recommended way to use it.
If the underlying filesystem does not support creation time, the returned value is 0.
##### Examples
```
use std::io;
use std::fs;
use std::os::windows::prelude::*;
fn main() -> io::Result<()> {
let metadata = fs::metadata("foo.txt")?;
let creation_time = metadata.creation_time();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#391)#### fn last\_access\_time(&self) -> u64
Returns the value of the `ftLastAccessTime` field of this metadata.
The returned 64-bit value is equivalent to a [`FILETIME`](https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime) struct, which represents the number of 100-nanosecond intervals since January 1, 1601 (UTC). The struct is automatically converted to a `u64` value, as that is the recommended way to use it.
For a file, the value specifies the last time that a file was read from or written to. For a directory, the value specifies when the directory was created. For both files and directories, the specified date is correct, but the time of day is always set to midnight.
If the underlying filesystem does not support last access time, the returned value is 0.
##### Examples
```
use std::io;
use std::fs;
use std::os::windows::prelude::*;
fn main() -> io::Result<()> {
let metadata = fs::metadata("foo.txt")?;
let last_access_time = metadata.last_access_time();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#424)#### fn last\_write\_time(&self) -> u64
Returns the value of the `ftLastWriteTime` field of this metadata.
The returned 64-bit value is equivalent to a [`FILETIME`](https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime) struct, which represents the number of 100-nanosecond intervals since January 1, 1601 (UTC). The struct is automatically converted to a `u64` value, as that is the recommended way to use it.
For a file, the value specifies the last time that a file was written to. For a directory, the structure specifies when the directory was created.
If the underlying filesystem does not support the last write time, the returned value is 0.
##### Examples
```
use std::io;
use std::fs;
use std::os::windows::prelude::*;
fn main() -> io::Result<()> {
let metadata = fs::metadata("foo.txt")?;
let last_write_time = metadata.last_write_time();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#445)#### fn file\_size(&self) -> u64
Returns the value of the `nFileSize{High,Low}` fields of this metadata.
The returned value does not have meaning for directories.
##### Examples
```
use std::io;
use std::fs;
use std::os::windows::prelude::*;
fn main() -> io::Result<()> {
let metadata = fs::metadata("foo.txt")?;
let file_size = metadata.file_size();
Ok(())
}
```
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#454)#### fn volume\_serial\_number(&self) -> Option<u32>
🔬This is a nightly-only experimental API. (`windows_by_handle` [#63010](https://github.com/rust-lang/rust/issues/63010))
Returns the value of the `dwVolumeSerialNumber` field of this metadata.
This will return `None` if the `Metadata` instance was created from a call to `DirEntry::metadata`. If this `Metadata` was created by using `fs::metadata` or `File::metadata`, then this will return `Some`.
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#463)#### fn number\_of\_links(&self) -> Option<u32>
🔬This is a nightly-only experimental API. (`windows_by_handle` [#63010](https://github.com/rust-lang/rust/issues/63010))
Returns the value of the `nNumberOfLinks` field of this metadata.
This will return `None` if the `Metadata` instance was created from a call to `DirEntry::metadata`. If this `Metadata` was created by using `fs::metadata` or `File::metadata`, then this will return `Some`.
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#472)#### fn file\_index(&self) -> Option<u64>
🔬This is a nightly-only experimental API. (`windows_by_handle` [#63010](https://github.com/rust-lang/rust/issues/63010))
Returns the value of the `nFileIndex{Low,High}` fields of this metadata.
This will return `None` if the `Metadata` instance was created from a call to `DirEntry::metadata`. If this `Metadata` was created by using `fs::metadata` or `File::metadata`, then this will return `Some`.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#476-501)### impl MetadataExt for Metadata
| programming_docs |
rust Function std::os::windows::fs::symlink_dir Function std::os::windows::fs::symlink\_dir
===========================================
```
pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>( original: P, link: Q) -> Result<()>
```
Available on **Windows** only.Creates a new symlink to a directory on the filesystem.
The `link` path will be a directory symbolic link pointing to the `original` path.
The `original` path must be a directory or a symlink to a directory, otherwise the symlink will be broken. Use [`symlink_file`](fn.symlink_file "symlink_file") for other files.
This function currently corresponds to [`CreateSymbolicLinkW`](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw). Note that this [may change in the future](../../../io/index#platform-specific-behavior).
Examples
--------
```
use std::os::windows::fs;
fn main() -> std::io::Result<()> {
fs::symlink_dir("a", "b")?;
Ok(())
}
```
Limitations
-----------
Windows treats symlink creation as a [privileged action](https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links), therefore this function is likely to fail unless the user makes changes to their system to permit symlink creation. Users can try enabling Developer Mode, granting the `SeCreateSymbolicLinkPrivilege` privilege, or running the process as an administrator.
rust Module std::os::windows::thread Module std::os::windows::thread
===============================
Available on **Windows** only.Windows-specific extensions to primitives in the [`std::thread`](../../../thread/index) module.
rust Module std::os::windows::raw Module std::os::windows::raw
============================
Available on **Windows** only.Windows-specific primitives.
Type Definitions
----------------
[HANDLE](type.handle "std::os::windows::raw::HANDLE type")
[SOCKET](type.socket "std::os::windows::raw::SOCKET type")
rust Type Definition std::os::windows::raw::SOCKET Type Definition std::os::windows::raw::SOCKET
=============================================
```
pub type SOCKET = u64;
```
Available on **Windows** only.
rust Type Definition std::os::windows::raw::HANDLE Type Definition std::os::windows::raw::HANDLE
=============================================
```
pub type HANDLE = *mut c_void;
```
Available on **Windows** only.
rust Trait std::os::windows::process::ExitCodeExt Trait std::os::windows::process::ExitCodeExt
============================================
```
pub trait ExitCodeExt: Sealed {
fn from_raw(raw: u32) -> Self;
}
```
🔬This is a nightly-only experimental API. (`windows_process_exit_code_from`)
Available on **Windows** only.Windows-specific extensions to [`process::ExitCode`](../../../process/struct.exitcode "process::ExitCode").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#251)#### fn from\_raw(raw: u32) -> Self
🔬This is a nightly-only experimental API. (`windows_process_exit_code_from`)
Creates a new `ExitCode` from the raw underlying `u32` return value of a process.
The exit code should not be 259, as this conflicts with the `STILL_ACTIVE` macro returned from the `GetExitCodeProcess` function to signal that the process has yet to run to completion.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#255-259)### impl ExitCodeExt for ExitCode
rust Module std::os::windows::process Module std::os::windows::process
================================
Available on **Windows** only.Windows-specific extensions to primitives in the [`std::process`](../../../process/index) module.
Traits
------
[ChildExt](trait.childext "std::os::windows::process::ChildExt trait")Experimental
[ExitCodeExt](trait.exitcodeext "std::os::windows::process::ExitCodeExt trait")Experimental
Windows-specific extensions to [`process::ExitCode`](../../../process/struct.exitcode "process::ExitCode").
[CommandExt](trait.commandext "std::os::windows::process::CommandExt trait")
Windows-specific extensions to the [`process::Command`](../../../process/struct.command "process::Command") builder.
[ExitStatusExt](trait.exitstatusext "std::os::windows::process::ExitStatusExt trait")
Windows-specific extensions to [`process::ExitStatus`](../../../process/struct.exitstatus "process::ExitStatus").
rust Trait std::os::windows::process::ExitStatusExt Trait std::os::windows::process::ExitStatusExt
==============================================
```
pub trait ExitStatusExt: Sealed {
fn from_raw(raw: u32) -> Self;
}
```
Available on **Windows** only.Windows-specific extensions to [`process::ExitStatus`](../../../process/struct.exitstatus "process::ExitStatus").
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#118)#### fn from\_raw(raw: u32) -> Self
Creates a new `ExitStatus` from the raw underlying `u32` return value of a process.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#122-126)### impl ExitStatusExt for ExitStatus
rust Trait std::os::windows::process::ChildExt Trait std::os::windows::process::ChildExt
=========================================
```
pub trait ChildExt: Sealed {
fn main_thread_handle(&self) -> BorrowedHandle<'_>;
}
```
🔬This is a nightly-only experimental API. (`windows_process_extensions_main_thread_handle` [#96723](https://github.com/rust-lang/rust/issues/96723))
Available on **Windows** only.Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#228)#### fn main\_thread\_handle(&self) -> BorrowedHandle<'\_>
🔬This is a nightly-only experimental API. (`windows_process_extensions_main_thread_handle` [#96723](https://github.com/rust-lang/rust/issues/96723))
Extracts the main thread raw handle, without taking ownership
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#232-236)### impl ChildExt for Child
rust Trait std::os::windows::process::CommandExt Trait std::os::windows::process::CommandExt
===========================================
```
pub trait CommandExt: Sealed {
fn creation_flags(&mut self, flags: u32) -> &mut Command;
fn force_quotes(&mut self, enabled: bool) -> &mut Command;
fn raw_arg<S: AsRef<OsStr>>( &mut self, text_to_append_as_is: S ) -> &mut Command;
fn async_pipes(&mut self, always_async: bool) -> &mut Command;
}
```
Available on **Windows** only.Windows-specific extensions to the [`process::Command`](../../../process/struct.command "process::Command") builder.
This trait is sealed: it cannot be implemented outside the standard library. This is so that future additional methods are not breaking changes.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#140)#### fn creation\_flags(&mut self, flags: u32) -> &mut Command
Sets the [process creation flags](https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags) to be passed to `CreateProcess`.
These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`.
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#156)#### fn force\_quotes(&mut self, enabled: bool) -> &mut Command
🔬This is a nightly-only experimental API. (`windows_process_extensions_force_quotes` [#82227](https://github.com/rust-lang/rust/issues/82227))
Forces all arguments to be wrapped in quote (`"`) characters.
This is useful for passing arguments to [MSYS2/Cygwin](https://github.com/msys2/MSYS2-packages/issues/2176) based executables: these programs will expand unquoted arguments containing wildcard characters (`?` and `*`) by searching for any file paths matching the wildcard pattern.
Adding quotes has no effect when passing arguments to programs that use [msvcrt](https://msdn.microsoft.com/en-us/library/17w5ykft.aspx). This includes programs built with both MinGW and MSVC.
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#163)1.62.0 · #### fn raw\_arg<S: AsRef<OsStr>>(&mut self, text\_to\_append\_as\_is: S) -> &mut Command
Append literal text to the command line without any quoting or escaping.
This is useful for passing arguments to `cmd.exe /c`, which doesn’t follow `CommandLineToArgvW` escaping rules.
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#194)#### fn async\_pipes(&mut self, always\_async: bool) -> &mut Command
🔬This is a nightly-only experimental API. (`windows_process_extensions_async_pipes` [#98289](https://github.com/rust-lang/rust/issues/98289))
When [`process::Command`](../../../process/struct.command "process::Command") creates pipes, request that our side is always async.
By default [`process::Command`](../../../process/struct.command "process::Command") may choose to use pipes where both ends are opened for synchronous read or write operations. By using `async_pipes(true)`, this behavior is overridden so that our side is always async.
This is important because if doing async I/O a pipe or a file has to be opened for async access.
The end of the pipe sent to the child process will always be synchronous regardless of this option.
##### Example
```
#![feature(windows_process_extensions_async_pipes)]
use std::os::windows::process::CommandExt;
use std::process::{Command, Stdio};
Command::new(program)
.async_pipes(true)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
```
Implementors
------------
[source](https://doc.rust-lang.org/src/std/os/windows/process.rs.html#198-222)### impl CommandExt for Command
rust Type Definition std::os::raw::c_int Type Definition std::os::raw::c\_int
====================================
```
pub type c_int = c_int;
```
Equivalent to C’s `signed int` (`int`) type.
This type will almost always be [`i32`](../../primitive.i32 "i32"), but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer that is at least the size of a [`short`](type.c_short); some systems define it as an [`i16`](../../primitive.i16 "i16"), for example.
rust Type Definition std::os::raw::c_double Type Definition std::os::raw::c\_double
=======================================
```
pub type c_double = c_double;
```
Equivalent to C’s `double` type.
This type will almost always be [`f64`](../../primitive.f64 "f64"), which is guaranteed to be an [IEEE 754 double-precision float](https://en.wikipedia.org/wiki/IEEE_754) in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`](type.c_float), and it may be `f32` or something entirely different from the IEEE-754 standard.
rust Type Definition std::os::raw::c_char Type Definition std::os::raw::c\_char
=====================================
```
pub type c_char = c_char;
```
Equivalent to C’s `char` type.
[C’s `char` type](https://en.wikipedia.org/wiki/C_data_types#Basic_types) is completely unlike [Rust’s `char` type](../../primitive.char); while Rust’s type represents a unicode scalar value, C’s `char` type is just an ordinary integer. On modern architectures this type will always be either [`i8`](../../primitive.i8 "i8") or [`u8`](../../primitive.u8 "u8"), as they use byte-addresses memory with 8-bit bytes.
C chars are most commonly used to make C strings. Unlike Rust, where the length of a string is included alongside the string, C strings mark the end of a string with the character `'\0'`. See `CStr` for more information.
rust Type Definition std::os::raw::c_short Type Definition std::os::raw::c\_short
======================================
```
pub type c_short = c_short;
```
Equivalent to C’s `signed short` (`short`) type.
This type will almost always be [`i16`](../../primitive.i16 "i16"), but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer with at least 16 bits; some systems may define it as `i32`, for example.
rust Module std::os::raw Module std::os::raw
===================
Compatibility module for C platform-specific types. Use [`core::ffi`](https://doc.rust-lang.org/core/ffi/index.html "core::ffi") instead.
Type Definitions
----------------
[c\_char](type.c_char "std::os::raw::c_char type")
Equivalent to C’s `char` type.
[c\_double](type.c_double "std::os::raw::c_double type")
Equivalent to C’s `double` type.
[c\_float](type.c_float "std::os::raw::c_float type")
Equivalent to C’s `float` type.
[c\_int](type.c_int "std::os::raw::c_int type")
Equivalent to C’s `signed int` (`int`) type.
[c\_long](type.c_long "std::os::raw::c_long type")
Equivalent to C’s `signed long` (`long`) type.
[c\_longlong](type.c_longlong "std::os::raw::c_longlong type")
Equivalent to C’s `signed long long` (`long long`) type.
[c\_schar](type.c_schar "std::os::raw::c_schar type")
Equivalent to C’s `signed char` type.
[c\_short](type.c_short "std::os::raw::c_short type")
Equivalent to C’s `signed short` (`short`) type.
[c\_uchar](type.c_uchar "std::os::raw::c_uchar type")
Equivalent to C’s `unsigned char` type.
[c\_uint](type.c_uint "std::os::raw::c_uint type")
Equivalent to C’s `unsigned int` type.
[c\_ulong](type.c_ulong "std::os::raw::c_ulong type")
Equivalent to C’s `unsigned long` type.
[c\_ulonglong](type.c_ulonglong "std::os::raw::c_ulonglong type")
Equivalent to C’s `unsigned long long` type.
[c\_ushort](type.c_ushort "std::os::raw::c_ushort type")
Equivalent to C’s `unsigned short` type.
[c\_void](type.c_void "std::os::raw::c_void type")
Equivalent to C’s `void` type when used as a [pointer](../../primitive.pointer "pointer").
rust Type Definition std::os::raw::c_uint Type Definition std::os::raw::c\_uint
=====================================
```
pub type c_uint = c_uint;
```
Equivalent to C’s `unsigned int` type.
This type will almost always be [`u32`](../../primitive.u32 "u32"), but may differ on some esoteric systems. The C standard technically only requires that this type be an unsigned integer with the same size as an [`int`](type.c_int); some systems define it as a [`u16`](../../primitive.u16 "u16"), for example.
rust Type Definition std::os::raw::c_schar Type Definition std::os::raw::c\_schar
======================================
```
pub type c_schar = c_schar;
```
Equivalent to C’s `signed char` type.
This type will always be [`i8`](../../primitive.i8 "i8"), but is included for completeness. It is defined as being a signed integer the same size as a C [`char`](type.c_char).
rust Type Definition std::os::raw::c_float Type Definition std::os::raw::c\_float
======================================
```
pub type c_float = c_float;
```
Equivalent to C’s `float` type.
This type will almost always be [`f32`](../../primitive.f32 "f32"), which is guaranteed to be an [IEEE 754 single-precision float](https://en.wikipedia.org/wiki/IEEE_754) in Rust. That said, the standard technically only guarantees that it be a floating-point number, and it may have less precision than `f32` or not follow the IEEE-754 standard at all.
rust Type Definition std::os::raw::c_uchar Type Definition std::os::raw::c\_uchar
======================================
```
pub type c_uchar = c_uchar;
```
Equivalent to C’s `unsigned char` type.
This type will always be [`u8`](../../primitive.u8 "u8"), but is included for completeness. It is defined as being an unsigned integer the same size as a C [`char`](type.c_char).
rust Type Definition std::os::raw::c_longlong Type Definition std::os::raw::c\_longlong
=========================================
```
pub type c_longlong = c_longlong;
```
Equivalent to C’s `signed long long` (`long long`) type.
This type will almost always be [`i64`](../../primitive.i64 "i64"), but may differ on some systems. The C standard technically only requires that this type be a signed integer that is at least 64 bits and at least the size of a [`long`](type.c_int), although in practice, no system would have a `long long` that is not an `i64`, as most systems do not have a standardised [`i128`](../../primitive.i128 "i128") type.
rust Type Definition std::os::raw::c_ushort Type Definition std::os::raw::c\_ushort
=======================================
```
pub type c_ushort = c_ushort;
```
Equivalent to C’s `unsigned short` type.
This type will almost always be [`u16`](../../primitive.u16 "u16"), but may differ on some esoteric systems. The C standard technically only requires that this type be an unsigned integer with the same size as a [`short`](type.c_short).
rust Type Definition std::os::raw::c_ulong Type Definition std::os::raw::c\_ulong
======================================
```
pub type c_ulong = c_ulong;
```
Equivalent to C’s `unsigned long` type.
This type will always be [`u32`](../../primitive.u32 "u32") or [`u64`](../../primitive.u64 "u64"). Most notably, many Linux-based systems assume an `u64`, but Windows assumes `u32`. The C standard technically only requires that this type be an unsigned integer with the size of a [`long`](type.c_long), although in practice, no system would have a `ulong` that is neither a `u32` nor `u64`.
rust Type Definition std::os::raw::c_ulonglong Type Definition std::os::raw::c\_ulonglong
==========================================
```
pub type c_ulonglong = c_ulonglong;
```
Equivalent to C’s `unsigned long long` type.
This type will almost always be [`u64`](../../primitive.u64 "u64"), but may differ on some systems. The C standard technically only requires that this type be an unsigned integer with the size of a [`long long`](type.c_longlong), although in practice, no system would have a `long long` that is not a `u64`, as most systems do not have a standardised [`u128`](../../primitive.u128 "u128") type.
rust Type Definition std::os::raw::c_long Type Definition std::os::raw::c\_long
=====================================
```
pub type c_long = c_long;
```
Equivalent to C’s `signed long` (`long`) type.
This type will always be [`i32`](../../primitive.i32 "i32") or [`i64`](../../primitive.i64 "i64"). Most notably, many Linux-based systems assume an `i64`, but Windows assumes `i32`. The C standard technically only requires that this type be a signed integer that is at least 32 bits and at least the size of an [`int`](type.c_int), although in practice, no system would have a `long` that is neither an `i32` nor `i64`.
rust Type Definition std::os::raw::c_void Type Definition std::os::raw::c\_void
=====================================
```
pub type c_void = c_void;
```
Equivalent to C’s `void` type when used as a [pointer](../../primitive.pointer "pointer").
In essence, `*const c_void` is equivalent to C’s `const void*` and `*mut c_void` is equivalent to C’s `void*`. That said, this is *not* the same as C’s `void` return type, which is Rust’s `()` type.
To model pointers to opaque types in FFI, until `extern type` is stabilized, it is recommended to use a newtype wrapper around an empty byte array. See the [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs) for details.
One could use `std::os::raw::c_void` if they want to support old Rust compiler down to 1.1.0. After Rust 1.30.0, it was re-exported by this definition. For more information, please read [RFC 2521](https://github.com/rust-lang/rfcs/blob/master/text/2521-c_void-reunification.md).
rust Function std::intrinsics::wrapping_sub Function std::intrinsics::wrapping\_sub
=======================================
```
pub const extern "rust-intrinsic" fn wrapping_sub<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns (a - b) mod 2N, where N is the width of T in bits.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `wrapping_sub` method. For example, [`u32::wrapping_sub`](../primitive.u32#method.wrapping_sub "u32::wrapping_sub")
| programming_docs |
rust Function std::intrinsics::atomic_or_seqcst Function std::intrinsics::atomic\_or\_seqcst
============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_or_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise or with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_or` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicBool::fetch_or`](../sync/atomic/struct.atomicbool#method.fetch_or "AtomicBool::fetch_or").
rust Function std::intrinsics::raw_eq Function std::intrinsics::raw\_eq
=================================
```
pub unsafe extern "rust-intrinsic" fn raw_eq<T>(a: &T, b: &T) -> bool
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Determines whether the raw bytes of the two values are equal.
This is particularly handy for arrays, since it allows things like just comparing `i96`s instead of forcing `alloca`s for `[6 x i16]`.
Above some backend-decided threshold this will emit calls to `memcmp`, like slice equality does, instead of causing massive code size.
Safety
------
It’s UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized or carry a pointer value. Note that this is a stricter criterion than just the *values* being fully-initialized: if `T` has padding, it’s UB to call this intrinsic.
(The implementation is allowed to branch on the results of comparisons, which is UB if any of their inputs are `undef`.)
rust Function std::intrinsics::atomic_max_relaxed Function std::intrinsics::atomic\_max\_relaxed
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_max_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_max` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicI32::fetch_max`](../sync/atomic/struct.atomici32#method.fetch_max "AtomicI32::fetch_max").
rust Function std::intrinsics::atomic_nand_release Function std::intrinsics::atomic\_nand\_release
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_nand_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise nand with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`AtomicBool`](../sync/atomic/struct.atomicbool "AtomicBool") type via the `fetch_nand` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicBool::fetch_nand`](../sync/atomic/struct.atomicbool#method.fetch_nand "AtomicBool::fetch_nand").
rust Function std::intrinsics::atomic_cxchgweak_relaxed_relaxed Function std::intrinsics::atomic\_cxchgweak\_relaxed\_relaxed
=============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_relaxed_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as both the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::nontemporal_store Function std::intrinsics::nontemporal\_store
============================================
```
pub unsafe extern "rust-intrinsic" fn nontemporal_store<T>( ptr: *mut T, val: T)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Emits a `!nontemporal` store according to LLVM (see their docs). Probably will never become stable.
rust Function std::intrinsics::atomic_min_relaxed Function std::intrinsics::atomic\_min\_relaxed
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_min_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_min` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicI32::fetch_min`](../sync/atomic/struct.atomici32#method.fetch_min "AtomicI32::fetch_min").
rust Function std::intrinsics::atomic_xchg_relaxed Function std::intrinsics::atomic\_xchg\_relaxed
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xchg_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location, returning the old value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `swap` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicBool::swap`](../sync/atomic/struct.atomicbool#method.swap "AtomicBool::swap").
rust Function std::intrinsics::atomic_xor_release Function std::intrinsics::atomic\_xor\_release
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xor_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise xor with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_xor` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicBool::fetch_xor`](../sync/atomic/struct.atomicbool#method.fetch_xor "AtomicBool::fetch_xor").
rust Function std::intrinsics::nearbyintf64 Function std::intrinsics::nearbyintf64
======================================
```
pub unsafe extern "rust-intrinsic" fn nearbyintf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the nearest integer to an `f64`.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::fmaf64 Function std::intrinsics::fmaf64
================================
```
pub unsafe extern "rust-intrinsic" fn fmaf64( a: f64, b: f64, c: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns `a * b + c` for `f64` values.
The stabilized version of this intrinsic is [`f64::mul_add`](../primitive.f64#method.mul_add)
rust Function std::intrinsics::type_id Function std::intrinsics::type\_id
==================================
```
pub extern "rust-intrinsic" fn type_id<T>() -> u64where T: 'static + ?Sized,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Gets an identifier which is globally unique to the specified type. This function will return the same value for a type regardless of whichever crate it is invoked in.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`core::any::TypeId::of`](../any/struct.typeid#method.of "core::any::TypeId::of").
rust Function std::intrinsics::atomic_load_acquire Function std::intrinsics::atomic\_load\_acquire
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_load_acquire<T>( src: *const T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Loads the current value of the pointer.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `load` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicBool::load`](../sync/atomic/struct.atomicbool#method.load "AtomicBool::load").
rust Function std::intrinsics::discriminant_value Function std::intrinsics::discriminant\_value
=============================================
```
pub extern "rust-intrinsic" fn discriminant_value<T>( v: &T) -> <T as DiscriminantKind>::Discriminant
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the value of the discriminant for the variant in ‘v’; if `T` has no discriminant, returns `0`.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`core::mem::discriminant`](../mem/fn.discriminant "core::mem::discriminant").
rust Function std::intrinsics::atomic_cxchgweak_release_relaxed Function std::intrinsics::atomic\_cxchgweak\_release\_relaxed
=============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_release_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::atomic_cxchg_relaxed_seqcst Function std::intrinsics::atomic\_cxchg\_relaxed\_seqcst
========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_relaxed_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::atomic_xadd_relaxed Function std::intrinsics::atomic\_xadd\_relaxed
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xadd_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Adds to the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_add` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicIsize::fetch_add`](../sync/atomic/struct.atomicisize#method.fetch_add "AtomicIsize::fetch_add").
rust Function std::intrinsics::abort Function std::intrinsics::abort
===============================
```
pub extern "rust-intrinsic" fn abort() -> !
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Aborts the execution of the process.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
[`std::process::abort`](../process/fn.abort) is to be preferred if possible, as its behavior is more user-friendly and more stable.
The current implementation of `intrinsics::abort` is to invoke an invalid instruction, on most platforms. On Unix, the process will probably terminate with a signal like `SIGABRT`, `SIGILL`, `SIGTRAP`, `SIGSEGV` or `SIGBUS`. The precise behaviour is not guaranteed and not stable.
rust Function std::intrinsics::atomic_umax_seqcst Function std::intrinsics::atomic\_umax\_seqcst
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umax_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_max` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicU32::fetch_max`](../sync/atomic/struct.atomicu32#method.fetch_max "AtomicU32::fetch_max").
rust Function std::intrinsics::float_to_int_unchecked Function std::intrinsics::float\_to\_int\_unchecked
===================================================
```
pub unsafe extern "rust-intrinsic" fn float_to_int_unchecked<Float, Int>( value: Float) -> Intwhere Float: Copy, Int: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range (<https://github.com/rust-lang/rust/issues/10184>)
Stabilized as [`f32::to_int_unchecked`](../primitive.f32#method.to_int_unchecked "f32::to_int_unchecked") and [`f64::to_int_unchecked`](../primitive.f64#method.to_int_unchecked "f64::to_int_unchecked").
rust Function std::intrinsics::atomic_cxchg_seqcst_relaxed Function std::intrinsics::atomic\_cxchg\_seqcst\_relaxed
========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_seqcst_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::powf32 Function std::intrinsics::powf32
================================
```
pub unsafe extern "rust-intrinsic" fn powf32(a: f32, x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Raises an `f32` to an `f32` power.
The stabilized version of this intrinsic is [`f32::powf`](../primitive.f32#method.powf)
rust Function std::intrinsics::saturating_add Function std::intrinsics::saturating\_add
=========================================
```
pub const extern "rust-intrinsic" fn saturating_add<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Computes `a + b`, saturating at numeric bounds.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `saturating_add` method. For example, [`u32::saturating_add`](../primitive.u32#method.saturating_add "u32::saturating_add")
rust Function std::intrinsics::atomic_and_relaxed Function std::intrinsics::atomic\_and\_relaxed
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_and_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise and with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_and` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicBool::fetch_and`](../sync/atomic/struct.atomicbool#method.fetch_and "AtomicBool::fetch_and").
rust Function std::intrinsics::atomic_umin_acquire Function std::intrinsics::atomic\_umin\_acquire
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umin_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_min` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicU32::fetch_min`](../sync/atomic/struct.atomicu32#method.fetch_min "AtomicU32::fetch_min").
rust Function std::intrinsics::fmul_fast Function std::intrinsics::fmul\_fast
====================================
```
pub unsafe extern "rust-intrinsic" fn fmul_fast<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Float multiplication that allows optimizations based on algebraic rules. May assume inputs are finite.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::expf32 Function std::intrinsics::expf32
================================
```
pub unsafe extern "rust-intrinsic" fn expf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the exponential of an `f32`.
The stabilized version of this intrinsic is [`f32::exp`](../primitive.f32#method.exp)
rust Function std::intrinsics::minnumf64 Function std::intrinsics::minnumf64
===================================
```
pub extern "rust-intrinsic" fn minnumf64(x: f64, y: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the minimum of two `f64` values.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`f64::min`](../primitive.f64#method.min "f64::min")
rust Function std::intrinsics::exp2f64 Function std::intrinsics::exp2f64
=================================
```
pub unsafe extern "rust-intrinsic" fn exp2f64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns 2 raised to the power of an `f64`.
The stabilized version of this intrinsic is [`f64::exp2`](../primitive.f64#method.exp2)
| programming_docs |
rust Function std::intrinsics::atomic_min_seqcst Function std::intrinsics::atomic\_min\_seqcst
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_min_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_min` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicI32::fetch_min`](../sync/atomic/struct.atomici32#method.fetch_min "AtomicI32::fetch_min").
rust Function std::intrinsics::atomic_singlethreadfence_seqcst Function std::intrinsics::atomic\_singlethreadfence\_seqcst
===========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_singlethreadfence_seqcst()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
A compiler-only memory barrier.
Memory accesses will never be reordered across this barrier by the compiler, but no instructions will be emitted for it. This is appropriate for operations on the same thread that may be preempted, such as when interacting with signal handlers.
The stabilized version of this intrinsic is available in [`atomic::compiler_fence`](../sync/atomic/fn.compiler_fence "atomic::compiler_fence") by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`.
rust Function std::intrinsics::size_of_val Function std::intrinsics::size\_of\_val
=======================================
```
pub unsafe extern "rust-intrinsic" fn size_of_val<T>( *const T) -> usizewhere T: ?Sized,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The size of the referenced value in bytes.
The stabilized version of this intrinsic is [`mem::size_of_val`](../mem/fn.size_of_val "mem::size_of_val").
rust Function std::intrinsics::unaligned_volatile_load Function std::intrinsics::unaligned\_volatile\_load
===================================================
```
pub unsafe extern "rust-intrinsic" fn unaligned_volatile_load<T>( src: *const T) -> T
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs a volatile load from the `src` pointer The pointer is not required to be aligned.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_umax_acquire Function std::intrinsics::atomic\_umax\_acquire
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umax_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_max` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicU32::fetch_max`](../sync/atomic/struct.atomicu32#method.fetch_max "AtomicU32::fetch_max").
rust Function std::intrinsics::fabsf32 Function std::intrinsics::fabsf32
=================================
```
pub unsafe extern "rust-intrinsic" fn fabsf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the absolute value of an `f32`.
The stabilized version of this intrinsic is [`f32::abs`](../primitive.f32#method.abs)
rust Function std::intrinsics::vtable_align Function std::intrinsics::vtable\_align
=======================================
```
pub unsafe extern "rust-intrinsic" fn vtable_align( ptr: *const ()) -> usize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
`ptr` must point to a vtable. The intrinsic will return the alignment stored in that vtable.
rust Function std::intrinsics::exp2f32 Function std::intrinsics::exp2f32
=================================
```
pub unsafe extern "rust-intrinsic" fn exp2f32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns 2 raised to the power of an `f32`.
The stabilized version of this intrinsic is [`f32::exp2`](../primitive.f32#method.exp2)
rust Function std::intrinsics::atomic_load_seqcst Function std::intrinsics::atomic\_load\_seqcst
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_load_seqcst<T>( src: *const T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Loads the current value of the pointer.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `load` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicBool::load`](../sync/atomic/struct.atomicbool#method.load "AtomicBool::load").
rust Function std::intrinsics::atomic_or_relaxed Function std::intrinsics::atomic\_or\_relaxed
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_or_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise or with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_or` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicBool::fetch_or`](../sync/atomic/struct.atomicbool#method.fetch_or "AtomicBool::fetch_or").
rust Function std::intrinsics::fabsf64 Function std::intrinsics::fabsf64
=================================
```
pub unsafe extern "rust-intrinsic" fn fabsf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the absolute value of an `f64`.
The stabilized version of this intrinsic is [`f64::abs`](../primitive.f64#method.abs)
rust Module std::intrinsics Module std::intrinsics
======================
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Compiler intrinsics.
The corresponding definitions are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>. The corresponding const implementations are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
Const intrinsics
----------------
Note: any changes to the constness of intrinsics should be discussed with the language team. This includes changes in the stability of the constness.
In order to make an intrinsic usable at compile-time, one needs to copy the implementation from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs> to <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs> and add a `#[rustc_const_unstable(feature = "const_such_and_such", issue = "01234")]` to the intrinsic declaration.
If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute, the intrinsic’s attribute must be `rustc_const_stable`, too. Such a change should not be done without T-lang consultation, because it bakes a feature into the language that cannot be replicated in user code without compiler support.
Volatiles
---------
The volatile intrinsics provide operations intended to act on I/O memory, which are guaranteed to not be reordered by the compiler across other volatile intrinsics. See the LLVM documentation on [[volatile](https://llvm.org/docs/LangRef.html#volatile-memory-accesses)].
Atomics
-------
The atomic intrinsics provide common atomic operations on machine words, with multiple possible memory orderings. They obey the same semantics as C++11. See the LLVM documentation on [[atomics](https://llvm.org/docs/Atomics.html)].
A quick refresher on memory ordering:
* Acquire - a barrier for acquiring a lock. Subsequent reads and writes take place after the barrier.
* Release - a barrier for releasing a lock. Preceding reads and writes take place before the barrier.
* Sequentially consistent - sequentially consistent operations are guaranteed to happen in order. This is the standard mode for working with atomic types and is equivalent to Java’s `volatile`.
Functions
---------
[abort](fn.abort "std::intrinsics::abort fn")Experimental
Aborts the execution of the process.
[add\_with\_overflow](fn.add_with_overflow "std::intrinsics::add_with_overflow fn")Experimental
Performs checked integer addition.
[arith\_offset](fn.arith_offset "std::intrinsics::arith_offset fn")[⚠](# "unsafe function")Experimental
Calculates the offset from a pointer, potentially wrapping.
[assert\_inhabited](fn.assert_inhabited "std::intrinsics::assert_inhabited fn")Experimental
A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: This will statically either panic, or do nothing.
[assert\_uninit\_valid](fn.assert_uninit_valid "std::intrinsics::assert_uninit_valid fn")Experimental
A guard for unsafe functions that cannot ever be executed if `T` has invalid bit patterns: This will statically either panic, or do nothing.
[assert\_zero\_valid](fn.assert_zero_valid "std::intrinsics::assert_zero_valid fn")Experimental
A guard for unsafe functions that cannot ever be executed if `T` does not permit zero-initialization: This will statically either panic, or do nothing.
[assume](fn.assume "std::intrinsics::assume fn")[⚠](# "unsafe function")Experimental
Informs the optimizer that a condition is always true. If the condition is false, the behavior is undefined.
[atomic\_and\_acqrel](fn.atomic_and_acqrel "std::intrinsics::atomic_and_acqrel fn")[⚠](# "unsafe function")Experimental
Bitwise and with the current value, returning the previous value.
[atomic\_and\_acquire](fn.atomic_and_acquire "std::intrinsics::atomic_and_acquire fn")[⚠](# "unsafe function")Experimental
Bitwise and with the current value, returning the previous value.
[atomic\_and\_relaxed](fn.atomic_and_relaxed "std::intrinsics::atomic_and_relaxed fn")[⚠](# "unsafe function")Experimental
Bitwise and with the current value, returning the previous value.
[atomic\_and\_release](fn.atomic_and_release "std::intrinsics::atomic_and_release fn")[⚠](# "unsafe function")Experimental
Bitwise and with the current value, returning the previous value.
[atomic\_and\_seqcst](fn.atomic_and_seqcst "std::intrinsics::atomic_and_seqcst fn")[⚠](# "unsafe function")Experimental
Bitwise and with the current value, returning the previous value.
[atomic\_cxchg\_acqrel\_acquire](fn.atomic_cxchg_acqrel_acquire "std::intrinsics::atomic_cxchg_acqrel_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_acqrel\_relaxed](fn.atomic_cxchg_acqrel_relaxed "std::intrinsics::atomic_cxchg_acqrel_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_acqrel\_seqcst](fn.atomic_cxchg_acqrel_seqcst "std::intrinsics::atomic_cxchg_acqrel_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_acquire\_acquire](fn.atomic_cxchg_acquire_acquire "std::intrinsics::atomic_cxchg_acquire_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_acquire\_relaxed](fn.atomic_cxchg_acquire_relaxed "std::intrinsics::atomic_cxchg_acquire_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_acquire\_seqcst](fn.atomic_cxchg_acquire_seqcst "std::intrinsics::atomic_cxchg_acquire_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_relaxed\_acquire](fn.atomic_cxchg_relaxed_acquire "std::intrinsics::atomic_cxchg_relaxed_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_relaxed\_relaxed](fn.atomic_cxchg_relaxed_relaxed "std::intrinsics::atomic_cxchg_relaxed_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_relaxed\_seqcst](fn.atomic_cxchg_relaxed_seqcst "std::intrinsics::atomic_cxchg_relaxed_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_release\_acquire](fn.atomic_cxchg_release_acquire "std::intrinsics::atomic_cxchg_release_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_release\_relaxed](fn.atomic_cxchg_release_relaxed "std::intrinsics::atomic_cxchg_release_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_release\_seqcst](fn.atomic_cxchg_release_seqcst "std::intrinsics::atomic_cxchg_release_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_seqcst\_acquire](fn.atomic_cxchg_seqcst_acquire "std::intrinsics::atomic_cxchg_seqcst_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_seqcst\_relaxed](fn.atomic_cxchg_seqcst_relaxed "std::intrinsics::atomic_cxchg_seqcst_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchg\_seqcst\_seqcst](fn.atomic_cxchg_seqcst_seqcst "std::intrinsics::atomic_cxchg_seqcst_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_acqrel\_acquire](fn.atomic_cxchgweak_acqrel_acquire "std::intrinsics::atomic_cxchgweak_acqrel_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_acqrel\_relaxed](fn.atomic_cxchgweak_acqrel_relaxed "std::intrinsics::atomic_cxchgweak_acqrel_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_acqrel\_seqcst](fn.atomic_cxchgweak_acqrel_seqcst "std::intrinsics::atomic_cxchgweak_acqrel_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_acquire\_acquire](fn.atomic_cxchgweak_acquire_acquire "std::intrinsics::atomic_cxchgweak_acquire_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_acquire\_relaxed](fn.atomic_cxchgweak_acquire_relaxed "std::intrinsics::atomic_cxchgweak_acquire_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_acquire\_seqcst](fn.atomic_cxchgweak_acquire_seqcst "std::intrinsics::atomic_cxchgweak_acquire_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_relaxed\_acquire](fn.atomic_cxchgweak_relaxed_acquire "std::intrinsics::atomic_cxchgweak_relaxed_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_relaxed\_relaxed](fn.atomic_cxchgweak_relaxed_relaxed "std::intrinsics::atomic_cxchgweak_relaxed_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_relaxed\_seqcst](fn.atomic_cxchgweak_relaxed_seqcst "std::intrinsics::atomic_cxchgweak_relaxed_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_release\_acquire](fn.atomic_cxchgweak_release_acquire "std::intrinsics::atomic_cxchgweak_release_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_release\_relaxed](fn.atomic_cxchgweak_release_relaxed "std::intrinsics::atomic_cxchgweak_release_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_release\_seqcst](fn.atomic_cxchgweak_release_seqcst "std::intrinsics::atomic_cxchgweak_release_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_seqcst\_acquire](fn.atomic_cxchgweak_seqcst_acquire "std::intrinsics::atomic_cxchgweak_seqcst_acquire fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_seqcst\_relaxed](fn.atomic_cxchgweak_seqcst_relaxed "std::intrinsics::atomic_cxchgweak_seqcst_relaxed fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_cxchgweak\_seqcst\_seqcst](fn.atomic_cxchgweak_seqcst_seqcst "std::intrinsics::atomic_cxchgweak_seqcst_seqcst fn")[⚠](# "unsafe function")Experimental
Stores a value if the current value is the same as the `old` value.
[atomic\_fence\_acqrel](fn.atomic_fence_acqrel "std::intrinsics::atomic_fence_acqrel fn")[⚠](# "unsafe function")Experimental
An atomic fence.
[atomic\_fence\_acquire](fn.atomic_fence_acquire "std::intrinsics::atomic_fence_acquire fn")[⚠](# "unsafe function")Experimental
An atomic fence.
[atomic\_fence\_release](fn.atomic_fence_release "std::intrinsics::atomic_fence_release fn")[⚠](# "unsafe function")Experimental
An atomic fence.
[atomic\_fence\_seqcst](fn.atomic_fence_seqcst "std::intrinsics::atomic_fence_seqcst fn")[⚠](# "unsafe function")Experimental
An atomic fence.
[atomic\_load\_acquire](fn.atomic_load_acquire "std::intrinsics::atomic_load_acquire fn")[⚠](# "unsafe function")Experimental
Loads the current value of the pointer.
[atomic\_load\_relaxed](fn.atomic_load_relaxed "std::intrinsics::atomic_load_relaxed fn")[⚠](# "unsafe function")Experimental
Loads the current value of the pointer.
[atomic\_load\_seqcst](fn.atomic_load_seqcst "std::intrinsics::atomic_load_seqcst fn")[⚠](# "unsafe function")Experimental
Loads the current value of the pointer.
[atomic\_load\_unordered](fn.atomic_load_unordered "std::intrinsics::atomic_load_unordered fn")[⚠](# "unsafe function")Experimental
[atomic\_max\_acqrel](fn.atomic_max_acqrel "std::intrinsics::atomic_max_acqrel fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using a signed comparison.
[atomic\_max\_acquire](fn.atomic_max_acquire "std::intrinsics::atomic_max_acquire fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using a signed comparison.
[atomic\_max\_relaxed](fn.atomic_max_relaxed "std::intrinsics::atomic_max_relaxed fn")[⚠](# "unsafe function")Experimental
Maximum with the current value.
[atomic\_max\_release](fn.atomic_max_release "std::intrinsics::atomic_max_release fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using a signed comparison.
[atomic\_max\_seqcst](fn.atomic_max_seqcst "std::intrinsics::atomic_max_seqcst fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using a signed comparison.
[atomic\_min\_acqrel](fn.atomic_min_acqrel "std::intrinsics::atomic_min_acqrel fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using a signed comparison.
[atomic\_min\_acquire](fn.atomic_min_acquire "std::intrinsics::atomic_min_acquire fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using a signed comparison.
[atomic\_min\_relaxed](fn.atomic_min_relaxed "std::intrinsics::atomic_min_relaxed fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using a signed comparison.
[atomic\_min\_release](fn.atomic_min_release "std::intrinsics::atomic_min_release fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using a signed comparison.
[atomic\_min\_seqcst](fn.atomic_min_seqcst "std::intrinsics::atomic_min_seqcst fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using a signed comparison.
[atomic\_nand\_acqrel](fn.atomic_nand_acqrel "std::intrinsics::atomic_nand_acqrel fn")[⚠](# "unsafe function")Experimental
Bitwise nand with the current value, returning the previous value.
[atomic\_nand\_acquire](fn.atomic_nand_acquire "std::intrinsics::atomic_nand_acquire fn")[⚠](# "unsafe function")Experimental
Bitwise nand with the current value, returning the previous value.
[atomic\_nand\_relaxed](fn.atomic_nand_relaxed "std::intrinsics::atomic_nand_relaxed fn")[⚠](# "unsafe function")Experimental
Bitwise nand with the current value, returning the previous value.
[atomic\_nand\_release](fn.atomic_nand_release "std::intrinsics::atomic_nand_release fn")[⚠](# "unsafe function")Experimental
Bitwise nand with the current value, returning the previous value.
[atomic\_nand\_seqcst](fn.atomic_nand_seqcst "std::intrinsics::atomic_nand_seqcst fn")[⚠](# "unsafe function")Experimental
Bitwise nand with the current value, returning the previous value.
[atomic\_or\_acqrel](fn.atomic_or_acqrel "std::intrinsics::atomic_or_acqrel fn")[⚠](# "unsafe function")Experimental
Bitwise or with the current value, returning the previous value.
[atomic\_or\_acquire](fn.atomic_or_acquire "std::intrinsics::atomic_or_acquire fn")[⚠](# "unsafe function")Experimental
Bitwise or with the current value, returning the previous value.
[atomic\_or\_relaxed](fn.atomic_or_relaxed "std::intrinsics::atomic_or_relaxed fn")[⚠](# "unsafe function")Experimental
Bitwise or with the current value, returning the previous value.
[atomic\_or\_release](fn.atomic_or_release "std::intrinsics::atomic_or_release fn")[⚠](# "unsafe function")Experimental
Bitwise or with the current value, returning the previous value.
[atomic\_or\_seqcst](fn.atomic_or_seqcst "std::intrinsics::atomic_or_seqcst fn")[⚠](# "unsafe function")Experimental
Bitwise or with the current value, returning the previous value.
[atomic\_singlethreadfence\_acqrel](fn.atomic_singlethreadfence_acqrel "std::intrinsics::atomic_singlethreadfence_acqrel fn")[⚠](# "unsafe function")Experimental
A compiler-only memory barrier.
[atomic\_singlethreadfence\_acquire](fn.atomic_singlethreadfence_acquire "std::intrinsics::atomic_singlethreadfence_acquire fn")[⚠](# "unsafe function")Experimental
A compiler-only memory barrier.
[atomic\_singlethreadfence\_release](fn.atomic_singlethreadfence_release "std::intrinsics::atomic_singlethreadfence_release fn")[⚠](# "unsafe function")Experimental
A compiler-only memory barrier.
[atomic\_singlethreadfence\_seqcst](fn.atomic_singlethreadfence_seqcst "std::intrinsics::atomic_singlethreadfence_seqcst fn")[⚠](# "unsafe function")Experimental
A compiler-only memory barrier.
[atomic\_store\_relaxed](fn.atomic_store_relaxed "std::intrinsics::atomic_store_relaxed fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location.
[atomic\_store\_release](fn.atomic_store_release "std::intrinsics::atomic_store_release fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location.
[atomic\_store\_seqcst](fn.atomic_store_seqcst "std::intrinsics::atomic_store_seqcst fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location.
[atomic\_store\_unordered](fn.atomic_store_unordered "std::intrinsics::atomic_store_unordered fn")[⚠](# "unsafe function")Experimental
[atomic\_umax\_acqrel](fn.atomic_umax_acqrel "std::intrinsics::atomic_umax_acqrel fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using an unsigned comparison.
[atomic\_umax\_acquire](fn.atomic_umax_acquire "std::intrinsics::atomic_umax_acquire fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using an unsigned comparison.
[atomic\_umax\_relaxed](fn.atomic_umax_relaxed "std::intrinsics::atomic_umax_relaxed fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using an unsigned comparison.
[atomic\_umax\_release](fn.atomic_umax_release "std::intrinsics::atomic_umax_release fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using an unsigned comparison.
[atomic\_umax\_seqcst](fn.atomic_umax_seqcst "std::intrinsics::atomic_umax_seqcst fn")[⚠](# "unsafe function")Experimental
Maximum with the current value using an unsigned comparison.
[atomic\_umin\_acqrel](fn.atomic_umin_acqrel "std::intrinsics::atomic_umin_acqrel fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using an unsigned comparison.
[atomic\_umin\_acquire](fn.atomic_umin_acquire "std::intrinsics::atomic_umin_acquire fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using an unsigned comparison.
[atomic\_umin\_relaxed](fn.atomic_umin_relaxed "std::intrinsics::atomic_umin_relaxed fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using an unsigned comparison.
[atomic\_umin\_release](fn.atomic_umin_release "std::intrinsics::atomic_umin_release fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using an unsigned comparison.
[atomic\_umin\_seqcst](fn.atomic_umin_seqcst "std::intrinsics::atomic_umin_seqcst fn")[⚠](# "unsafe function")Experimental
Minimum with the current value using an unsigned comparison.
[atomic\_xadd\_acqrel](fn.atomic_xadd_acqrel "std::intrinsics::atomic_xadd_acqrel fn")[⚠](# "unsafe function")Experimental
Adds to the current value, returning the previous value.
[atomic\_xadd\_acquire](fn.atomic_xadd_acquire "std::intrinsics::atomic_xadd_acquire fn")[⚠](# "unsafe function")Experimental
Adds to the current value, returning the previous value.
[atomic\_xadd\_relaxed](fn.atomic_xadd_relaxed "std::intrinsics::atomic_xadd_relaxed fn")[⚠](# "unsafe function")Experimental
Adds to the current value, returning the previous value.
[atomic\_xadd\_release](fn.atomic_xadd_release "std::intrinsics::atomic_xadd_release fn")[⚠](# "unsafe function")Experimental
Adds to the current value, returning the previous value.
[atomic\_xadd\_seqcst](fn.atomic_xadd_seqcst "std::intrinsics::atomic_xadd_seqcst fn")[⚠](# "unsafe function")Experimental
Adds to the current value, returning the previous value.
[atomic\_xchg\_acqrel](fn.atomic_xchg_acqrel "std::intrinsics::atomic_xchg_acqrel fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location, returning the old value.
[atomic\_xchg\_acquire](fn.atomic_xchg_acquire "std::intrinsics::atomic_xchg_acquire fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location, returning the old value.
[atomic\_xchg\_relaxed](fn.atomic_xchg_relaxed "std::intrinsics::atomic_xchg_relaxed fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location, returning the old value.
[atomic\_xchg\_release](fn.atomic_xchg_release "std::intrinsics::atomic_xchg_release fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location, returning the old value.
[atomic\_xchg\_seqcst](fn.atomic_xchg_seqcst "std::intrinsics::atomic_xchg_seqcst fn")[⚠](# "unsafe function")Experimental
Stores the value at the specified memory location, returning the old value.
[atomic\_xor\_acqrel](fn.atomic_xor_acqrel "std::intrinsics::atomic_xor_acqrel fn")[⚠](# "unsafe function")Experimental
Bitwise xor with the current value, returning the previous value.
[atomic\_xor\_acquire](fn.atomic_xor_acquire "std::intrinsics::atomic_xor_acquire fn")[⚠](# "unsafe function")Experimental
Bitwise xor with the current value, returning the previous value.
[atomic\_xor\_relaxed](fn.atomic_xor_relaxed "std::intrinsics::atomic_xor_relaxed fn")[⚠](# "unsafe function")Experimental
Bitwise xor with the current value, returning the previous value.
[atomic\_xor\_release](fn.atomic_xor_release "std::intrinsics::atomic_xor_release fn")[⚠](# "unsafe function")Experimental
Bitwise xor with the current value, returning the previous value.
[atomic\_xor\_seqcst](fn.atomic_xor_seqcst "std::intrinsics::atomic_xor_seqcst fn")[⚠](# "unsafe function")Experimental
Bitwise xor with the current value, returning the previous value.
[atomic\_xsub\_acqrel](fn.atomic_xsub_acqrel "std::intrinsics::atomic_xsub_acqrel fn")[⚠](# "unsafe function")Experimental
Subtract from the current value, returning the previous value.
[atomic\_xsub\_acquire](fn.atomic_xsub_acquire "std::intrinsics::atomic_xsub_acquire fn")[⚠](# "unsafe function")Experimental
Subtract from the current value, returning the previous value.
[atomic\_xsub\_relaxed](fn.atomic_xsub_relaxed "std::intrinsics::atomic_xsub_relaxed fn")[⚠](# "unsafe function")Experimental
Subtract from the current value, returning the previous value.
[atomic\_xsub\_release](fn.atomic_xsub_release "std::intrinsics::atomic_xsub_release fn")[⚠](# "unsafe function")Experimental
Subtract from the current value, returning the previous value.
[atomic\_xsub\_seqcst](fn.atomic_xsub_seqcst "std::intrinsics::atomic_xsub_seqcst fn")[⚠](# "unsafe function")Experimental
Subtract from the current value, returning the previous value.
[bitreverse](fn.bitreverse "std::intrinsics::bitreverse fn")Experimental
Reverses the bits in an integer type `T`.
[black\_box](fn.black_box "std::intrinsics::black_box fn")Experimental
See documentation of [`std::hint::black_box`](../hint/fn.black_box) for details.
[breakpoint](fn.breakpoint "std::intrinsics::breakpoint fn")[⚠](# "unsafe function")Experimental
Executes a breakpoint trap, for inspection by a debugger.
[bswap](fn.bswap "std::intrinsics::bswap fn")Experimental
Reverses the bytes in an integer type `T`.
[caller\_location](fn.caller_location "std::intrinsics::caller_location fn")Experimental
Gets a reference to a static `Location` indicating where it was called.
[ceilf32](fn.ceilf32 "std::intrinsics::ceilf32 fn")[⚠](# "unsafe function")Experimental
Returns the smallest integer greater than or equal to an `f32`.
[ceilf64](fn.ceilf64 "std::intrinsics::ceilf64 fn")[⚠](# "unsafe function")Experimental
Returns the smallest integer greater than or equal to an `f64`.
[const\_allocate](fn.const_allocate "std::intrinsics::const_allocate fn")[⚠](# "unsafe function")Experimental
Allocates a block of memory at compile time. At runtime, just returns a null pointer.
[const\_deallocate](fn.const_deallocate "std::intrinsics::const_deallocate fn")[⚠](# "unsafe function")Experimental
Deallocates a memory which allocated by `intrinsics::const_allocate` at compile time. At runtime, does nothing.
[const\_eval\_select](fn.const_eval_select "std::intrinsics::const_eval_select fn")[⚠](# "unsafe function")Experimental
Selects which function to call depending on the context.
[copysignf32](fn.copysignf32 "std::intrinsics::copysignf32 fn")[⚠](# "unsafe function")Experimental
Copies the sign from `y` to `x` for `f32` values.
[copysignf64](fn.copysignf64 "std::intrinsics::copysignf64 fn")[⚠](# "unsafe function")Experimental
Copies the sign from `y` to `x` for `f64` values.
[cosf32](fn.cosf32 "std::intrinsics::cosf32 fn")[⚠](# "unsafe function")Experimental
Returns the cosine of an `f32`.
[cosf64](fn.cosf64 "std::intrinsics::cosf64 fn")[⚠](# "unsafe function")Experimental
Returns the cosine of an `f64`.
[ctlz](fn.ctlz "std::intrinsics::ctlz fn")Experimental
Returns the number of leading unset bits (zeroes) in an integer type `T`.
[ctlz\_nonzero](fn.ctlz_nonzero "std::intrinsics::ctlz_nonzero fn")[⚠](# "unsafe function")Experimental
Like `ctlz`, but extra-unsafe as it returns `undef` when given an `x` with value `0`.
[ctpop](fn.ctpop "std::intrinsics::ctpop fn")Experimental
Returns the number of bits set in an integer type `T`
[cttz](fn.cttz "std::intrinsics::cttz fn")Experimental
Returns the number of trailing unset bits (zeroes) in an integer type `T`.
[cttz\_nonzero](fn.cttz_nonzero "std::intrinsics::cttz_nonzero fn")[⚠](# "unsafe function")Experimental
Like `cttz`, but extra-unsafe as it returns `undef` when given an `x` with value `0`.
[discriminant\_value](fn.discriminant_value "std::intrinsics::discriminant_value fn")Experimental
Returns the value of the discriminant for the variant in ‘v’; if `T` has no discriminant, returns `0`.
[exact\_div](fn.exact_div "std::intrinsics::exact_div fn")[⚠](# "unsafe function")Experimental
Performs an exact division, resulting in undefined behavior where `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
[exp2f32](fn.exp2f32 "std::intrinsics::exp2f32 fn")[⚠](# "unsafe function")Experimental
Returns 2 raised to the power of an `f32`.
[exp2f64](fn.exp2f64 "std::intrinsics::exp2f64 fn")[⚠](# "unsafe function")Experimental
Returns 2 raised to the power of an `f64`.
[expf32](fn.expf32 "std::intrinsics::expf32 fn")[⚠](# "unsafe function")Experimental
Returns the exponential of an `f32`.
[expf64](fn.expf64 "std::intrinsics::expf64 fn")[⚠](# "unsafe function")Experimental
Returns the exponential of an `f64`.
[fabsf32](fn.fabsf32 "std::intrinsics::fabsf32 fn")[⚠](# "unsafe function")Experimental
Returns the absolute value of an `f32`.
[fabsf64](fn.fabsf64 "std::intrinsics::fabsf64 fn")[⚠](# "unsafe function")Experimental
Returns the absolute value of an `f64`.
[fadd\_fast](fn.fadd_fast "std::intrinsics::fadd_fast fn")[⚠](# "unsafe function")Experimental
Float addition that allows optimizations based on algebraic rules. May assume inputs are finite.
[fdiv\_fast](fn.fdiv_fast "std::intrinsics::fdiv_fast fn")[⚠](# "unsafe function")Experimental
Float division that allows optimizations based on algebraic rules. May assume inputs are finite.
[float\_to\_int\_unchecked](fn.float_to_int_unchecked "std::intrinsics::float_to_int_unchecked fn")[⚠](# "unsafe function")Experimental
Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range (<https://github.com/rust-lang/rust/issues/10184>)
[floorf32](fn.floorf32 "std::intrinsics::floorf32 fn")[⚠](# "unsafe function")Experimental
Returns the largest integer less than or equal to an `f32`.
[floorf64](fn.floorf64 "std::intrinsics::floorf64 fn")[⚠](# "unsafe function")Experimental
Returns the largest integer less than or equal to an `f64`.
[fmaf32](fn.fmaf32 "std::intrinsics::fmaf32 fn")[⚠](# "unsafe function")Experimental
Returns `a * b + c` for `f32` values.
[fmaf64](fn.fmaf64 "std::intrinsics::fmaf64 fn")[⚠](# "unsafe function")Experimental
Returns `a * b + c` for `f64` values.
[fmul\_fast](fn.fmul_fast "std::intrinsics::fmul_fast fn")[⚠](# "unsafe function")Experimental
Float multiplication that allows optimizations based on algebraic rules. May assume inputs are finite.
[forget](fn.forget "std::intrinsics::forget fn")Experimental
Moves a value out of scope without running drop glue.
[frem\_fast](fn.frem_fast "std::intrinsics::frem_fast fn")[⚠](# "unsafe function")Experimental
Float remainder that allows optimizations based on algebraic rules. May assume inputs are finite.
[fsub\_fast](fn.fsub_fast "std::intrinsics::fsub_fast fn")[⚠](# "unsafe function")Experimental
Float subtraction that allows optimizations based on algebraic rules. May assume inputs are finite.
[likely](fn.likely "std::intrinsics::likely fn")Experimental
Hints to the compiler that branch condition is likely to be true. Returns the value passed to it.
[log2f32](fn.log2f32 "std::intrinsics::log2f32 fn")[⚠](# "unsafe function")Experimental
Returns the base 2 logarithm of an `f32`.
[log2f64](fn.log2f64 "std::intrinsics::log2f64 fn")[⚠](# "unsafe function")Experimental
Returns the base 2 logarithm of an `f64`.
[log10f32](fn.log10f32 "std::intrinsics::log10f32 fn")[⚠](# "unsafe function")Experimental
Returns the base 10 logarithm of an `f32`.
[log10f64](fn.log10f64 "std::intrinsics::log10f64 fn")[⚠](# "unsafe function")Experimental
Returns the base 10 logarithm of an `f64`.
[logf32](fn.logf32 "std::intrinsics::logf32 fn")[⚠](# "unsafe function")Experimental
Returns the natural logarithm of an `f32`.
[logf64](fn.logf64 "std::intrinsics::logf64 fn")[⚠](# "unsafe function")Experimental
Returns the natural logarithm of an `f64`.
[maxnumf32](fn.maxnumf32 "std::intrinsics::maxnumf32 fn")Experimental
Returns the maximum of two `f32` values.
[maxnumf64](fn.maxnumf64 "std::intrinsics::maxnumf64 fn")Experimental
Returns the maximum of two `f64` values.
[min\_align\_of](fn.min_align_of "std::intrinsics::min_align_of fn")Experimental
The minimum alignment of a type.
[min\_align\_of\_val](fn.min_align_of_val "std::intrinsics::min_align_of_val fn")[⚠](# "unsafe function")Experimental
The required alignment of the referenced value.
[minnumf32](fn.minnumf32 "std::intrinsics::minnumf32 fn")Experimental
Returns the minimum of two `f32` values.
[minnumf64](fn.minnumf64 "std::intrinsics::minnumf64 fn")Experimental
Returns the minimum of two `f64` values.
[mul\_with\_overflow](fn.mul_with_overflow "std::intrinsics::mul_with_overflow fn")Experimental
Performs checked integer multiplication
[nearbyintf32](fn.nearbyintf32 "std::intrinsics::nearbyintf32 fn")[⚠](# "unsafe function")Experimental
Returns the nearest integer to an `f32`.
[nearbyintf64](fn.nearbyintf64 "std::intrinsics::nearbyintf64 fn")[⚠](# "unsafe function")Experimental
Returns the nearest integer to an `f64`.
[needs\_drop](fn.needs_drop "std::intrinsics::needs_drop fn")Experimental
Returns `true` if the actual type given as `T` requires drop glue; returns `false` if the actual type provided for `T` implements `Copy`.
[nontemporal\_store](fn.nontemporal_store "std::intrinsics::nontemporal_store fn")[⚠](# "unsafe function")Experimental
Emits a `!nontemporal` store according to LLVM (see their docs). Probably will never become stable.
[offset](fn.offset "std::intrinsics::offset fn")[⚠](# "unsafe function")Experimental
Calculates the offset from a pointer.
[powf32](fn.powf32 "std::intrinsics::powf32 fn")[⚠](# "unsafe function")Experimental
Raises an `f32` to an `f32` power.
[powf64](fn.powf64 "std::intrinsics::powf64 fn")[⚠](# "unsafe function")Experimental
Raises an `f64` to an `f64` power.
[powif32](fn.powif32 "std::intrinsics::powif32 fn")[⚠](# "unsafe function")Experimental
Raises an `f32` to an integer power.
[powif64](fn.powif64 "std::intrinsics::powif64 fn")[⚠](# "unsafe function")Experimental
Raises an `f64` to an integer power.
[pref\_align\_of](fn.pref_align_of "std::intrinsics::pref_align_of fn")[⚠](# "unsafe function")Experimental
The preferred alignment of a type.
[prefetch\_read\_data](fn.prefetch_read_data "std::intrinsics::prefetch_read_data fn")[⚠](# "unsafe function")Experimental
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
[prefetch\_read\_instruction](fn.prefetch_read_instruction "std::intrinsics::prefetch_read_instruction fn")[⚠](# "unsafe function")Experimental
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
[prefetch\_write\_data](fn.prefetch_write_data "std::intrinsics::prefetch_write_data fn")[⚠](# "unsafe function")Experimental
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
[prefetch\_write\_instruction](fn.prefetch_write_instruction "std::intrinsics::prefetch_write_instruction fn")[⚠](# "unsafe function")Experimental
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
[ptr\_guaranteed\_cmp](fn.ptr_guaranteed_cmp "std::intrinsics::ptr_guaranteed_cmp fn")Experimental
See documentation of `<*const T>::guaranteed_eq` for details. Returns `2` if the result is unknown. Returns `1` if the pointers are guaranteed equal Returns `0` if the pointers are guaranteed inequal
[ptr\_mask](fn.ptr_mask "std::intrinsics::ptr_mask fn")Experimental
Masks out bits of the pointer according to a mask.
[ptr\_offset\_from](fn.ptr_offset_from "std::intrinsics::ptr_offset_from fn")[⚠](# "unsafe function")Experimental
See documentation of `<*const T>::offset_from` for details.
[ptr\_offset\_from\_unsigned](fn.ptr_offset_from_unsigned "std::intrinsics::ptr_offset_from_unsigned fn")[⚠](# "unsafe function")Experimental
See documentation of `<*const T>::sub_ptr` for details.
[raw\_eq](fn.raw_eq "std::intrinsics::raw_eq fn")[⚠](# "unsafe function")Experimental
Determines whether the raw bytes of the two values are equal.
[rintf32](fn.rintf32 "std::intrinsics::rintf32 fn")[⚠](# "unsafe function")Experimental
Returns the nearest integer to an `f32`. May raise an inexact floating-point exception if the argument is not an integer.
[rintf64](fn.rintf64 "std::intrinsics::rintf64 fn")[⚠](# "unsafe function")Experimental
Returns the nearest integer to an `f64`. May raise an inexact floating-point exception if the argument is not an integer.
[rotate\_left](fn.rotate_left "std::intrinsics::rotate_left fn")Experimental
Performs rotate left.
[rotate\_right](fn.rotate_right "std::intrinsics::rotate_right fn")Experimental
Performs rotate right.
[roundf32](fn.roundf32 "std::intrinsics::roundf32 fn")[⚠](# "unsafe function")Experimental
Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
[roundf64](fn.roundf64 "std::intrinsics::roundf64 fn")[⚠](# "unsafe function")Experimental
Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
[rustc\_peek](fn.rustc_peek "std::intrinsics::rustc_peek fn")Experimental
Magic intrinsic that derives its meaning from attributes attached to the function.
[saturating\_add](fn.saturating_add "std::intrinsics::saturating_add fn")Experimental
Computes `a + b`, saturating at numeric bounds.
[saturating\_sub](fn.saturating_sub "std::intrinsics::saturating_sub fn")Experimental
Computes `a - b`, saturating at numeric bounds.
[sinf32](fn.sinf32 "std::intrinsics::sinf32 fn")[⚠](# "unsafe function")Experimental
Returns the sine of an `f32`.
[sinf64](fn.sinf64 "std::intrinsics::sinf64 fn")[⚠](# "unsafe function")Experimental
Returns the sine of an `f64`.
[size\_of](fn.size_of "std::intrinsics::size_of fn")Experimental
The size of a type in bytes.
[size\_of\_val](fn.size_of_val "std::intrinsics::size_of_val fn")[⚠](# "unsafe function")Experimental
The size of the referenced value in bytes.
[sqrtf32](fn.sqrtf32 "std::intrinsics::sqrtf32 fn")[⚠](# "unsafe function")Experimental
Returns the square root of an `f32`
[sqrtf64](fn.sqrtf64 "std::intrinsics::sqrtf64 fn")[⚠](# "unsafe function")Experimental
Returns the square root of an `f64`
[sub\_with\_overflow](fn.sub_with_overflow "std::intrinsics::sub_with_overflow fn")Experimental
Performs checked integer subtraction
[truncf32](fn.truncf32 "std::intrinsics::truncf32 fn")[⚠](# "unsafe function")Experimental
Returns the integer part of an `f32`.
[truncf64](fn.truncf64 "std::intrinsics::truncf64 fn")[⚠](# "unsafe function")Experimental
Returns the integer part of an `f64`.
[try](fn.try "std::intrinsics::try fn")[⚠](# "unsafe function")Experimental
Rust’s “try catch” construct which invokes the function pointer `try_fn` with the data pointer `data`.
[type\_id](fn.type_id "std::intrinsics::type_id fn")Experimental
Gets an identifier which is globally unique to the specified type. This function will return the same value for a type regardless of whichever crate it is invoked in.
[type\_name](fn.type_name "std::intrinsics::type_name fn")Experimental
Gets a static string slice containing the name of a type.
[unaligned\_volatile\_load](fn.unaligned_volatile_load "std::intrinsics::unaligned_volatile_load fn")[⚠](# "unsafe function")Experimental
Performs a volatile load from the `src` pointer The pointer is not required to be aligned.
[unaligned\_volatile\_store](fn.unaligned_volatile_store "std::intrinsics::unaligned_volatile_store fn")[⚠](# "unsafe function")Experimental
Performs a volatile store to the `dst` pointer. The pointer is not required to be aligned.
[unchecked\_add](fn.unchecked_add "std::intrinsics::unchecked_add fn")[⚠](# "unsafe function")Experimental
Returns the result of an unchecked addition, resulting in undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
[unchecked\_div](fn.unchecked_div "std::intrinsics::unchecked_div fn")[⚠](# "unsafe function")Experimental
Performs an unchecked division, resulting in undefined behavior where `y == 0` or `x == T::MIN && y == -1`
[unchecked\_mul](fn.unchecked_mul "std::intrinsics::unchecked_mul fn")[⚠](# "unsafe function")Experimental
Returns the result of an unchecked multiplication, resulting in undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
[unchecked\_rem](fn.unchecked_rem "std::intrinsics::unchecked_rem fn")[⚠](# "unsafe function")Experimental
Returns the remainder of an unchecked division, resulting in undefined behavior when `y == 0` or `x == T::MIN && y == -1`
[unchecked\_shl](fn.unchecked_shl "std::intrinsics::unchecked_shl fn")[⚠](# "unsafe function")Experimental
Performs an unchecked left shift, resulting in undefined behavior when `y < 0` or `y >= N`, where N is the width of T in bits.
[unchecked\_shr](fn.unchecked_shr "std::intrinsics::unchecked_shr fn")[⚠](# "unsafe function")Experimental
Performs an unchecked right shift, resulting in undefined behavior when `y < 0` or `y >= N`, where N is the width of T in bits.
[unchecked\_sub](fn.unchecked_sub "std::intrinsics::unchecked_sub fn")[⚠](# "unsafe function")Experimental
Returns the result of an unchecked subtraction, resulting in undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
[unlikely](fn.unlikely "std::intrinsics::unlikely fn")Experimental
Hints to the compiler that branch condition is likely to be false. Returns the value passed to it.
[unreachable](fn.unreachable "std::intrinsics::unreachable fn")[⚠](# "unsafe function")Experimental
Informs the optimizer that this point in the code is not reachable, enabling further optimizations.
[variant\_count](fn.variant_count "std::intrinsics::variant_count fn")Experimental
Returns the number of variants of the type `T` cast to a `usize`; if `T` has no variants, returns `0`. Uninhabited variants will be counted.
[volatile\_copy\_memory](fn.volatile_copy_memory "std::intrinsics::volatile_copy_memory fn")[⚠](# "unsafe function")Experimental
Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with a size of `count * size_of::<T>()` and an alignment of `min_align_of::<T>()`
[volatile\_copy\_nonoverlapping\_memory](fn.volatile_copy_nonoverlapping_memory "std::intrinsics::volatile_copy_nonoverlapping_memory fn")[⚠](# "unsafe function")Experimental
Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with a size of `count` \* `size_of::<T>()` and an alignment of `min_align_of::<T>()`
[volatile\_load](fn.volatile_load "std::intrinsics::volatile_load fn")[⚠](# "unsafe function")Experimental
Performs a volatile load from the `src` pointer.
[volatile\_set\_memory](fn.volatile_set_memory "std::intrinsics::volatile_set_memory fn")[⚠](# "unsafe function")Experimental
Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a size of `count * size_of::<T>()` and an alignment of `min_align_of::<T>()`.
[volatile\_store](fn.volatile_store "std::intrinsics::volatile_store fn")[⚠](# "unsafe function")Experimental
Performs a volatile store to the `dst` pointer.
[vtable\_align](fn.vtable_align "std::intrinsics::vtable_align fn")[⚠](# "unsafe function")Experimental
`ptr` must point to a vtable. The intrinsic will return the alignment stored in that vtable.
[vtable\_size](fn.vtable_size "std::intrinsics::vtable_size fn")[⚠](# "unsafe function")Experimental
`ptr` must point to a vtable. The intrinsic will return the size stored in that vtable.
[wrapping\_add](fn.wrapping_add "std::intrinsics::wrapping_add fn")Experimental
Returns (a + b) mod 2N, where N is the width of T in bits.
[wrapping\_mul](fn.wrapping_mul "std::intrinsics::wrapping_mul fn")Experimental
Returns (a \* b) mod 2N, where N is the width of T in bits.
[wrapping\_sub](fn.wrapping_sub "std::intrinsics::wrapping_sub fn")Experimental
Returns (a - b) mod 2N, where N is the width of T in bits.
[copy](fn.copy "std::intrinsics::copy fn")[⚠](# "unsafe function")
Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source and destination may overlap.
[copy\_nonoverlapping](fn.copy_nonoverlapping "std::intrinsics::copy_nonoverlapping fn")[⚠](# "unsafe function")
Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source and destination must *not* overlap.
[drop\_in\_place](fn.drop_in_place "std::intrinsics::drop_in_place fn")[⚠](# "unsafe function")Deprecated
[transmute](fn.transmute "std::intrinsics::transmute fn")[⚠](# "unsafe function")
Reinterprets the bits of a value of one type as another type.
[write\_bytes](fn.write_bytes "std::intrinsics::write_bytes fn")[⚠](# "unsafe function")
Sets `count * size_of::<T>()` bytes of memory starting at `dst` to `val`.
| programming_docs |
rust Function std::intrinsics::cttz_nonzero Function std::intrinsics::cttz\_nonzero
=======================================
```
pub const unsafe extern "rust-intrinsic" fn cttz_nonzero<T>(x: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Like `cttz`, but extra-unsafe as it returns `undef` when given an `x` with value `0`.
This intrinsic does not have a stable counterpart.
Examples
--------
```
#![feature(core_intrinsics)]
use std::intrinsics::cttz_nonzero;
let x = 0b0011_1000_u8;
let num_trailing = unsafe { cttz_nonzero(x) };
assert_eq!(num_trailing, 3);
```
rust Function std::intrinsics::minnumf32 Function std::intrinsics::minnumf32
===================================
```
pub extern "rust-intrinsic" fn minnumf32(x: f32, y: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the minimum of two `f32` values.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`f32::min`](../primitive.f32#method.min "f32::min")
rust Function std::intrinsics::atomic_cxchg_acquire_acquire Function std::intrinsics::atomic\_cxchg\_acquire\_acquire
=========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_acquire_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as both the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::expf64 Function std::intrinsics::expf64
================================
```
pub unsafe extern "rust-intrinsic" fn expf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the exponential of an `f64`.
The stabilized version of this intrinsic is [`f64::exp`](../primitive.f64#method.exp)
rust Function std::intrinsics::atomic_xor_acqrel Function std::intrinsics::atomic\_xor\_acqrel
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xor_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise xor with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_xor` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicBool::fetch_xor`](../sync/atomic/struct.atomicbool#method.fetch_xor "AtomicBool::fetch_xor").
rust Function std::intrinsics::black_box Function std::intrinsics::black\_box
====================================
```
pub extern "rust-intrinsic" fn black_box<T>(dummy: T) -> T
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
See documentation of [`std::hint::black_box`](../hint/fn.black_box) for details.
rust Function std::intrinsics::prefetch_read_instruction Function std::intrinsics::prefetch\_read\_instruction
=====================================================
```
pub unsafe extern "rust-intrinsic" fn prefetch_read_instruction<T>( data: *const T, locality: i32)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
The `locality` argument must be a constant integer and is a temporal locality specifier ranging from (0) - no locality, to (3) - extremely local keep in cache.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_fence_acqrel Function std::intrinsics::atomic\_fence\_acqrel
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_fence_acqrel()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
An atomic fence.
The stabilized version of this intrinsic is available in [`atomic::fence`](../sync/atomic/fn.fence "atomic::fence") by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`.
rust Function std::intrinsics::atomic_cxchgweak_acqrel_acquire Function std::intrinsics::atomic\_cxchgweak\_acqrel\_acquire
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_acqrel_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::unchecked_shr Function std::intrinsics::unchecked\_shr
========================================
```
pub const unsafe extern "rust-intrinsic" fn unchecked_shr<T>( x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs an unchecked right shift, resulting in undefined behavior when `y < 0` or `y >= N`, where N is the width of T in bits.
Safe wrappers for this intrinsic are available on the integer primitives via the `checked_shr` method. For example, [`u32::checked_shr`](../primitive.u32#method.checked_shr "u32::checked_shr")
rust Function std::intrinsics::unchecked_mul Function std::intrinsics::unchecked\_mul
========================================
```
pub unsafe extern "rust-intrinsic" fn unchecked_mul<T>(x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the result of an unchecked multiplication, resulting in undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::powf64 Function std::intrinsics::powf64
================================
```
pub unsafe extern "rust-intrinsic" fn powf64(a: f64, x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Raises an `f64` to an `f64` power.
The stabilized version of this intrinsic is [`f64::powf`](../primitive.f64#method.powf)
rust Function std::intrinsics::assert_inhabited Function std::intrinsics::assert\_inhabited
===========================================
```
pub const extern "rust-intrinsic" fn assert_inhabited<T>()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: This will statically either panic, or do nothing.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::unaligned_volatile_store Function std::intrinsics::unaligned\_volatile\_store
====================================================
```
pub unsafe extern "rust-intrinsic" fn unaligned_volatile_store<T>( dst: *mut T, val: T)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs a volatile store to the `dst` pointer. The pointer is not required to be aligned.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::transmute Function std::intrinsics::transmute
===================================
```
pub const unsafe extern "rust-intrinsic" fn transmute<T, U>(e: T) -> U
```
Reinterprets the bits of a value of one type as another type.
Both types must have the same size. Compilation will fail if this is not guaranteed.
`transmute` is semantically equivalent to a bitwise move of one type into another. It copies the bits from the source value into the destination value, then forgets the original. Note that source and destination are passed by-value, which means if `T` or `U` contain padding, that padding is *not* guaranteed to be preserved by `transmute`.
Both the argument and the result must be [valid](https://doc.rust-lang.org/nomicon/what-unsafe-does.html) at their given type. Violating this condition leads to [undefined behavior](../../reference/behavior-considered-undefined). The compiler will generate code *assuming that you, the programmer, ensure that there will never be undefined behavior*. It is therefore your responsibility to guarantee that every value passed to `transmute` is valid at both types `T` and `U`. Failing to uphold this condition may lead to unexpected and unstable compilation results. This makes `transmute` **incredibly unsafe**. `transmute` should be the absolute last resort.
Transmuting pointers to integers in a `const` context is [undefined behavior](../../reference/behavior-considered-undefined). Any attempt to use the resulting value for integer operations will abort const-evaluation. (And even outside `const`, such transmutation is touching on many unspecified aspects of the Rust memory model and should be avoided. See below for alternatives.)
Because `transmute` is a by-value operation, alignment of the *transmuted values themselves* is not a concern. As with any other function, the compiler already ensures both `T` and `U` are properly aligned. However, when transmuting values that *point elsewhere* (such as pointers, references, boxes…), the caller has to ensure proper alignment of the pointed-to values.
The [nomicon](https://doc.rust-lang.org/nomicon/transmutes.html) has additional documentation.
Examples
--------
There are a few things that `transmute` is really useful for.
Turning a pointer into a function pointer. This is *not* portable to machines where function pointers and data pointers have different sizes.
```
fn foo() -> i32 {
0
}
// Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
// This avoids an integer-to-pointer `transmute`, which can be problematic.
// Transmuting between raw pointers and function pointers (i.e., two pointer types) is fine.
let pointer = foo as *const ();
let function = unsafe {
std::mem::transmute::<*const (), fn() -> i32>(pointer)
};
assert_eq!(function(), 0);
```
Extending a lifetime, or shortening an invariant lifetime. This is advanced, very unsafe Rust!
```
struct R<'a>(&'a i32);
unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
std::mem::transmute::<R<'b>, R<'static>>(r)
}
unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
-> &'b mut R<'c> {
std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
}
```
Alternatives
------------
Don’t despair: many uses of `transmute` can be achieved through other means. Below are common applications of `transmute` which can be replaced with safer constructs.
Turning raw bytes (`&[u8]`) into `u32`, `f64`, etc.:
```
let raw_bytes = [0x78, 0x56, 0x34, 0x12];
let num = unsafe {
std::mem::transmute::<[u8; 4], u32>(raw_bytes)
};
// use `u32::from_ne_bytes` instead
let num = u32::from_ne_bytes(raw_bytes);
// or use `u32::from_le_bytes` or `u32::from_be_bytes` to specify the endianness
let num = u32::from_le_bytes(raw_bytes);
assert_eq!(num, 0x12345678);
let num = u32::from_be_bytes(raw_bytes);
assert_eq!(num, 0x78563412);
```
Turning a pointer into a `usize`:
```
let ptr = &0;
let ptr_num_transmute = unsafe {
std::mem::transmute::<&i32, usize>(ptr)
};
// Use an `as` cast instead
let ptr_num_cast = ptr as *const i32 as usize;
```
Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined behavior](../../reference/behavior-considered-undefined) in `const` contexts. Also outside of consts, this operation might not behave as expected – this is touching on many unspecified aspects of the Rust memory model. Depending on what the code is doing, the following alternatives are preferable to pointer-to-integer transmutation:
* If the code just wants to store data of arbitrary type in some buffer and needs to pick a type for that buffer, it can use [`MaybeUninit`](../mem/union.maybeuninit "mem::MaybeUninit").
* If the code actually wants to work on the address the pointer points to, it can use `as` casts or [`ptr.addr()`](../primitive.pointer#method.addr "pointer::addr").
Turning a `*mut T` into an `&mut T`:
```
let ptr: *mut i32 = &mut 0;
let ref_transmuted = unsafe {
std::mem::transmute::<*mut i32, &mut i32>(ptr)
};
// Use a reborrow instead
let ref_casted = unsafe { &mut *ptr };
```
Turning an `&mut T` into an `&mut U`:
```
let ptr = &mut 0;
let val_transmuted = unsafe {
std::mem::transmute::<&mut i32, &mut u32>(ptr)
};
// Now, put together `as` and reborrowing - note the chaining of `as`
// `as` is not transitive
let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
```
Turning an `&str` into a `&[u8]`:
```
// this is not a good way to do this.
let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
assert_eq!(slice, &[82, 117, 115, 116]);
// You could use `str::as_bytes`
let slice = "Rust".as_bytes();
assert_eq!(slice, &[82, 117, 115, 116]);
// Or, just use a byte string, if you have control over the string
// literal
assert_eq!(b"Rust", &[82, 117, 115, 116]);
```
Turning a `Vec<&T>` into a `Vec<Option<&T>>`.
To transmute the inner type of the contents of a container, you must make sure to not violate any of the container’s invariants. For `Vec`, this means that both the size *and alignment* of the inner types have to match. Other containers might rely on the size of the type, alignment, or even the `TypeId`, in which case transmuting wouldn’t be possible at all without violating the container invariants.
```
let store = [0, 1, 2, 3];
let v_orig = store.iter().collect::<Vec<&i32>>();
// clone the vector as we will reuse them later
let v_clone = v_orig.clone();
// Using transmute: this relies on the unspecified data layout of `Vec`, which is a
// bad idea and could cause Undefined Behavior.
// However, it is no-copy.
let v_transmuted = unsafe {
std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
};
let v_clone = v_orig.clone();
// This is the suggested, safe way.
// It does copy the entire vector, though, into a new array.
let v_collected = v_clone.into_iter()
.map(Some)
.collect::<Vec<Option<&i32>>>();
let v_clone = v_orig.clone();
// This is the proper no-copy, unsafe way of "transmuting" a `Vec`, without relying on the
// data layout. Instead of literally calling `transmute`, we perform a pointer cast, but
// in terms of converting the original inner type (`&i32`) to the new one (`Option<&i32>`),
// this has all the same caveats. Besides the information provided above, also consult the
// [`from_raw_parts`] documentation.
let v_from_raw = unsafe {
// Ensure the original vector is not dropped.
let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
v_clone.len(),
v_clone.capacity())
};
```
Implementing `split_at_mut`:
```
use std::{slice, mem};
// There are multiple ways to do this, and there are multiple problems
// with the following (transmute) way.
fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
-> (&mut [T], &mut [T]) {
let len = slice.len();
assert!(mid <= len);
unsafe {
let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
// first: transmute is not type safe; all it checks is that T and
// U are of the same size. Second, right here, you have two
// mutable references pointing to the same memory.
(&mut slice[0..mid], &mut slice2[mid..len])
}
}
// This gets rid of the type safety problems; `&mut *` will *only* give
// you an `&mut T` from an `&mut T` or `*mut T`.
fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
-> (&mut [T], &mut [T]) {
let len = slice.len();
assert!(mid <= len);
unsafe {
let slice2 = &mut *(slice as *mut [T]);
// however, you still have two mutable references pointing to
// the same memory.
(&mut slice[0..mid], &mut slice2[mid..len])
}
}
// This is how the standard library does it. This is the best method, if
// you need to do something like this
fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
-> (&mut [T], &mut [T]) {
let len = slice.len();
assert!(mid <= len);
unsafe {
let ptr = slice.as_mut_ptr();
// This now has three mutable references pointing at the same
// memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
// `slice` is never used after `let ptr = ...`, and so one can
// treat it as "dead", and therefore, you only have two real
// mutable slices.
(slice::from_raw_parts_mut(ptr, mid),
slice::from_raw_parts_mut(ptr.add(mid), len - mid))
}
}
```
rust Function std::intrinsics::atomic_xadd_acqrel Function std::intrinsics::atomic\_xadd\_acqrel
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xadd_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Adds to the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_add` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicIsize::fetch_add`](../sync/atomic/struct.atomicisize#method.fetch_add "AtomicIsize::fetch_add").
rust Function std::intrinsics::nearbyintf32 Function std::intrinsics::nearbyintf32
======================================
```
pub unsafe extern "rust-intrinsic" fn nearbyintf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the nearest integer to an `f32`.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::fmaf32 Function std::intrinsics::fmaf32
================================
```
pub unsafe extern "rust-intrinsic" fn fmaf32( a: f32, b: f32, c: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns `a * b + c` for `f32` values.
The stabilized version of this intrinsic is [`f32::mul_add`](../primitive.f32#method.mul_add)
rust Function std::intrinsics::atomic_xsub_release Function std::intrinsics::atomic\_xsub\_release
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xsub_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Subtract from the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_sub` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicIsize::fetch_sub`](../sync/atomic/struct.atomicisize#method.fetch_sub "AtomicIsize::fetch_sub").
| programming_docs |
rust Function std::intrinsics::bswap Function std::intrinsics::bswap
===============================
```
pub const extern "rust-intrinsic" fn bswap<T>(x: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Reverses the bytes in an integer type `T`.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `swap_bytes` method. For example, [`u32::swap_bytes`](../primitive.u32#method.swap_bytes "u32::swap_bytes")
rust Function std::intrinsics::volatile_store Function std::intrinsics::volatile\_store
=========================================
```
pub unsafe extern "rust-intrinsic" fn volatile_store<T>( dst: *mut T, val: T)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs a volatile store to the `dst` pointer.
The stabilized version of this intrinsic is [`core::ptr::write_volatile`](../ptr/fn.write_volatile "core::ptr::write_volatile").
rust Function std::intrinsics::needs_drop Function std::intrinsics::needs\_drop
=====================================
```
pub const extern "rust-intrinsic" fn needs_drop<T>() -> boolwhere T: ?Sized,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns `true` if the actual type given as `T` requires drop glue; returns `false` if the actual type provided for `T` implements `Copy`.
If the actual type neither requires drop glue nor implements `Copy`, then the return value of this function is unspecified.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`mem::needs_drop`](../mem/fn.needs_drop).
rust Function std::intrinsics::drop_in_place Function std::intrinsics::drop\_in\_place
=========================================
```
pub unsafe fn drop_in_place<T>(to_drop: *mut T)where T: ?Sized,
```
👎Deprecated since 1.52.0: no longer an intrinsic - use `ptr::drop_in_place` directly
rust Function std::intrinsics::atomic_singlethreadfence_acquire Function std::intrinsics::atomic\_singlethreadfence\_acquire
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_singlethreadfence_acquire()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
A compiler-only memory barrier.
Memory accesses will never be reordered across this barrier by the compiler, but no instructions will be emitted for it. This is appropriate for operations on the same thread that may be preempted, such as when interacting with signal handlers.
The stabilized version of this intrinsic is available in [`atomic::compiler_fence`](../sync/atomic/fn.compiler_fence "atomic::compiler_fence") by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`.
rust Function std::intrinsics::prefetch_write_instruction Function std::intrinsics::prefetch\_write\_instruction
======================================================
```
pub unsafe extern "rust-intrinsic" fn prefetch_write_instruction<T>( data: *const T, locality: i32)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
The `locality` argument must be a constant integer and is a temporal locality specifier ranging from (0) - no locality, to (3) - extremely local keep in cache.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::volatile_copy_memory Function std::intrinsics::volatile\_copy\_memory
================================================
```
pub unsafe extern "rust-intrinsic" fn volatile_copy_memory<T>( dst: *mut T, src: *const T, count: usize)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with a size of `count * size_of::<T>()` and an alignment of `min_align_of::<T>()`
The volatile parameter is set to `true`, so it will not be optimized out unless size is equal to zero.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::powif64 Function std::intrinsics::powif64
=================================
```
pub unsafe extern "rust-intrinsic" fn powif64(a: f64, x: i32) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Raises an `f64` to an integer power.
The stabilized version of this intrinsic is [`f64::powi`](../primitive.f64#method.powi)
rust Function std::intrinsics::assert_zero_valid Function std::intrinsics::assert\_zero\_valid
=============================================
```
pub extern "rust-intrinsic" fn assert_zero_valid<T>()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
A guard for unsafe functions that cannot ever be executed if `T` does not permit zero-initialization: This will statically either panic, or do nothing.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_xsub_acquire Function std::intrinsics::atomic\_xsub\_acquire
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xsub_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Subtract from the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_sub` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicIsize::fetch_sub`](../sync/atomic/struct.atomicisize#method.fetch_sub "AtomicIsize::fetch_sub").
rust Function std::intrinsics::unchecked_div Function std::intrinsics::unchecked\_div
========================================
```
pub const unsafe extern "rust-intrinsic" fn unchecked_div<T>( x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs an unchecked division, resulting in undefined behavior where `y == 0` or `x == T::MIN && y == -1`
Safe wrappers for this intrinsic are available on the integer primitives via the `checked_div` method. For example, [`u32::checked_div`](../primitive.u32#method.checked_div "u32::checked_div")
rust Function std::intrinsics::atomic_singlethreadfence_release Function std::intrinsics::atomic\_singlethreadfence\_release
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_singlethreadfence_release()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
A compiler-only memory barrier.
Memory accesses will never be reordered across this barrier by the compiler, but no instructions will be emitted for it. This is appropriate for operations on the same thread that may be preempted, such as when interacting with signal handlers.
The stabilized version of this intrinsic is available in [`atomic::compiler_fence`](../sync/atomic/fn.compiler_fence "atomic::compiler_fence") by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`.
rust Function std::intrinsics::prefetch_read_data Function std::intrinsics::prefetch\_read\_data
==============================================
```
pub unsafe extern "rust-intrinsic" fn prefetch_read_data<T>( data: *const T, locality: i32)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
The `locality` argument must be a constant integer and is a temporal locality specifier ranging from (0) - no locality, to (3) - extremely local keep in cache.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_xadd_seqcst Function std::intrinsics::atomic\_xadd\_seqcst
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xadd_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Adds to the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_add` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicIsize::fetch_add`](../sync/atomic/struct.atomicisize#method.fetch_add "AtomicIsize::fetch_add").
rust Function std::intrinsics::atomic_load_unordered Function std::intrinsics::atomic\_load\_unordered
=================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_load_unordered<T>( src: *const T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
rust Function std::intrinsics::volatile_set_memory Function std::intrinsics::volatile\_set\_memory
===============================================
```
pub unsafe extern "rust-intrinsic" fn volatile_set_memory<T>( dst: *mut T, val: u8, count: usize)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a size of `count * size_of::<T>()` and an alignment of `min_align_of::<T>()`.
The volatile parameter is set to `true`, so it will not be optimized out unless size is equal to zero.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_cxchg_acqrel_acquire Function std::intrinsics::atomic\_cxchg\_acqrel\_acquire
========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_acqrel_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::atomic_cxchgweak_acquire_relaxed Function std::intrinsics::atomic\_cxchgweak\_acquire\_relaxed
=============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_acquire_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::pref_align_of Function std::intrinsics::pref\_align\_of
=========================================
```
pub unsafe extern "rust-intrinsic" fn pref_align_of<T>() -> usize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The preferred alignment of a type.
This intrinsic does not have a stable counterpart. It’s “tracking issue” is [#91971](https://github.com/rust-lang/rust/issues/91971).
rust Function std::intrinsics::unchecked_rem Function std::intrinsics::unchecked\_rem
========================================
```
pub const unsafe extern "rust-intrinsic" fn unchecked_rem<T>( x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the remainder of an unchecked division, resulting in undefined behavior when `y == 0` or `x == T::MIN && y == -1`
Safe wrappers for this intrinsic are available on the integer primitives via the `checked_rem` method. For example, [`u32::checked_rem`](../primitive.u32#method.checked_rem "u32::checked_rem")
rust Function std::intrinsics::sqrtf32 Function std::intrinsics::sqrtf32
=================================
```
pub unsafe extern "rust-intrinsic" fn sqrtf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the square root of an `f32`
The stabilized version of this intrinsic is [`f32::sqrt`](../primitive.f32#method.sqrt)
rust Function std::intrinsics::atomic_cxchg_seqcst_seqcst Function std::intrinsics::atomic\_cxchg\_seqcst\_seqcst
=======================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_seqcst_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as both the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::log10f64 Function std::intrinsics::log10f64
==================================
```
pub unsafe extern "rust-intrinsic" fn log10f64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the base 10 logarithm of an `f64`.
The stabilized version of this intrinsic is [`f64::log10`](../primitive.f64#method.log10)
rust Function std::intrinsics::truncf32 Function std::intrinsics::truncf32
==================================
```
pub unsafe extern "rust-intrinsic" fn truncf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the integer part of an `f32`.
The stabilized version of this intrinsic is [`f32::trunc`](../primitive.f32#method.trunc)
rust Function std::intrinsics::sinf32 Function std::intrinsics::sinf32
================================
```
pub unsafe extern "rust-intrinsic" fn sinf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the sine of an `f32`.
The stabilized version of this intrinsic is [`f32::sin`](../primitive.f32#method.sin)
rust Function std::intrinsics::logf32 Function std::intrinsics::logf32
================================
```
pub unsafe extern "rust-intrinsic" fn logf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the natural logarithm of an `f32`.
The stabilized version of this intrinsic is [`f32::ln`](../primitive.f32#method.ln)
rust Function std::intrinsics::add_with_overflow Function std::intrinsics::add\_with\_overflow
=============================================
```
pub const extern "rust-intrinsic" fn add_with_overflow<T>( x: T, y: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs checked integer addition.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `overflowing_add` method. For example, [`u32::overflowing_add`](../primitive.u32#method.overflowing_add "u32::overflowing_add")
rust Function std::intrinsics::atomic_xor_seqcst Function std::intrinsics::atomic\_xor\_seqcst
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xor_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise xor with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_xor` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicBool::fetch_xor`](../sync/atomic/struct.atomicbool#method.fetch_xor "AtomicBool::fetch_xor").
rust Function std::intrinsics::rintf64 Function std::intrinsics::rintf64
=================================
```
pub unsafe extern "rust-intrinsic" fn rintf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the nearest integer to an `f64`. May raise an inexact floating-point exception if the argument is not an integer.
rust Function std::intrinsics::atomic_fence_seqcst Function std::intrinsics::atomic\_fence\_seqcst
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_fence_seqcst()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
An atomic fence.
The stabilized version of this intrinsic is available in [`atomic::fence`](../sync/atomic/fn.fence "atomic::fence") by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`.
rust Function std::intrinsics::unchecked_shl Function std::intrinsics::unchecked\_shl
========================================
```
pub const unsafe extern "rust-intrinsic" fn unchecked_shl<T>( x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs an unchecked left shift, resulting in undefined behavior when `y < 0` or `y >= N`, where N is the width of T in bits.
Safe wrappers for this intrinsic are available on the integer primitives via the `checked_shl` method. For example, [`u32::checked_shl`](../primitive.u32#method.checked_shl "u32::checked_shl")
rust Function std::intrinsics::roundf64 Function std::intrinsics::roundf64
==================================
```
pub unsafe extern "rust-intrinsic" fn roundf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
The stabilized version of this intrinsic is [`f64::round`](../primitive.f64#method.round)
rust Function std::intrinsics::atomic_cxchg_release_acquire Function std::intrinsics::atomic\_cxchg\_release\_acquire
=========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_release_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
| programming_docs |
rust Function std::intrinsics::atomic_umin_release Function std::intrinsics::atomic\_umin\_release
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umin_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_min` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicU32::fetch_min`](../sync/atomic/struct.atomicu32#method.fetch_min "AtomicU32::fetch_min").
rust Function std::intrinsics::ptr_mask Function std::intrinsics::ptr\_mask
===================================
```
pub extern "rust-intrinsic" fn ptr_mask<T>( ptr: *const T, mask: usize) -> *const T
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Masks out bits of the pointer according to a mask.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
Consider using [`pointer::mask`](../primitive.pointer#method.mask "pointer::mask") instead.
rust Function std::intrinsics::atomic_umax_acqrel Function std::intrinsics::atomic\_umax\_acqrel
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umax_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_max` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicU32::fetch_max`](../sync/atomic/struct.atomicu32#method.fetch_max "AtomicU32::fetch_max").
rust Function std::intrinsics::roundf32 Function std::intrinsics::roundf32
==================================
```
pub unsafe extern "rust-intrinsic" fn roundf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
The stabilized version of this intrinsic is [`f32::round`](../primitive.f32#method.round)
rust Function std::intrinsics::atomic_cxchgweak_acqrel_seqcst Function std::intrinsics::atomic\_cxchgweak\_acqrel\_seqcst
===========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_acqrel_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::variant_count Function std::intrinsics::variant\_count
========================================
```
pub extern "rust-intrinsic" fn variant_count<T>() -> usize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the number of variants of the type `T` cast to a `usize`; if `T` has no variants, returns `0`. Uninhabited variants will be counted.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The to-be-stabilized version of this intrinsic is [`mem::variant_count`](../mem/fn.variant_count "mem::variant_count").
rust Function std::intrinsics::size_of Function std::intrinsics::size\_of
==================================
```
pub const extern "rust-intrinsic" fn size_of<T>() -> usize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The size of a type in bytes.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
More specifically, this is the offset in bytes between successive items of the same type, including alignment padding.
The stabilized version of this intrinsic is [`core::mem::size_of`](../mem/fn.size_of "core::mem::size_of").
rust Function std::intrinsics::atomic_cxchgweak_relaxed_seqcst Function std::intrinsics::atomic\_cxchgweak\_relaxed\_seqcst
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_relaxed_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::arith_offset Function std::intrinsics::arith\_offset
=======================================
```
pub const unsafe extern "rust-intrinsic" fn arith_offset<T>( dst: *const T, offset: isize) -> *const T
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Calculates the offset from a pointer, potentially wrapping.
This is implemented as an intrinsic to avoid converting to and from an integer, since the conversion inhibits certain optimizations.
Safety
------
Unlike the `offset` intrinsic, this intrinsic does not restrict the resulting pointer to point into or one byte past the end of an allocated object, and it wraps with two’s complement arithmetic. The resulting value is not necessarily valid to be used to actually access memory.
The stabilized version of this intrinsic is [`pointer::wrapping_offset`](../primitive.pointer#method.wrapping_offset "pointer::wrapping_offset").
rust Function std::intrinsics::bitreverse Function std::intrinsics::bitreverse
====================================
```
pub const extern "rust-intrinsic" fn bitreverse<T>(x: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Reverses the bits in an integer type `T`.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `reverse_bits` method. For example, [`u32::reverse_bits`](../primitive.u32#method.reverse_bits "u32::reverse_bits")
rust Function std::intrinsics::atomic_store_release Function std::intrinsics::atomic\_store\_release
================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_store_release<T>( dst: *mut T, val: T)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `store` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicBool::store`](../sync/atomic/struct.atomicbool#method.store "AtomicBool::store").
rust Function std::intrinsics::atomic_umax_release Function std::intrinsics::atomic\_umax\_release
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umax_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_max` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicU32::fetch_max`](../sync/atomic/struct.atomicu32#method.fetch_max "AtomicU32::fetch_max").
rust Function std::intrinsics::rintf32 Function std::intrinsics::rintf32
=================================
```
pub unsafe extern "rust-intrinsic" fn rintf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the nearest integer to an `f32`. May raise an inexact floating-point exception if the argument is not an integer.
rust Function std::intrinsics::truncf64 Function std::intrinsics::truncf64
==================================
```
pub unsafe extern "rust-intrinsic" fn truncf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the integer part of an `f64`.
The stabilized version of this intrinsic is [`f64::trunc`](../primitive.f64#method.trunc)
rust Function std::intrinsics::atomic_cxchg_relaxed_acquire Function std::intrinsics::atomic\_cxchg\_relaxed\_acquire
=========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_relaxed_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::sinf64 Function std::intrinsics::sinf64
================================
```
pub unsafe extern "rust-intrinsic" fn sinf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the sine of an `f64`.
The stabilized version of this intrinsic is [`f64::sin`](../primitive.f64#method.sin)
rust Function std::intrinsics::logf64 Function std::intrinsics::logf64
================================
```
pub unsafe extern "rust-intrinsic" fn logf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the natural logarithm of an `f64`.
The stabilized version of this intrinsic is [`f64::ln`](../primitive.f64#method.ln)
rust Function std::intrinsics::atomic_min_acqrel Function std::intrinsics::atomic\_min\_acqrel
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_min_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_min` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicI32::fetch_min`](../sync/atomic/struct.atomici32#method.fetch_min "AtomicI32::fetch_min").
rust Function std::intrinsics::sqrtf64 Function std::intrinsics::sqrtf64
=================================
```
pub unsafe extern "rust-intrinsic" fn sqrtf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the square root of an `f64`
The stabilized version of this intrinsic is [`f64::sqrt`](../primitive.f64#method.sqrt)
rust Function std::intrinsics::atomic_singlethreadfence_acqrel Function std::intrinsics::atomic\_singlethreadfence\_acqrel
===========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_singlethreadfence_acqrel()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
A compiler-only memory barrier.
Memory accesses will never be reordered across this barrier by the compiler, but no instructions will be emitted for it. This is appropriate for operations on the same thread that may be preempted, such as when interacting with signal handlers.
The stabilized version of this intrinsic is available in [`atomic::compiler_fence`](../sync/atomic/fn.compiler_fence "atomic::compiler_fence") by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`.
rust Function std::intrinsics::log10f32 Function std::intrinsics::log10f32
==================================
```
pub unsafe extern "rust-intrinsic" fn log10f32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the base 10 logarithm of an `f32`.
The stabilized version of this intrinsic is [`f32::log10`](../primitive.f32#method.log10)
rust Function std::intrinsics::exact_div Function std::intrinsics::exact\_div
====================================
```
pub unsafe extern "rust-intrinsic" fn exact_div<T>(x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs an exact division, resulting in undefined behavior where `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::min_align_of Function std::intrinsics::min\_align\_of
========================================
```
pub const extern "rust-intrinsic" fn min_align_of<T>() -> usize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The minimum alignment of a type.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`core::mem::align_of`](../mem/fn.align_of "core::mem::align_of").
rust Function std::intrinsics::atomic_or_acqrel Function std::intrinsics::atomic\_or\_acqrel
============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_or_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise or with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_or` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicBool::fetch_or`](../sync/atomic/struct.atomicbool#method.fetch_or "AtomicBool::fetch_or").
rust Function std::intrinsics::atomic_xor_acquire Function std::intrinsics::atomic\_xor\_acquire
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xor_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise xor with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_xor` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicBool::fetch_xor`](../sync/atomic/struct.atomicbool#method.fetch_xor "AtomicBool::fetch_xor").
rust Function std::intrinsics::assume Function std::intrinsics::assume
================================
```
pub unsafe extern "rust-intrinsic" fn assume(b: bool)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Informs the optimizer that a condition is always true. If the condition is false, the behavior is undefined.
No code is generated for this intrinsic, but the optimizer will try to preserve it (and its condition) between passes, which may interfere with optimization of surrounding code and reduce performance. It should not be used if the invariant can be discovered by the optimizer on its own, or if it does not enable any significant optimizations.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::fsub_fast Function std::intrinsics::fsub\_fast
====================================
```
pub unsafe extern "rust-intrinsic" fn fsub_fast<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Float subtraction that allows optimizations based on algebraic rules. May assume inputs are finite.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_cxchgweak_seqcst_relaxed Function std::intrinsics::atomic\_cxchgweak\_seqcst\_relaxed
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_seqcst_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::rustc_peek Function std::intrinsics::rustc\_peek
=====================================
```
pub extern "rust-intrinsic" fn rustc_peek<T>(T) -> T
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Magic intrinsic that derives its meaning from attributes attached to the function.
For example, dataflow uses this to inject static assertions so that `rustc_peek(potentially_uninitialized)` would actually double-check that dataflow did indeed compute that it is uninitialized at that point in the control flow.
This intrinsic should not be used outside of the compiler.
rust Function std::intrinsics::atomic_nand_acquire Function std::intrinsics::atomic\_nand\_acquire
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_nand_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise nand with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`AtomicBool`](../sync/atomic/struct.atomicbool "AtomicBool") type via the `fetch_nand` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicBool::fetch_nand`](../sync/atomic/struct.atomicbool#method.fetch_nand "AtomicBool::fetch_nand").
| programming_docs |
rust Function std::intrinsics::unchecked_add Function std::intrinsics::unchecked\_add
========================================
```
pub unsafe extern "rust-intrinsic" fn unchecked_add<T>(x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the result of an unchecked addition, resulting in undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::powif32 Function std::intrinsics::powif32
=================================
```
pub unsafe extern "rust-intrinsic" fn powif32(a: f32, x: i32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Raises an `f32` to an integer power.
The stabilized version of this intrinsic is [`f32::powi`](../primitive.f32#method.powi)
rust Function std::intrinsics::ctlz_nonzero Function std::intrinsics::ctlz\_nonzero
=======================================
```
pub const unsafe extern "rust-intrinsic" fn ctlz_nonzero<T>(x: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Like `ctlz`, but extra-unsafe as it returns `undef` when given an `x` with value `0`.
This intrinsic does not have a stable counterpart.
Examples
--------
```
#![feature(core_intrinsics)]
use std::intrinsics::ctlz_nonzero;
let x = 0b0001_1100_u8;
let num_leading = unsafe { ctlz_nonzero(x) };
assert_eq!(num_leading, 3);
```
rust Function std::intrinsics::volatile_load Function std::intrinsics::volatile\_load
========================================
```
pub unsafe extern "rust-intrinsic" fn volatile_load<T>( src: *const T) -> T
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs a volatile load from the `src` pointer.
The stabilized version of this intrinsic is [`core::ptr::read_volatile`](../ptr/fn.read_volatile "core::ptr::read_volatile").
rust Function std::intrinsics::ctpop Function std::intrinsics::ctpop
===============================
```
pub const extern "rust-intrinsic" fn ctpop<T>(x: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the number of bits set in an integer type `T`
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `count_ones` method. For example, [`u32::count_ones`](../primitive.u32#method.count_ones "u32::count_ones")
rust Function std::intrinsics::caller_location Function std::intrinsics::caller\_location
==========================================
```
pub extern "rust-intrinsic" fn caller_location() -> &'static Location<'static>
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Gets a reference to a static `Location` indicating where it was called.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
Consider using [`core::panic::Location::caller`](../panic/struct.location#method.caller "core::panic::Location::caller") instead.
rust Function std::intrinsics::log2f64 Function std::intrinsics::log2f64
=================================
```
pub unsafe extern "rust-intrinsic" fn log2f64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the base 2 logarithm of an `f64`.
The stabilized version of this intrinsic is [`f64::log2`](../primitive.f64#method.log2)
rust Function std::intrinsics::try Function std::intrinsics::try
=============================
```
pub unsafe extern "rust-intrinsic" fn try( try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Rust’s “try catch” construct which invokes the function pointer `try_fn` with the data pointer `data`.
The third argument is a function called if a panic occurs. This function takes the data pointer and a pointer to the target-specific exception object that was caught. For more information see the compiler’s source as well as std’s catch implementation.
rust Function std::intrinsics::wrapping_mul Function std::intrinsics::wrapping\_mul
=======================================
```
pub const extern "rust-intrinsic" fn wrapping_mul<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns (a \* b) mod 2N, where N is the width of T in bits.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `wrapping_mul` method. For example, [`u32::wrapping_mul`](../primitive.u32#method.wrapping_mul "u32::wrapping_mul")
rust Function std::intrinsics::offset Function std::intrinsics::offset
================================
```
pub const unsafe extern "rust-intrinsic" fn offset<T>( dst: *const T, offset: isize) -> *const T
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Calculates the offset from a pointer.
This is implemented as an intrinsic to avoid converting to and from an integer, since the conversion would throw away aliasing information.
Safety
------
Both the starting and resulting pointer must be either in bounds or one byte past the end of an allocated object. If either pointer is out of bounds or arithmetic overflow occurs then any further use of the returned value will result in undefined behavior.
The stabilized version of this intrinsic is [`pointer::offset`](../primitive.pointer#method.offset "pointer::offset").
rust Function std::intrinsics::atomic_store_seqcst Function std::intrinsics::atomic\_store\_seqcst
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_store_seqcst<T>( dst: *mut T, val: T)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `store` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicBool::store`](../sync/atomic/struct.atomicbool#method.store "AtomicBool::store").
rust Function std::intrinsics::atomic_xsub_seqcst Function std::intrinsics::atomic\_xsub\_seqcst
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xsub_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Subtract from the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_sub` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicIsize::fetch_sub`](../sync/atomic/struct.atomicisize#method.fetch_sub "AtomicIsize::fetch_sub").
rust Function std::intrinsics::const_allocate Function std::intrinsics::const\_allocate
=========================================
```
pub unsafe extern "rust-intrinsic" fn const_allocate( size: usize, align: usize) -> *mut u8
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Allocates a block of memory at compile time. At runtime, just returns a null pointer.
Safety
------
* The `align` argument must be a power of two.
+ At compile time, a compile error occurs if this constraint is violated.
+ At runtime, it is not checked.
rust Function std::intrinsics::rotate_right Function std::intrinsics::rotate\_right
=======================================
```
pub const extern "rust-intrinsic" fn rotate_right<T>(x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs rotate right.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `rotate_right` method. For example, [`u32::rotate_right`](../primitive.u32#method.rotate_right "u32::rotate_right")
rust Function std::intrinsics::floorf32 Function std::intrinsics::floorf32
==================================
```
pub unsafe extern "rust-intrinsic" fn floorf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the largest integer less than or equal to an `f32`.
The stabilized version of this intrinsic is [`f32::floor`](../primitive.f32#method.floor)
rust Function std::intrinsics::atomic_or_acquire Function std::intrinsics::atomic\_or\_acquire
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_or_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise or with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_or` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicBool::fetch_or`](../sync/atomic/struct.atomicbool#method.fetch_or "AtomicBool::fetch_or").
rust Function std::intrinsics::atomic_umin_seqcst Function std::intrinsics::atomic\_umin\_seqcst
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umin_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_min` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicU32::fetch_min`](../sync/atomic/struct.atomicu32#method.fetch_min "AtomicU32::fetch_min").
rust Function std::intrinsics::atomic_cxchgweak_release_seqcst Function std::intrinsics::atomic\_cxchgweak\_release\_seqcst
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_release_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::atomic_cxchg_acquire_relaxed Function std::intrinsics::atomic\_cxchg\_acquire\_relaxed
=========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_acquire_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::atomic_fence_release Function std::intrinsics::atomic\_fence\_release
================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_fence_release()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
An atomic fence.
The stabilized version of this intrinsic is available in [`atomic::fence`](../sync/atomic/fn.fence "atomic::fence") by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`.
rust Function std::intrinsics::fadd_fast Function std::intrinsics::fadd\_fast
====================================
```
pub unsafe extern "rust-intrinsic" fn fadd_fast<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Float addition that allows optimizations based on algebraic rules. May assume inputs are finite.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_max_seqcst Function std::intrinsics::atomic\_max\_seqcst
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_max_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_max` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicI32::fetch_max`](../sync/atomic/struct.atomici32#method.fetch_max "AtomicI32::fetch_max").
rust Function std::intrinsics::atomic_cxchg_acquire_seqcst Function std::intrinsics::atomic\_cxchg\_acquire\_seqcst
========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_acquire_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::maxnumf64 Function std::intrinsics::maxnumf64
===================================
```
pub extern "rust-intrinsic" fn maxnumf64(x: f64, y: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the maximum of two `f64` values.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`f64::max`](../primitive.f64#method.max "f64::max")
rust Function std::intrinsics::ptr_offset_from Function std::intrinsics::ptr\_offset\_from
===========================================
```
pub const unsafe extern "rust-intrinsic" fn ptr_offset_from<T>( ptr: *const T, base: *const T) -> isize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
See documentation of `<*const T>::offset_from` for details.
rust Function std::intrinsics::atomic_cxchgweak_acqrel_relaxed Function std::intrinsics::atomic\_cxchgweak\_acqrel\_relaxed
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_acqrel_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::maxnumf32 Function std::intrinsics::maxnumf32
===================================
```
pub extern "rust-intrinsic" fn maxnumf32(x: f32, y: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the maximum of two `f32` values.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`f32::max`](../primitive.f32#method.max "f32::max")
rust Function std::intrinsics::frem_fast Function std::intrinsics::frem\_fast
====================================
```
pub unsafe extern "rust-intrinsic" fn frem_fast<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Float remainder that allows optimizations based on algebraic rules. May assume inputs are finite.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_cxchg_seqcst_acquire Function std::intrinsics::atomic\_cxchg\_seqcst\_acquire
========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_seqcst_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::forget Function std::intrinsics::forget
================================
```
pub extern "rust-intrinsic" fn forget<T>(T)where T: ?Sized,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Moves a value out of scope without running drop glue.
This exists solely for [`mem::forget_unsized`](../mem/fn.forget_unsized "mem::forget_unsized"); normal `forget` uses `ManuallyDrop` instead.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
rust Function std::intrinsics::const_deallocate Function std::intrinsics::const\_deallocate
===========================================
```
pub unsafe extern "rust-intrinsic" fn const_deallocate( ptr: *mut u8, size: usize, align: usize)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Deallocates a memory which allocated by `intrinsics::const_allocate` at compile time. At runtime, does nothing.
Safety
------
* The `align` argument must be a power of two.
+ At compile time, a compile error occurs if this constraint is violated.
+ At runtime, it is not checked.
* If the `ptr` is created in an another const, this intrinsic doesn’t deallocate it.
* If the `ptr` is pointing to a local variable, this intrinsic doesn’t deallocate it.
| programming_docs |
rust Function std::intrinsics::atomic_xadd_acquire Function std::intrinsics::atomic\_xadd\_acquire
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xadd_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Adds to the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_add` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicIsize::fetch_add`](../sync/atomic/struct.atomicisize#method.fetch_add "AtomicIsize::fetch_add").
rust Function std::intrinsics::atomic_and_acquire Function std::intrinsics::atomic\_and\_acquire
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_and_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise and with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_and` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicBool::fetch_and`](../sync/atomic/struct.atomicbool#method.fetch_and "AtomicBool::fetch_and").
rust Function std::intrinsics::breakpoint Function std::intrinsics::breakpoint
====================================
```
pub unsafe extern "rust-intrinsic" fn breakpoint()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Executes a breakpoint trap, for inspection by a debugger.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::unchecked_sub Function std::intrinsics::unchecked\_sub
========================================
```
pub unsafe extern "rust-intrinsic" fn unchecked_sub<T>(x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the result of an unchecked subtraction, resulting in undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_umin_relaxed Function std::intrinsics::atomic\_umin\_relaxed
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umin_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_min` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicU32::fetch_min`](../sync/atomic/struct.atomicu32#method.fetch_min "AtomicU32::fetch_min").
rust Function std::intrinsics::atomic_and_acqrel Function std::intrinsics::atomic\_and\_acqrel
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_and_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise and with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_and` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicBool::fetch_and`](../sync/atomic/struct.atomicbool#method.fetch_and "AtomicBool::fetch_and").
rust Function std::intrinsics::atomic_umax_relaxed Function std::intrinsics::atomic\_umax\_relaxed
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umax_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_max` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicU32::fetch_max`](../sync/atomic/struct.atomicu32#method.fetch_max "AtomicU32::fetch_max").
rust Function std::intrinsics::atomic_store_relaxed Function std::intrinsics::atomic\_store\_relaxed
================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_store_relaxed<T>( dst: *mut T, val: T)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `store` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicBool::store`](../sync/atomic/struct.atomicbool#method.store "AtomicBool::store").
rust Function std::intrinsics::vtable_size Function std::intrinsics::vtable\_size
======================================
```
pub unsafe extern "rust-intrinsic" fn vtable_size( ptr: *const ()) -> usize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
`ptr` must point to a vtable. The intrinsic will return the size stored in that vtable.
rust Function std::intrinsics::copy_nonoverlapping Function std::intrinsics::copy\_nonoverlapping
==============================================
```
pub const unsafe fn copy_nonoverlapping<T>( src: *const T, dst: *mut T, count: usize)
```
Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source and destination must *not* overlap.
For regions of memory which might overlap, use [`copy`](../ptr/fn.copy "copy") instead.
`copy_nonoverlapping` is semantically equivalent to C’s [`memcpy`](https://en.cppreference.com/w/c/string/byte/memcpy), but with the argument order swapped.
The copy is “untyped” in the sense that data may be uninitialized or otherwise violate the requirements of `T`. The initialization state is preserved exactly.
Safety
------
Behavior is undefined if any of the following conditions are violated:
* `src` must be [valid](../ptr/index#safety) for reads of `count * size_of::<T>()` bytes.
* `dst` must be [valid](../ptr/index#safety) for writes of `count * size_of::<T>()` bytes.
* Both `src` and `dst` must be properly aligned.
* The region of memory beginning at `src` with a size of `count * size_of::<T>()` bytes must *not* overlap with the region of memory beginning at `dst` with the same size.
Like [`read`](../ptr/fn.read), `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of whether `T` is [`Copy`](../marker/trait.copy "Copy"). If `T` is not [`Copy`](../marker/trait.copy "Copy"), using *both* the values in the region beginning at `*src` and the region beginning at `*dst` can [violate memory safety](../ptr/fn.read#ownership-of-the-returned-value).
Note that even if the effectively copied size (`count * size_of::<T>()`) is `0`, the pointers must be non-null and properly aligned.
Examples
--------
Manually implement [`Vec::append`](../vec/struct.vec#method.append):
```
use std::ptr;
/// Moves all the elements of `src` into `dst`, leaving `src` empty.
fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
let src_len = src.len();
let dst_len = dst.len();
// Ensure that `dst` has enough capacity to hold all of `src`.
dst.reserve(src_len);
unsafe {
// The call to add is always safe because `Vec` will never
// allocate more than `isize::MAX` bytes.
let dst_ptr = dst.as_mut_ptr().add(dst_len);
let src_ptr = src.as_ptr();
// Truncate `src` without dropping its contents. We do this first,
// to avoid problems in case something further down panics.
src.set_len(0);
// The two regions cannot overlap because mutable references do
// not alias, and two different vectors cannot own the same
// memory.
ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
// Notify `dst` that it now holds the contents of `src`.
dst.set_len(dst_len + src_len);
}
}
let mut a = vec!['r'];
let mut b = vec!['u', 's', 't'];
append(&mut a, &mut b);
assert_eq!(a, &['r', 'u', 's', 't']);
assert!(b.is_empty());
```
rust Function std::intrinsics::floorf64 Function std::intrinsics::floorf64
==================================
```
pub unsafe extern "rust-intrinsic" fn floorf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the largest integer less than or equal to an `f64`.
The stabilized version of this intrinsic is [`f64::floor`](../primitive.f64#method.floor)
rust Function std::intrinsics::atomic_max_acquire Function std::intrinsics::atomic\_max\_acquire
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_max_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_max` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicI32::fetch_max`](../sync/atomic/struct.atomici32#method.fetch_max "AtomicI32::fetch_max").
rust Function std::intrinsics::atomic_xchg_acquire Function std::intrinsics::atomic\_xchg\_acquire
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xchg_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location, returning the old value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `swap` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicBool::swap`](../sync/atomic/struct.atomicbool#method.swap "AtomicBool::swap").
rust Function std::intrinsics::unlikely Function std::intrinsics::unlikely
==================================
```
pub extern "rust-intrinsic" fn unlikely(b: bool) -> bool
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Hints to the compiler that branch condition is likely to be false. Returns the value passed to it.
Any use other than with `if` statements will probably not have an effect.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_cxchgweak_relaxed_acquire Function std::intrinsics::atomic\_cxchgweak\_relaxed\_acquire
=============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_relaxed_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::write_bytes Function std::intrinsics::write\_bytes
======================================
```
pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize)
```
Sets `count * size_of::<T>()` bytes of memory starting at `dst` to `val`.
`write_bytes` is similar to C’s [`memset`](https://en.cppreference.com/w/c/string/byte/memset), but sets `count * size_of::<T>()` bytes to `val`.
Safety
------
Behavior is undefined if any of the following conditions are violated:
* `dst` must be [valid](../ptr/index#safety) for writes of `count * size_of::<T>()` bytes.
* `dst` must be properly aligned.
Note that even if the effectively copied size (`count * size_of::<T>()`) is `0`, the pointer must be non-null and properly aligned.
Additionally, note that changing `*dst` in this way can easily lead to undefined behavior (UB) later if the written bytes are not a valid representation of some `T`. For instance, the following is an **incorrect** use of this function:
```
unsafe {
let mut value: u8 = 0;
let ptr: *mut bool = &mut value as *mut u8 as *mut bool;
let _bool = ptr.read(); // This is fine, `ptr` points to a valid `bool`.
ptr.write_bytes(42u8, 1); // This function itself does not cause UB...
let _bool = ptr.read(); // ...but it makes this operation UB! ⚠️
}
```
Examples
--------
Basic usage:
```
use std::ptr;
let mut vec = vec![0u32; 4];
unsafe {
let vec_ptr = vec.as_mut_ptr();
ptr::write_bytes(vec_ptr, 0xfe, 2);
}
assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
```
rust Function std::intrinsics::atomic_min_acquire Function std::intrinsics::atomic\_min\_acquire
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_min_acquire<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_min` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`. For example, [`AtomicI32::fetch_min`](../sync/atomic/struct.atomici32#method.fetch_min "AtomicI32::fetch_min").
rust Function std::intrinsics::atomic_xchg_seqcst Function std::intrinsics::atomic\_xchg\_seqcst
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xchg_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location, returning the old value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `swap` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicBool::swap`](../sync/atomic/struct.atomicbool#method.swap "AtomicBool::swap").
rust Function std::intrinsics::atomic_nand_seqcst Function std::intrinsics::atomic\_nand\_seqcst
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_nand_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise nand with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`AtomicBool`](../sync/atomic/struct.atomicbool "AtomicBool") type via the `fetch_nand` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicBool::fetch_nand`](../sync/atomic/struct.atomicbool#method.fetch_nand "AtomicBool::fetch_nand").
rust Function std::intrinsics::atomic_load_relaxed Function std::intrinsics::atomic\_load\_relaxed
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_load_relaxed<T>( src: *const T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Loads the current value of the pointer.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `load` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicBool::load`](../sync/atomic/struct.atomicbool#method.load "AtomicBool::load").
rust Function std::intrinsics::log2f32 Function std::intrinsics::log2f32
=================================
```
pub unsafe extern "rust-intrinsic" fn log2f32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the base 2 logarithm of an `f32`.
The stabilized version of this intrinsic is [`f32::log2`](../primitive.f32#method.log2)
rust Function std::intrinsics::cttz Function std::intrinsics::cttz
==============================
```
pub const extern "rust-intrinsic" fn cttz<T>(x: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the number of trailing unset bits (zeroes) in an integer type `T`.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `trailing_zeros` method. For example, [`u32::trailing_zeros`](../primitive.u32#method.trailing_zeros "u32::trailing_zeros")
Examples
--------
```
#![feature(core_intrinsics)]
use std::intrinsics::cttz;
let x = 0b0011_1000_u8;
let num_trailing = cttz(x);
assert_eq!(num_trailing, 3);
```
An `x` with value `0` will return the bit width of `T`:
```
#![feature(core_intrinsics)]
use std::intrinsics::cttz;
let x = 0u16;
let num_trailing = cttz(x);
assert_eq!(num_trailing, 16);
```
rust Function std::intrinsics::atomic_cxchgweak_release_acquire Function std::intrinsics::atomic\_cxchgweak\_release\_acquire
=============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_release_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::atomic_xor_relaxed Function std::intrinsics::atomic\_xor\_relaxed
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xor_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise xor with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_xor` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicBool::fetch_xor`](../sync/atomic/struct.atomicbool#method.fetch_xor "AtomicBool::fetch_xor").
| programming_docs |
rust Function std::intrinsics::cosf64 Function std::intrinsics::cosf64
================================
```
pub unsafe extern "rust-intrinsic" fn cosf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the cosine of an `f64`.
The stabilized version of this intrinsic is [`f64::cos`](../primitive.f64#method.cos)
rust Function std::intrinsics::atomic_xchg_acqrel Function std::intrinsics::atomic\_xchg\_acqrel
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xchg_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location, returning the old value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `swap` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicBool::swap`](../sync/atomic/struct.atomicbool#method.swap "AtomicBool::swap").
rust Function std::intrinsics::atomic_nand_acqrel Function std::intrinsics::atomic\_nand\_acqrel
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_nand_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise nand with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`AtomicBool`](../sync/atomic/struct.atomicbool "AtomicBool") type via the `fetch_nand` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicBool::fetch_nand`](../sync/atomic/struct.atomicbool#method.fetch_nand "AtomicBool::fetch_nand").
rust Function std::intrinsics::atomic_nand_relaxed Function std::intrinsics::atomic\_nand\_relaxed
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_nand_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise nand with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`AtomicBool`](../sync/atomic/struct.atomicbool "AtomicBool") type via the `fetch_nand` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicBool::fetch_nand`](../sync/atomic/struct.atomicbool#method.fetch_nand "AtomicBool::fetch_nand").
rust Function std::intrinsics::atomic_max_release Function std::intrinsics::atomic\_max\_release
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_max_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_max` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicI32::fetch_max`](../sync/atomic/struct.atomici32#method.fetch_max "AtomicI32::fetch_max").
rust Function std::intrinsics::atomic_cxchgweak_seqcst_acquire Function std::intrinsics::atomic\_cxchgweak\_seqcst\_acquire
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_seqcst_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") and [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::saturating_sub Function std::intrinsics::saturating\_sub
=========================================
```
pub const extern "rust-intrinsic" fn saturating_sub<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Computes `a - b`, saturating at numeric bounds.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `saturating_sub` method. For example, [`u32::saturating_sub`](../primitive.u32#method.saturating_sub "u32::saturating_sub")
rust Function std::intrinsics::atomic_xchg_release Function std::intrinsics::atomic\_xchg\_release
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xchg_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores the value at the specified memory location, returning the old value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `swap` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicBool::swap`](../sync/atomic/struct.atomicbool#method.swap "AtomicBool::swap").
rust Function std::intrinsics::unreachable Function std::intrinsics::unreachable
=====================================
```
pub const unsafe extern "rust-intrinsic" fn unreachable() -> !
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Informs the optimizer that this point in the code is not reachable, enabling further optimizations.
N.B., this is very different from the `unreachable!()` macro: Unlike the macro, which panics when it is executed, it is *undefined behavior* to reach code marked with this function.
The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`](../hint/fn.unreachable_unchecked "core::hint::unreachable_unchecked").
rust Function std::intrinsics::atomic_min_release Function std::intrinsics::atomic\_min\_release
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_min_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_min` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicI32::fetch_min`](../sync/atomic/struct.atomici32#method.fetch_min "AtomicI32::fetch_min").
rust Function std::intrinsics::copysignf64 Function std::intrinsics::copysignf64
=====================================
```
pub unsafe extern "rust-intrinsic" fn copysignf64( x: f64, y: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Copies the sign from `y` to `x` for `f64` values.
The stabilized version of this intrinsic is [`f64::copysign`](../primitive.f64#method.copysign)
rust Function std::intrinsics::atomic_cxchg_release_relaxed Function std::intrinsics::atomic\_cxchg\_release\_relaxed
=========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_release_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::ptr_guaranteed_cmp Function std::intrinsics::ptr\_guaranteed\_cmp
==============================================
```
pub extern "rust-intrinsic" fn ptr_guaranteed_cmp<T>( ptr: *const T, other: *const T) -> u8
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
See documentation of `<*const T>::guaranteed_eq` for details. Returns `2` if the result is unknown. Returns `1` if the pointers are guaranteed equal Returns `0` if the pointers are guaranteed inequal
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
rust Function std::intrinsics::copy Function std::intrinsics::copy
==============================
```
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize)
```
Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source and destination may overlap.
If the source and destination will *never* overlap, [`copy_nonoverlapping`](../ptr/fn.copy_nonoverlapping "copy_nonoverlapping") can be used instead.
`copy` is semantically equivalent to C’s [`memmove`](https://en.cppreference.com/w/c/string/byte/memmove), but with the argument order swapped. Copying takes place as if the bytes were copied from `src` to a temporary array and then copied from the array to `dst`.
The copy is “untyped” in the sense that data may be uninitialized or otherwise violate the requirements of `T`. The initialization state is preserved exactly.
Safety
------
Behavior is undefined if any of the following conditions are violated:
* `src` must be [valid](../ptr/index#safety) for reads of `count * size_of::<T>()` bytes.
* `dst` must be [valid](../ptr/index#safety) for writes of `count * size_of::<T>()` bytes.
* Both `src` and `dst` must be properly aligned.
Like [`read`](../ptr/fn.read), `copy` creates a bitwise copy of `T`, regardless of whether `T` is [`Copy`](../marker/trait.copy "Copy"). If `T` is not [`Copy`](../marker/trait.copy "Copy"), using both the values in the region beginning at `*src` and the region beginning at `*dst` can [violate memory safety](../ptr/fn.read#ownership-of-the-returned-value).
Note that even if the effectively copied size (`count * size_of::<T>()`) is `0`, the pointers must be non-null and properly aligned.
Examples
--------
Efficiently create a Rust vector from an unsafe buffer:
```
use std::ptr;
/// # Safety
///
/// * `ptr` must be correctly aligned for its type and non-zero.
/// * `ptr` must be valid for reads of `elts` contiguous elements of type `T`.
/// * Those elements must not be used after calling this function unless `T: Copy`.
unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
let mut dst = Vec::with_capacity(elts);
// SAFETY: Our precondition ensures the source is aligned and valid,
// and `Vec::with_capacity` ensures that we have usable space to write them.
ptr::copy(ptr, dst.as_mut_ptr(), elts);
// SAFETY: We created it with this much capacity earlier,
// and the previous `copy` has initialized these elements.
dst.set_len(elts);
dst
}
```
rust Function std::intrinsics::atomic_cxchgweak_seqcst_seqcst Function std::intrinsics::atomic\_cxchgweak\_seqcst\_seqcst
===========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_seqcst_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as both the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::ceilf32 Function std::intrinsics::ceilf32
=================================
```
pub unsafe extern "rust-intrinsic" fn ceilf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the smallest integer greater than or equal to an `f32`.
The stabilized version of this intrinsic is [`f32::ceil`](../primitive.f32#method.ceil)
rust Function std::intrinsics::wrapping_add Function std::intrinsics::wrapping\_add
=======================================
```
pub const extern "rust-intrinsic" fn wrapping_add<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns (a + b) mod 2N, where N is the width of T in bits.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `wrapping_add` method. For example, [`u32::wrapping_add`](../primitive.u32#method.wrapping_add "u32::wrapping_add")
rust Function std::intrinsics::atomic_xadd_release Function std::intrinsics::atomic\_xadd\_release
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xadd_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Adds to the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_add` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicIsize::fetch_add`](../sync/atomic/struct.atomicisize#method.fetch_add "AtomicIsize::fetch_add").
rust Function std::intrinsics::atomic_cxchg_relaxed_relaxed Function std::intrinsics::atomic\_cxchg\_relaxed\_relaxed
=========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_relaxed_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as both the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::const_eval_select Function std::intrinsics::const\_eval\_select
=============================================
```
pub unsafe extern "rust-intrinsic" fn const_eval_select<ARG, F, G, RET>( arg: ARG, called_in_const: F, called_at_rt: G) -> RETwhere G: FnOnce<ARG, Output = RET>, F: FnOnce<ARG, Output = RET>,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Selects which function to call depending on the context.
If this function is evaluated at compile-time, then a call to this intrinsic will be replaced with a call to `called_in_const`. It gets replaced with a call to `called_at_rt` otherwise.
Type Requirements
-----------------
The two functions must be both function items. They cannot be function pointers or closures. The first function must be a `const fn`.
`arg` will be the tupled arguments that will be passed to either one of the two functions, therefore, both functions must accept the same type of arguments. Both functions must return RET.
Safety
------
The two functions must behave observably equivalent. Safe code in other crates may assume that calling a `const fn` at compile-time and at run-time produces the same result. A function that produces a different result when evaluated at run-time, or has any other observable side-effects, is *unsound*.
Here is an example of how this could cause a problem:
```
#![feature(const_eval_select)]
#![feature(core_intrinsics)]
use std::hint::unreachable_unchecked;
use std::intrinsics::const_eval_select;
// Crate A
pub const fn inconsistent() -> i32 {
fn runtime() -> i32 { 1 }
const fn compiletime() -> i32 { 2 }
unsafe {
// and `runtime`.
const_eval_select((), compiletime, runtime)
}
}
// Crate B
const X: i32 = inconsistent();
let x = inconsistent();
if x != X { unsafe { unreachable_unchecked(); }}
```
This code causes Undefined Behavior when being run, since the `unreachable_unchecked` is actually being reached. The bug is in *crate A*, which violates the principle that a `const fn` must behave the same at compile-time and at run-time. The unsafe code in crate B is fine.
rust Function std::intrinsics::atomic_and_seqcst Function std::intrinsics::atomic\_and\_seqcst
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_and_seqcst<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise and with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_and` method by passing [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the `order`. For example, [`AtomicBool::fetch_and`](../sync/atomic/struct.atomicbool#method.fetch_and "AtomicBool::fetch_and").
rust Function std::intrinsics::atomic_and_release Function std::intrinsics::atomic\_and\_release
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_and_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise and with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_and` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicBool::fetch_and`](../sync/atomic/struct.atomicbool#method.fetch_and "AtomicBool::fetch_and").
rust Function std::intrinsics::likely Function std::intrinsics::likely
================================
```
pub extern "rust-intrinsic" fn likely(b: bool) -> bool
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Hints to the compiler that branch condition is likely to be true. Returns the value passed to it.
Any use other than with `if` statements will probably not have an effect.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
This intrinsic does not have a stable counterpart.
| programming_docs |
rust Function std::intrinsics::fdiv_fast Function std::intrinsics::fdiv\_fast
====================================
```
pub unsafe extern "rust-intrinsic" fn fdiv_fast<T>(a: T, b: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Float division that allows optimizations based on algebraic rules. May assume inputs are finite.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_fence_acquire Function std::intrinsics::atomic\_fence\_acquire
================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_fence_acquire()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
An atomic fence.
The stabilized version of this intrinsic is available in [`atomic::fence`](../sync/atomic/fn.fence "atomic::fence") by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as the `order`.
rust Function std::intrinsics::atomic_cxchg_acqrel_seqcst Function std::intrinsics::atomic\_cxchg\_acqrel\_seqcst
=======================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_acqrel_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::atomic_umin_acqrel Function std::intrinsics::atomic\_umin\_acqrel
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_umin_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Minimum with the current value using an unsigned comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") unsigned integer types via the `fetch_min` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicU32::fetch_min`](../sync/atomic/struct.atomicu32#method.fetch_min "AtomicU32::fetch_min").
rust Function std::intrinsics::ceilf64 Function std::intrinsics::ceilf64
=================================
```
pub unsafe extern "rust-intrinsic" fn ceilf64(x: f64) -> f64
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the smallest integer greater than or equal to an `f64`.
The stabilized version of this intrinsic is [`f64::ceil`](../primitive.f64#method.ceil)
rust Function std::intrinsics::assert_uninit_valid Function std::intrinsics::assert\_uninit\_valid
===============================================
```
pub extern "rust-intrinsic" fn assert_uninit_valid<T>()
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
A guard for unsafe functions that cannot ever be executed if `T` has invalid bit patterns: This will statically either panic, or do nothing.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_or_release Function std::intrinsics::atomic\_or\_release
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_or_release<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Bitwise or with the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_or` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") as the `order`. For example, [`AtomicBool::fetch_or`](../sync/atomic/struct.atomicbool#method.fetch_or "AtomicBool::fetch_or").
rust Function std::intrinsics::atomic_max_acqrel Function std::intrinsics::atomic\_max\_acqrel
=============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_max_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Maximum with the current value using a signed comparison.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") signed integer types via the `fetch_max` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicI32::fetch_max`](../sync/atomic/struct.atomici32#method.fetch_max "AtomicI32::fetch_max").
rust Function std::intrinsics::prefetch_write_data Function std::intrinsics::prefetch\_write\_data
===============================================
```
pub unsafe extern "rust-intrinsic" fn prefetch_write_data<T>( data: *const T, locality: i32)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.
The `locality` argument must be a constant integer and is a temporal locality specifier ranging from (0) - no locality, to (3) - extremely local keep in cache.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::atomic_cxchgweak_acquire_seqcst Function std::intrinsics::atomic\_cxchgweak\_acquire\_seqcst
============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_acquire_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::volatile_copy_nonoverlapping_memory Function std::intrinsics::volatile\_copy\_nonoverlapping\_memory
================================================================
```
pub unsafe extern "rust-intrinsic" fn volatile_copy_nonoverlapping_memory<T>( dst: *mut T, src: *const T, count: usize)
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with a size of `count` \* `size_of::<T>()` and an alignment of `min_align_of::<T>()`
The volatile parameter is set to `true`, so it will not be optimized out unless size is equal to zero.
This intrinsic does not have a stable counterpart.
rust Function std::intrinsics::copysignf32 Function std::intrinsics::copysignf32
=====================================
```
pub unsafe extern "rust-intrinsic" fn copysignf32( x: f32, y: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Copies the sign from `y` to `x` for `f32` values.
The stabilized version of this intrinsic is [`f32::copysign`](../primitive.f32#method.copysign)
rust Function std::intrinsics::atomic_store_unordered Function std::intrinsics::atomic\_store\_unordered
==================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_store_unordered<T>( dst: *mut T, val: T)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
rust Function std::intrinsics::atomic_xsub_relaxed Function std::intrinsics::atomic\_xsub\_relaxed
===============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xsub_relaxed<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Subtract from the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_sub` method by passing [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the `order`. For example, [`AtomicIsize::fetch_sub`](../sync/atomic/struct.atomicisize#method.fetch_sub "AtomicIsize::fetch_sub").
rust Function std::intrinsics::atomic_cxchg_acqrel_relaxed Function std::intrinsics::atomic\_cxchg\_acqrel\_relaxed
========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_acqrel_relaxed<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") and [`Ordering::Relaxed`](../sync/atomic/enum.ordering#variant.Relaxed "Ordering::Relaxed") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Function std::intrinsics::ctlz Function std::intrinsics::ctlz
==============================
```
pub const extern "rust-intrinsic" fn ctlz<T>(x: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the number of leading unset bits (zeroes) in an integer type `T`.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `leading_zeros` method. For example, [`u32::leading_zeros`](../primitive.u32#method.leading_zeros "u32::leading_zeros")
Examples
--------
```
#![feature(core_intrinsics)]
use std::intrinsics::ctlz;
let x = 0b0001_1100_u8;
let num_leading = ctlz(x);
assert_eq!(num_leading, 3);
```
An `x` with value `0` will return the bit width of `T`.
```
#![feature(core_intrinsics)]
use std::intrinsics::ctlz;
let x = 0u16;
let num_leading = ctlz(x);
assert_eq!(num_leading, 16);
```
rust Function std::intrinsics::type_name Function std::intrinsics::type\_name
====================================
```
pub extern "rust-intrinsic" fn type_name<T>() -> &'static strwhere T: ?Sized,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Gets a static string slice containing the name of a type.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized version of this intrinsic is [`core::any::type_name`](../any/fn.type_name "core::any::type_name").
rust Function std::intrinsics::cosf32 Function std::intrinsics::cosf32
================================
```
pub unsafe extern "rust-intrinsic" fn cosf32(x: f32) -> f32
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Returns the cosine of an `f32`.
The stabilized version of this intrinsic is [`f32::cos`](../primitive.f32#method.cos)
rust Function std::intrinsics::atomic_cxchgweak_acquire_acquire Function std::intrinsics::atomic\_cxchgweak\_acquire\_acquire
=============================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchgweak_acquire_acquire<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange_weak` method by passing [`Ordering::Acquire`](../sync/atomic/enum.ordering#variant.Acquire "Ordering::Acquire") as both the success and failure parameters. For example, [`AtomicBool::compare_exchange_weak`](../sync/atomic/struct.atomicbool#method.compare_exchange_weak "AtomicBool::compare_exchange_weak").
rust Function std::intrinsics::min_align_of_val Function std::intrinsics::min\_align\_of\_val
=============================================
```
pub unsafe extern "rust-intrinsic" fn min_align_of_val<T>( *const T) -> usizewhere T: ?Sized,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
The required alignment of the referenced value.
The stabilized version of this intrinsic is [`core::mem::align_of_val`](../mem/fn.align_of_val "core::mem::align_of_val").
rust Function std::intrinsics::sub_with_overflow Function std::intrinsics::sub\_with\_overflow
=============================================
```
pub const extern "rust-intrinsic" fn sub_with_overflow<T>( x: T, y: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs checked integer subtraction
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `overflowing_sub` method. For example, [`u32::overflowing_sub`](../primitive.u32#method.overflowing_sub "u32::overflowing_sub")
rust Function std::intrinsics::atomic_xsub_acqrel Function std::intrinsics::atomic\_xsub\_acqrel
==============================================
```
pub unsafe extern "rust-intrinsic" fn atomic_xsub_acqrel<T>( dst: *mut T, src: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Subtract from the current value, returning the previous value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `fetch_sub` method by passing [`Ordering::AcqRel`](../sync/atomic/enum.ordering#variant.AcqRel "Ordering::AcqRel") as the `order`. For example, [`AtomicIsize::fetch_sub`](../sync/atomic/struct.atomicisize#method.fetch_sub "AtomicIsize::fetch_sub").
rust Function std::intrinsics::mul_with_overflow Function std::intrinsics::mul\_with\_overflow
=============================================
```
pub const extern "rust-intrinsic" fn mul_with_overflow<T>( x: T, y: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs checked integer multiplication
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `overflowing_mul` method. For example, [`u32::overflowing_mul`](../primitive.u32#method.overflowing_mul "u32::overflowing_mul")
rust Function std::intrinsics::rotate_left Function std::intrinsics::rotate\_left
======================================
```
pub const extern "rust-intrinsic" fn rotate_left<T>(x: T, y: T) -> Twhere T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Performs rotate left.
Note that, unlike most intrinsics, this is safe to call; it does not require an `unsafe` block. Therefore, implementations must not require the user to uphold any safety invariants.
The stabilized versions of this intrinsic are available on the integer primitives via the `rotate_left` method. For example, [`u32::rotate_left`](../primitive.u32#method.rotate_left "u32::rotate_left")
rust Function std::intrinsics::ptr_offset_from_unsigned Function std::intrinsics::ptr\_offset\_from\_unsigned
=====================================================
```
pub unsafe extern "rust-intrinsic" fn ptr_offset_from_unsigned<T>( ptr: *const T, base: *const T) -> usize
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
See documentation of `<*const T>::sub_ptr` for details.
rust Function std::intrinsics::atomic_cxchg_release_seqcst Function std::intrinsics::atomic\_cxchg\_release\_seqcst
========================================================
```
pub unsafe extern "rust-intrinsic" fn atomic_cxchg_release_seqcst<T>( dst: *mut T, old: T, src: T) -> (T, bool)where T: Copy,
```
🔬This is a nightly-only experimental API. (`core_intrinsics`)
Stores a value if the current value is the same as the `old` value.
The stabilized version of this intrinsic is available on the [`atomic`](../sync/atomic/index "atomic") types via the `compare_exchange` method by passing [`Ordering::Release`](../sync/atomic/enum.ordering#variant.Release "Ordering::Release") and [`Ordering::SeqCst`](../sync/atomic/enum.ordering#variant.SeqCst "Ordering::SeqCst") as the success and failure parameters. For example, [`AtomicBool::compare_exchange`](../sync/atomic/struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange").
rust Module std::string Module std::string
==================
A UTF-8–encoded, growable string.
This module contains the [`String`](struct.string "String") type, the [`ToString`](trait.tostring "ToString") trait for converting to strings, and several error types that may result from working with [`String`](struct.string "String")s.
Examples
--------
There are multiple ways to create a new [`String`](struct.string "String") from a string literal:
```
let s = "Hello".to_string();
let s = String::from("world");
let s: String = "also this".into();
```
You can create a new [`String`](struct.string "String") from an existing one by concatenating with `+`:
```
let s = "Hello".to_string();
let message = s + " world!";
```
If you have a vector of valid UTF-8 bytes, you can make a [`String`](struct.string "String") out of it. You can do the reverse too.
```
let sparkle_heart = vec![240, 159, 146, 150];
// We know these bytes are valid, so we'll use `unwrap()`.
let sparkle_heart = String::from_utf8(sparkle_heart).unwrap();
assert_eq!("💖", sparkle_heart);
let bytes = sparkle_heart.into_bytes();
assert_eq!(bytes, [240, 159, 146, 150]);
```
Structs
-------
[Drain](struct.drain "std::string::Drain struct")
A draining iterator for `String`.
[FromUtf8Error](struct.fromutf8error "std::string::FromUtf8Error struct")
A possible error value when converting a `String` from a UTF-8 byte vector.
[FromUtf16Error](struct.fromutf16error "std::string::FromUtf16Error struct")
A possible error value when converting a `String` from a UTF-16 byte slice.
[String](struct.string "std::string::String struct")
A UTF-8–encoded, growable string.
Traits
------
[ToString](trait.tostring "std::string::ToString trait")
A trait for converting a value to a `String`.
Type Definitions
----------------
[ParseError](type.parseerror "std::string::ParseError type")
A type alias for [`Infallible`](../convert/enum.infallible "convert::Infallible").
rust Struct std::string::FromUtf16Error Struct std::string::FromUtf16Error
==================================
```
pub struct FromUtf16Error(_);
```
A possible error value when converting a `String` from a UTF-16 byte slice.
This type is the error type for the [`from_utf16`](struct.string#method.from_utf16) method on [`String`](struct.string "String").
Examples
--------
Basic usage:
```
// 𝄞mu<invalid>ic
let v = &[0xD834, 0xDD1E, 0x006d, 0x0075,
0xD800, 0x0069, 0x0063];
assert!(String::from_utf16(v).is_err());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#430)### impl Debug for FromUtf16Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#430)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1938)### impl Display for FromUtf16Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1939)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1955)### impl Error for FromUtf16Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1957)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../error/trait.error#method.provide)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for FromUtf16Error
### impl Send for FromUtf16Error
### impl Sync for FromUtf16Error
### impl Unpin for FromUtf16Error
### impl UnwindSafe for FromUtf16Error
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../error/trait.error "trait std::error::Error") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Trait std::string::ToString Trait std::string::ToString
===========================
```
pub trait ToString {
fn to_string(&self) -> String;
}
```
A trait for converting a value to a `String`.
This trait is automatically implemented for any type which implements the [`Display`](../fmt/trait.display) trait. As such, `ToString` shouldn’t be implemented directly: [`Display`](../fmt/trait.display) should be implemented instead, and you get the `ToString` implementation for free.
Required Methods
----------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2489)#### fn to\_string(&self) -> String
Converts the given value to a `String`.
##### Examples
Basic usage:
```
let i = 5;
let five = String::from("5");
assert_eq!(five, i.to_string());
```
Implementors
------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2579)1.17.0 · ### impl ToString for Cow<'\_, str>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2518)1.46.0 · ### impl ToString for char
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2547)1.54.0 · ### impl ToString for i8
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2570)1.9.0 · ### impl ToString for str
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2527)1.54.0 · ### impl ToString for u8
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2588)1.17.0 · ### impl ToString for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
#### Panics
In this implementation, the `to_string` method panics if the `Display` implementation returns an error. This indicates an incorrect `Display` implementation since `fmt::Write for String` never returns an error itself.
rust Struct std::string::String Struct std::string::String
==========================
```
pub struct String { /* private fields */ }
```
A UTF-8–encoded, growable string.
The `String` type is the most common string type that has ownership over the contents of the string. It has a close relationship with its borrowed counterpart, the primitive [`str`](../primitive.str "str").
Examples
--------
You can create a `String` from [a literal string](../primitive.str "&str") with [`String::from`](../convert/trait.from#tymethod.from):
```
let hello = String::from("Hello, world!");
```
You can append a [`char`](../primitive.char "char") to a `String` with the [`push`](struct.string#method.push) method, and append a [`&str`](../primitive.str "&str") with the [`push_str`](struct.string#method.push_str) method:
```
let mut hello = String::from("Hello, ");
hello.push('w');
hello.push_str("orld!");
```
If you have a vector of UTF-8 bytes, you can create a `String` from it with the [`from_utf8`](struct.string#method.from_utf8) method:
```
// some bytes, in a vector
let sparkle_heart = vec![240, 159, 146, 150];
// We know these bytes are valid, so we'll use `unwrap()`.
let sparkle_heart = String::from_utf8(sparkle_heart).unwrap();
assert_eq!("💖", sparkle_heart);
```
UTF-8
-----
`String`s are always valid UTF-8. If you need a non-UTF-8 string, consider [`OsString`](../ffi/struct.osstring "ffi::OsString"). It is similar, but without the UTF-8 constraint. Because UTF-8 is a variable width encoding, `String`s are typically smaller than an array of the same `chars`:
```
use std::mem;
// `s` is ASCII which represents each `char` as one byte
let s = "hello";
assert_eq!(s.len(), 5);
// A `char` array with the same contents would be longer because
// every `char` is four bytes
let s = ['h', 'e', 'l', 'l', 'o'];
let size: usize = s.into_iter().map(|c| mem::size_of_val(&c)).sum();
assert_eq!(size, 20);
// However, for non-ASCII strings, the difference will be smaller
// and sometimes they are the same
let s = "💖💖💖💖💖";
assert_eq!(s.len(), 20);
let s = ['💖', '💖', '💖', '💖', '💖'];
let size: usize = s.into_iter().map(|c| mem::size_of_val(&c)).sum();
assert_eq!(size, 20);
```
This raises interesting questions as to how `s[i]` should work. What should `i` be here? Several options include byte indices and `char` indices but, because of UTF-8 encoding, only byte indices would provide constant time indexing. Getting the `i`th `char`, for example, is available using [`chars`](../primitive.str#method.chars):
```
let s = "hello";
let third_character = s.chars().nth(2);
assert_eq!(third_character, Some('l'));
let s = "💖💖💖💖💖";
let third_character = s.chars().nth(2);
assert_eq!(third_character, Some('💖'));
```
Next, what should `s[i]` return? Because indexing returns a reference to underlying data it could be `&u8`, `&[u8]`, or something else similar. Since we’re only providing one index, `&u8` makes the most sense but that might not be what the user expects and can be explicitly achieved with [`as_bytes()`](../primitive.str#method.as_bytes):
```
// The first byte is 104 - the byte value of `'h'`
let s = "hello";
assert_eq!(s.as_bytes()[0], 104);
// or
assert_eq!(s.as_bytes()[0], b'h');
// The first byte is 240 which isn't obviously useful
let s = "💖💖💖💖💖";
assert_eq!(s.as_bytes()[0], 240);
```
Due to these ambiguities/restrictions, indexing with a `usize` is simply forbidden:
ⓘ
```
let s = "hello";
// The following will not compile!
println!("The first letter of s is {}", s[0]);
```
It is more clear, however, how `&s[i..j]` should work (that is, indexing with a range). It should accept byte indices (to be constant-time) and return a `&str` which is UTF-8 encoded. This is also called “string slicing”. Note this will panic if the byte indices provided are not character boundaries - see [`is_char_boundary`](../primitive.str#method.is_char_boundary) for more details. See the implementations for [`SliceIndex<str>`](../slice/trait.sliceindex) for more details on string slicing. For a non-panicking version of string slicing, see [`get`](../primitive.str#method.get).
The [`bytes`](../primitive.str#method.bytes) and [`chars`](../primitive.str#method.chars) methods return iterators over the bytes and codepoints of the string, respectively. To iterate over codepoints along with byte indices, use [`char_indices`](../primitive.str#method.char_indices).
Deref
-----
`String` implements `[Deref](../ops/trait.deref "ops::Deref")<Target = [str](../primitive.str "str")>`, and so inherits all of [`str`](../primitive.str "str")’s methods. In addition, this means that you can pass a `String` to a function which takes a [`&str`](../primitive.str "&str") by using an ampersand (`&`):
```
fn takes_str(s: &str) { }
let s = String::from("Hello");
takes_str(&s);
```
This will create a [`&str`](../primitive.str "&str") from the `String` and pass it in. This conversion is very inexpensive, and so generally, functions will accept [`&str`](../primitive.str "&str")s as arguments unless they need a `String` for some specific reason.
In certain cases Rust doesn’t have enough information to make this conversion, known as [`Deref`](../ops/trait.deref "ops::Deref") coercion. In the following example a string slice [`&'a str`](../primitive.str "&str") implements the trait `TraitExample`, and the function `example_func` takes anything that implements the trait. In this case Rust would need to make two implicit conversions, which Rust doesn’t have the means to do. For that reason, the following example will not compile.
ⓘ
```
trait TraitExample {}
impl<'a> TraitExample for &'a str {}
fn example_func<A: TraitExample>(example_arg: A) {}
let example_string = String::from("example_string");
example_func(&example_string);
```
There are two options that would work instead. The first would be to change the line `example_func(&example_string);` to `example_func(example_string.as_str());`, using the method [`as_str()`](struct.string#method.as_str) to explicitly extract the string slice containing the string. The second way changes `example_func(&example_string);` to `example_func(&*example_string);`. In this case we are dereferencing a `String` to a [`str`](../primitive.str "str"), then referencing the [`str`](../primitive.str "str") back to [`&str`](../primitive.str "&str"). The second way is more idiomatic, however both work to do the conversion explicitly rather than relying on the implicit conversion.
Representation
--------------
A `String` is made up of three components: a pointer to some bytes, a length, and a capacity. The pointer points to an internal buffer `String` uses to store its data. The length is the number of bytes currently stored in the buffer, and the capacity is the size of the buffer in bytes. As such, the length will always be less than or equal to the capacity.
This buffer is always stored on the heap.
You can look at these with the [`as_ptr`](../primitive.str#method.as_ptr), [`len`](struct.string#method.len), and [`capacity`](struct.string#method.capacity) methods:
```
use std::mem;
let story = String::from("Once upon a time...");
// Prevent automatically dropping the String's data
let mut story = mem::ManuallyDrop::new(story);
let ptr = story.as_mut_ptr();
let len = story.len();
let capacity = story.capacity();
// story has nineteen bytes
assert_eq!(19, len);
// We can re-build a String out of ptr, len, and capacity. This is all
// unsafe because we are responsible for making sure the components are
// valid:
let s = unsafe { String::from_raw_parts(ptr, len, capacity) } ;
assert_eq!(String::from("Once upon a time..."), s);
```
If a `String` has enough capacity, adding elements to it will not re-allocate. For example, consider this program:
```
let mut s = String::new();
println!("{}", s.capacity());
for _ in 0..5 {
s.push_str("hello");
println!("{}", s.capacity());
}
```
This will output the following:
```
0
8
16
16
32
32
```
At first, we have no memory allocated at all, but as we append to the string, it increases its capacity appropriately. If we instead use the [`with_capacity`](struct.string#method.with_capacity) method to allocate the correct capacity initially:
```
let mut s = String::with_capacity(25);
println!("{}", s.capacity());
for _ in 0..5 {
s.push_str("hello");
println!("{}", s.capacity());
}
```
We end up with a different output:
```
25
25
25
25
25
25
```
Here, there’s no need to allocate more memory inside the loop.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#433)### impl String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#456)const: 1.39.0 · #### pub const fn new() -> String
Creates a new empty `String`.
Given that the `String` is empty, this will not allocate any initial buffer. While that means that this initial operation is very inexpensive, it may cause excessive allocation later when you add data. If you have an idea of how much data the `String` will hold, consider the [`with_capacity`](struct.string#method.with_capacity) method to prevent excessive re-allocation.
##### Examples
Basic usage:
```
let s = String::new();
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#501)#### pub fn with\_capacity(capacity: usize) -> String
Creates a new empty `String` with at least the specified capacity.
`String`s have an internal buffer to hold their data. The capacity is the length of that buffer, and can be queried with the [`capacity`](struct.string#method.capacity) method. This method creates an empty `String`, but one with an initial buffer that can hold at least `capacity` bytes. This is useful when you may be appending a bunch of data to the `String`, reducing the number of reallocations it needs to do.
If the given capacity is `0`, no allocation will occur, and this method is identical to the [`new`](struct.string#method.new) method.
##### Examples
Basic usage:
```
let mut s = String::with_capacity(10);
// The String contains no chars, even though it has capacity for more
assert_eq!(s.len(), 0);
// These are all done without reallocating...
let cap = s.capacity();
for _ in 0..10 {
s.push('a');
}
assert_eq!(s.capacity(), cap);
// ...but this may make the string reallocate
s.push('a');
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#573)#### pub fn from\_utf8(vec: Vec<u8, Global>) -> Result<String, FromUtf8Error>
Converts a vector of bytes to a `String`.
A string ([`String`](struct.string "String")) is made of bytes ([`u8`](../primitive.u8 "u8")), and a vector of bytes ([`Vec<u8>`](../vec/struct.vec "Vec")) is made of bytes, so this function converts between the two. Not all byte slices are valid `String`s, however: `String` requires that it is valid UTF-8. `from_utf8()` checks to ensure that the bytes are valid UTF-8, and then does the conversion.
If you are sure that the byte slice is valid UTF-8, and you don’t want to incur the overhead of the validity check, there is an unsafe version of this function, [`from_utf8_unchecked`](struct.string#method.from_utf8_unchecked), which has the same behavior but skips the check.
This method will take care to not copy the vector, for efficiency’s sake.
If you need a [`&str`](../primitive.str "&str") instead of a `String`, consider [`str::from_utf8`](../str/fn.from_utf8 "str::from_utf8").
The inverse of this method is [`into_bytes`](struct.string#method.into_bytes).
##### Errors
Returns [`Err`](../result/enum.result#variant.Err "Err") if the slice is not UTF-8 with a description as to why the provided bytes are not UTF-8. The vector you moved in is also included.
##### Examples
Basic usage:
```
// some bytes, in a vector
let sparkle_heart = vec![240, 159, 146, 150];
// We know these bytes are valid, so we'll use `unwrap()`.
let sparkle_heart = String::from_utf8(sparkle_heart).unwrap();
assert_eq!("💖", sparkle_heart);
```
Incorrect bytes:
```
// some invalid bytes, in a vector
let sparkle_heart = vec![0, 159, 146, 150];
assert!(String::from_utf8(sparkle_heart).is_err());
```
See the docs for [`FromUtf8Error`](struct.fromutf8error "FromUtf8Error") for more details on what you can do with this error.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#632)#### pub fn from\_utf8\_lossy(v: &[u8]) -> Cow<'\_, str>
Converts a slice of bytes to a string, including invalid characters.
Strings are made of bytes ([`u8`](../primitive.u8 "u8")), and a slice of bytes ([`&[u8]`](../primitive.slice)) is made of bytes, so this function converts between the two. Not all byte slices are valid strings, however: strings are required to be valid UTF-8. During this conversion, `from_utf8_lossy()` will replace any invalid UTF-8 sequences with [`U+FFFD REPLACEMENT CHARACTER`](../char/constant.replacement_character), which looks like this: �
If you are sure that the byte slice is valid UTF-8, and you don’t want to incur the overhead of the conversion, there is an unsafe version of this function, [`from_utf8_unchecked`](struct.string#method.from_utf8_unchecked), which has the same behavior but skips the checks.
This function returns a [`Cow<'a, str>`](../borrow/enum.cow "borrow::Cow"). If our byte slice is invalid UTF-8, then we need to insert the replacement characters, which will change the size of the string, and hence, require a `String`. But if it’s already valid UTF-8, we don’t need a new allocation. This return type allows us to handle both cases.
##### Examples
Basic usage:
```
// some bytes, in a vector
let sparkle_heart = vec![240, 159, 146, 150];
let sparkle_heart = String::from_utf8_lossy(&sparkle_heart);
assert_eq!("💖", sparkle_heart);
```
Incorrect bytes:
```
// some invalid bytes
let input = b"Hello \xF0\x90\x80World";
let output = String::from_utf8_lossy(input);
assert_eq!("Hello �World", output);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#683)#### pub fn from\_utf16(v: &[u16]) -> Result<String, FromUtf16Error>
Decode a UTF-16–encoded vector `v` into a `String`, returning [`Err`](../result/enum.result#variant.Err "Err") if `v` contains any invalid data.
##### Examples
Basic usage:
```
// 𝄞music
let v = &[0xD834, 0xDD1E, 0x006d, 0x0075,
0x0073, 0x0069, 0x0063];
assert_eq!(String::from("𝄞music"),
String::from_utf16(v).unwrap());
// 𝄞mu<invalid>ic
let v = &[0xD834, 0xDD1E, 0x006d, 0x0075,
0xD800, 0x0069, 0x0063];
assert!(String::from_utf16(v).is_err());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#725)#### pub fn from\_utf16\_lossy(v: &[u16]) -> String
Decode a UTF-16–encoded slice `v` into a `String`, replacing invalid data with [the replacement character (`U+FFFD`)](../char/constant.replacement_character).
Unlike [`from_utf8_lossy`](struct.string#method.from_utf8_lossy) which returns a [`Cow<'a, str>`](../borrow/enum.cow "borrow::Cow"), `from_utf16_lossy` returns a `String` since the UTF-16 to UTF-8 conversion requires a memory allocation.
##### Examples
Basic usage:
```
// 𝄞mus<invalid>ic<invalid>
let v = &[0xD834, 0xDD1E, 0x006d, 0x0075,
0x0073, 0xDD1E, 0x0069, 0x0063,
0xD834];
assert_eq!(String::from("𝄞mus\u{FFFD}ic\u{FFFD}"),
String::from_utf16_lossy(v));
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#757)#### pub fn into\_raw\_parts(self) -> (\*mut u8, usize, usize)
🔬This is a nightly-only experimental API. (`vec_into_raw_parts` [#65816](https://github.com/rust-lang/rust/issues/65816))
Decomposes a `String` into its raw components.
Returns the raw pointer to the underlying data, the length of the string (in bytes), and the allocated capacity of the data (in bytes). These are the same arguments in the same order as the arguments to [`from_raw_parts`](struct.string#method.from_raw_parts).
After calling this function, the caller is responsible for the memory previously managed by the `String`. The only way to do this is to convert the raw pointer, length, and capacity back into a `String` with the [`from_raw_parts`](struct.string#method.from_raw_parts) function, allowing the destructor to perform the cleanup.
##### Examples
```
#![feature(vec_into_raw_parts)]
let s = String::from("hello");
let (ptr, len, cap) = s.into_raw_parts();
let rebuilt = unsafe { String::from_raw_parts(ptr, len, cap) };
assert_eq!(rebuilt, "hello");
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#811)#### pub unsafe fn from\_raw\_parts( buf: \*mut u8, length: usize, capacity: usize) -> String
Creates a new `String` from a length, capacity, and pointer.
##### Safety
This is highly unsafe, due to the number of invariants that aren’t checked:
* The memory at `buf` needs to have been previously allocated by the same allocator the standard library uses, with a required alignment of exactly 1.
* `length` needs to be less than or equal to `capacity`.
* `capacity` needs to be the correct value.
* The first `length` bytes at `buf` need to be valid UTF-8.
Violating these may cause problems like corrupting the allocator’s internal data structures. For example, it is normally **not** safe to build a `String` from a pointer to a C `char` array containing UTF-8 *unless* you are certain that array was originally allocated by the Rust standard library’s allocator.
The ownership of `buf` is effectively transferred to the `String` which may then deallocate, reallocate or change the contents of memory pointed to by the pointer at will. Ensure that nothing else uses the pointer after calling this function.
##### Examples
Basic usage:
```
use std::mem;
unsafe {
let s = String::from("hello");
// Prevent automatically dropping the String's data
let mut s = mem::ManuallyDrop::new(s);
let ptr = s.as_mut_ptr();
let len = s.len();
let capacity = s.capacity();
let s = String::from_raw_parts(ptr, len, capacity);
assert_eq!(String::from("hello"), s);
}
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#846)#### pub unsafe fn from\_utf8\_unchecked(bytes: Vec<u8, Global>) -> String
Converts a vector of bytes to a `String` without checking that the string contains valid UTF-8.
See the safe version, [`from_utf8`](struct.string#method.from_utf8), for more details.
##### Safety
This function is unsafe because it does not check that the bytes passed to it are valid UTF-8. If this constraint is violated, it may cause memory unsafety issues with future users of the `String`, as the rest of the standard library assumes that `String`s are valid UTF-8.
##### Examples
Basic usage:
```
// some bytes, in a vector
let sparkle_heart = vec![240, 159, 146, 150];
let sparkle_heart = unsafe {
String::from_utf8_unchecked(sparkle_heart)
};
assert_eq!("💖", sparkle_heart);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#867)#### pub fn into\_bytes(self) -> Vec<u8, Global>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Converts a `String` into a byte vector.
This consumes the `String`, so we do not need to copy its contents.
##### Examples
Basic usage:
```
let s = String::from("hello");
let bytes = s.into_bytes();
assert_eq!(&[104, 101, 108, 108, 111][..], &bytes[..]);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#885)1.7.0 · #### pub fn as\_str(&self) -> &str
Extracts a string slice containing the entire `String`.
##### Examples
Basic usage:
```
let s = String::from("foo");
assert_eq!("foo", s.as_str());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#906)1.7.0 · #### pub fn as\_mut\_str(&mut self) -> &mut str
Converts a `String` into a mutable string slice.
##### Examples
Basic usage:
```
let mut s = String::from("foobar");
let s_mut_str = s.as_mut_str();
s_mut_str.make_ascii_uppercase();
assert_eq!("FOOBAR", s_mut_str);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#926)#### pub fn push\_str(&mut self, string: &str)
Appends a given string slice onto the end of this `String`.
##### Examples
Basic usage:
```
let mut s = String::from("foo");
s.push_str("bar");
assert_eq!("foobar", s);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#954-956)#### pub fn extend\_from\_within<R>(&mut self, src: R)where R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<[usize](../primitive.usize)>,
🔬This is a nightly-only experimental API. (`string_extend_from_within`)
Copies elements from `src` range to the end of the string.
###### [Panics](#panics)
Panics if the starting point or end point do not lie on a [`char`](../primitive.char "char") boundary, or if they’re out of bounds.
###### [Examples](#examples-14)
```
#![feature(string_extend_from_within)]
let mut string = String::from("abcde");
string.extend_from_within(2..);
assert_eq!(string, "abcdecde");
string.extend_from_within(..2);
assert_eq!(string, "abcdecdeab");
string.extend_from_within(4..8);
assert_eq!(string, "abcdecdeabecde");
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#980)#### pub fn capacity(&self) -> usize
Returns this `String`’s capacity, in bytes.
##### Examples
Basic usage:
```
let s = String::with_capacity(10);
assert!(s.capacity() >= 10);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1027)#### pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least `additional` bytes more than the current length. The allocator may reserve more space to speculatively avoid frequent allocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional`. Does nothing if capacity is already sufficient.
##### Panics
Panics if the new capacity overflows [`usize`](../primitive.usize "usize").
##### Examples
Basic usage:
```
let mut s = String::new();
s.reserve(10);
assert!(s.capacity() >= 10);
```
This might not actually increase the capacity:
```
let mut s = String::with_capacity(10);
s.push('a');
s.push('b');
// s now has a length of 2 and a capacity of at least 10
let capacity = s.capacity();
assert_eq!(2, s.len());
assert!(capacity >= 10);
// Since we already have at least an extra 8 capacity, calling this...
s.reserve(8);
// ... doesn't actually increase.
assert_eq!(capacity, s.capacity());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1077)#### pub fn reserve\_exact(&mut self, additional: usize)
Reserves the minimum capacity for at least `additional` bytes more than the current length. Unlike [`reserve`](struct.string#method.reserve), this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling `reserve_exact`, capacity will be greater than or equal to `self.len() + additional`. Does nothing if the capacity is already sufficient.
##### Panics
Panics if the new capacity overflows [`usize`](../primitive.usize "usize").
##### Examples
Basic usage:
```
let mut s = String::new();
s.reserve_exact(10);
assert!(s.capacity() >= 10);
```
This might not actually increase the capacity:
```
let mut s = String::with_capacity(10);
s.push('a');
s.push('b');
// s now has a length of 2 and a capacity of at least 10
let capacity = s.capacity();
assert_eq!(2, s.len());
assert!(capacity >= 10);
// Since we already have at least an extra 8 capacity, calling this...
s.reserve_exact(8);
// ... doesn't actually increase.
assert_eq!(capacity, s.capacity());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1112)1.57.0 · #### pub fn try\_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least `additional` bytes more than the current length. The allocator may reserve more space to speculatively avoid frequent allocations. After calling `try_reserve`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if capacity is already sufficient. This method preserves the contents even if an error occurs.
##### Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::TryReserveError;
fn process_data(data: &str) -> Result<String, TryReserveError> {
let mut output = String::new();
// Pre-reserve the memory, exiting if we can't
output.try_reserve(data.len())?;
// Now we know this can't OOM in the middle of our complex work
output.push_str(data);
Ok(output)
}
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1153)1.57.0 · #### pub fn try\_reserve\_exact( &mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve the minimum capacity for at least `additional` bytes more than the current length. Unlike [`try_reserve`](struct.string#method.try_reserve), this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling `try_reserve_exact`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer [`try_reserve`](struct.string#method.try_reserve) if future insertions are expected.
##### Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::TryReserveError;
fn process_data(data: &str) -> Result<String, TryReserveError> {
let mut output = String::new();
// Pre-reserve the memory, exiting if we can't
output.try_reserve_exact(data.len())?;
// Now we know this can't OOM in the middle of our complex work
output.push_str(data);
Ok(output)
}
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1175)#### pub fn shrink\_to\_fit(&mut self)
Shrinks the capacity of this `String` to match its length.
##### Examples
Basic usage:
```
let mut s = String::from("foo");
s.reserve(100);
assert!(s.capacity() >= 100);
s.shrink_to_fit();
assert_eq!(3, s.capacity());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1202)1.56.0 · #### pub fn shrink\_to(&mut self, min\_capacity: usize)
Shrinks the capacity of this `String` with a lower bound.
The capacity will remain at least as large as both the length and the supplied value.
If the current capacity is less than the lower limit, this is a no-op.
##### Examples
```
let mut s = String::from("foo");
s.reserve(100);
assert!(s.capacity() >= 100);
s.shrink_to(10);
assert!(s.capacity() >= 10);
s.shrink_to(0);
assert!(s.capacity() >= 3);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1224)#### pub fn push(&mut self, ch: char)
Appends the given [`char`](../primitive.char "char") to the end of this `String`.
##### Examples
Basic usage:
```
let mut s = String::from("abc");
s.push('1');
s.push('2');
s.push('3');
assert_eq!("abc123", s);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1249)#### pub fn as\_bytes(&self) -> &[u8]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Returns a byte slice of this `String`’s contents.
The inverse of this method is [`from_utf8`](struct.string#method.from_utf8).
##### Examples
Basic usage:
```
let s = String::from("hello");
assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1278)#### pub fn truncate(&mut self, new\_len: usize)
Shortens this `String` to the specified length.
If `new_len` is greater than the string’s current length, this has no effect.
Note that this method has no effect on the allocated capacity of the string
##### Panics
Panics if `new_len` does not lie on a [`char`](../primitive.char "char") boundary.
##### Examples
Basic usage:
```
let mut s = String::from("hello");
s.truncate(2);
assert_eq!("he", s);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1304)#### pub fn pop(&mut self) -> Option<char>
Removes the last character from the string buffer and returns it.
Returns [`None`](../option/enum.option#variant.None "None") if this `String` is empty.
##### Examples
Basic usage:
```
let mut s = String::from("foo");
assert_eq!(s.pop(), Some('o'));
assert_eq!(s.pop(), Some('o'));
assert_eq!(s.pop(), Some('f'));
assert_eq!(s.pop(), None);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1336)#### pub fn remove(&mut self, idx: usize) -> char
Removes a [`char`](../primitive.char "char") from this `String` at a byte position and returns it.
This is an *O*(*n*) operation, as it requires copying every element in the buffer.
##### Panics
Panics if `idx` is larger than or equal to the `String`’s length, or if it does not lie on a [`char`](../primitive.char "char") boundary.
##### Examples
Basic usage:
```
let mut s = String::from("foo");
assert_eq!(s.remove(0), 'f');
assert_eq!(s.remove(1), 'o');
assert_eq!(s.remove(0), 'o');
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1373-1375)#### pub fn remove\_matches<P>(&'a mut self, pat: P)where P: for<'x> [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'x>,
🔬This is a nightly-only experimental API. (`string_remove_matches` [#72826](https://github.com/rust-lang/rust/issues/72826))
Remove all matches of pattern `pat` in the `String`.
##### Examples
```
#![feature(string_remove_matches)]
let mut s = String::from("Trees are not green, the sky is not blue.");
s.remove_matches("not ");
assert_eq!("Trees are green, the sky is blue.", s);
```
Matches will be detected and removed iteratively, so in cases where patterns overlap, only the first pattern will be removed:
```
#![feature(string_remove_matches)]
let mut s = String::from("banana");
s.remove_matches("ana");
assert_eq!("bna", s);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1453-1455)1.26.0 · #### pub fn retain<F>(&mut self, f: F)where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([char](../primitive.char)) -> [bool](../primitive.bool),
Retains only the characters specified by the predicate.
In other words, remove all characters `c` such that `f(c)` returns `false`. This method operates in place, visiting each character exactly once in the original order, and preserves the order of the retained characters.
##### Examples
```
let mut s = String::from("f_o_ob_ar");
s.retain(|c| c != '_');
assert_eq!(s, "foobar");
```
Because the elements are visited exactly once in the original order, external state may be used to decide which elements to keep.
```
let mut s = String::from("abcde");
let keep = [false, true, true, false, true];
let mut iter = keep.iter();
s.retain(|_| *iter.next().unwrap());
assert_eq!(s, "bce");
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1532)#### pub fn insert(&mut self, idx: usize, ch: char)
Inserts a character into this `String` at a byte position.
This is an *O*(*n*) operation as it requires copying every element in the buffer.
##### Panics
Panics if `idx` is larger than the `String`’s length, or if it does not lie on a [`char`](../primitive.char "char") boundary.
##### Examples
Basic usage:
```
let mut s = String::with_capacity(3);
s.insert(0, 'f');
s.insert(1, 'o');
s.insert(2, 'o');
assert_eq!("foo", s);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1579)1.16.0 · #### pub fn insert\_str(&mut self, idx: usize, string: &str)
Inserts a string slice into this `String` at a byte position.
This is an *O*(*n*) operation as it requires copying every element in the buffer.
##### Panics
Panics if `idx` is larger than the `String`’s length, or if it does not lie on a [`char`](../primitive.char "char") boundary.
##### Examples
Basic usage:
```
let mut s = String::from("bar");
s.insert_str(0, "foo");
assert_eq!("foobar", s);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1614)#### pub unsafe fn as\_mut\_vec(&mut self) -> &mut Vec<u8, Global>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Returns a mutable reference to the contents of this `String`.
##### Safety
This function is unsafe because the returned `&mut Vec` allows writing bytes which are not valid UTF-8. If this constraint is violated, using the original `String` after dropping the `&mut Vec` may violate memory safety, as the rest of the standard library assumes that `String`s are valid UTF-8.
##### Examples
Basic usage:
```
let mut s = String::from("hello");
unsafe {
let vec = s.as_mut_vec();
assert_eq!(&[104, 101, 108, 108, 111][..], &vec[..]);
vec.reverse();
}
assert_eq!(s, "olleh");
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1637)#### pub fn len(&self) -> usize
Returns the length of this `String`, in bytes, not [`char`](../primitive.char "char")s or graphemes. In other words, it might not be what a human considers the length of the string.
##### Examples
Basic usage:
```
let a = String::from("foo");
assert_eq!(a.len(), 3);
let fancy_f = String::from("ƒoo");
assert_eq!(fancy_f.len(), 4);
assert_eq!(fancy_f.chars().count(), 3);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1657)#### pub fn is\_empty(&self) -> bool
Returns `true` if this `String` has a length of zero, and `false` otherwise.
##### Examples
Basic usage:
```
let mut v = String::new();
assert!(v.is_empty());
v.push('a');
assert!(!v.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1688)1.16.0 · #### pub fn split\_off(&mut self, at: usize) -> String
Splits the string into two at the given byte index.
Returns a newly allocated `String`. `self` contains bytes `[0, at)`, and the returned `String` contains bytes `[at, len)`. `at` must be on the boundary of a UTF-8 code point.
Note that the capacity of `self` does not change.
##### Panics
Panics if `at` is not on a `UTF-8` code point boundary, or if it is beyond the last code point of the string.
##### Examples
```
let mut hello = String::from("Hello, World!");
let world = hello.split_off(7);
assert_eq!(hello, "Hello, ");
assert_eq!(world, "World!");
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1714)#### pub fn clear(&mut self)
Truncates this `String`, removing all contents.
While this means the `String` will have a length of zero, it does not touch its capacity.
##### Examples
Basic usage:
```
let mut s = String::from("foo");
s.clear();
assert!(s.is_empty());
assert_eq!(0, s.len());
assert_eq!(3, s.capacity());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1754-1756)1.6.0 · #### pub fn drain<R>(&mut self, range: R) -> Drain<'\_>where R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<[usize](../primitive.usize)>,
Notable traits for [Drain](struct.drain "struct std::string::Drain")<'\_>
```
impl Iterator for Drain<'_>
type Item = char;
```
Removes the specified range from the string in bulk, returning all removed characters as an iterator.
The returned iterator keeps a mutable borrow on the string to optimize its implementation.
##### Panics
Panics if the starting point or end point do not lie on a [`char`](../primitive.char "char") boundary, or if they’re out of bounds.
##### Leaking
If the returned iterator goes out of scope without being dropped (due to [`core::mem::forget`](../mem/fn.forget "core::mem::forget"), for example), the string may still contain a copy of any drained characters, or may have lost characters arbitrarily, including characters outside the range.
##### Examples
Basic usage:
```
let mut s = String::from("α is alpha, β is beta");
let beta_offset = s.find('β').unwrap_or(s.len());
// Remove the range up until the β from the string
let t: String = s.drain(..beta_offset).collect();
assert_eq!(t, "α is alpha, ");
assert_eq!(s, "β is beta");
// A full range clears the string, like `clear()` does
s.drain(..);
assert_eq!(s, "");
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1800-1802)1.27.0 · #### pub fn replace\_range<R>(&mut self, range: R, replace\_with: &str)where R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<[usize](../primitive.usize)>,
Removes the specified range in the string, and replaces it with the given string. The given string doesn’t need to be the same length as the range.
##### Panics
Panics if the starting point or end point do not lie on a [`char`](../primitive.char "char") boundary, or if they’re out of bounds.
##### Examples
Basic usage:
```
let mut s = String::from("α is alpha, β is beta");
let beta_offset = s.find('β').unwrap_or(s.len());
// Replace the range up until the β from the string
s.replace_range(..beta_offset, "Α is capital alpha; ");
assert_eq!(s, "Α is capital alpha; β is beta");
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1849)1.4.0 · #### pub fn into\_boxed\_str(self) -> Box<str, Global>
Notable traits for [Box](../boxed/struct.box "struct std::boxed::Box")<I, A>
```
impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator,
type Item = <I as Iterator>::Item;
impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static,
type Output = <F as Future>::Output;
impl<R: Read + ?Sized> Read for Box<R>
impl<W: Write + ?Sized> Write for Box<W>
```
Converts this `String` into a `[Box](../boxed/struct.box "Box")<[str](../primitive.str "str")>`.
This will drop any excess capacity.
##### Examples
Basic usage:
```
let s = String::from("hello");
let b = s.into_boxed_str();
```
Methods from [Deref](../ops/trait.deref "trait std::ops::Deref")<Target = [str](../primitive.str)>
--------------------------------------------------------------------------------------------------
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#159)#### pub fn len(&self) -> usize
Returns the length of `self`.
This length is in bytes, not [`char`](../primitive.char)s or graphemes. In other words, it might not be what a human considers the length of the string.
##### Examples
Basic usage:
```
let len = "foo".len();
assert_eq!(3, len);
assert_eq!("ƒoo".len(), 4); // fancy f!
assert_eq!("ƒoo".chars().count(), 3);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#180)#### pub fn is\_empty(&self) -> bool
Returns `true` if `self` has a length of zero bytes.
##### Examples
Basic usage:
```
let s = "";
assert!(s.is_empty());
let s = "not empty";
assert!(!s.is_empty());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#211)1.9.0 · #### pub fn is\_char\_boundary(&self, index: usize) -> bool
Checks that `index`-th byte is the first byte in a UTF-8 code point sequence or the end of the string.
The start and end of the string (when `index == self.len()`) are considered to be boundaries.
Returns `false` if `index` is greater than `self.len()`.
##### Examples
```
let s = "Löwe 老虎 Léopard";
assert!(s.is_char_boundary(0));
// start of `老`
assert!(s.is_char_boundary(6));
assert!(s.is_char_boundary(s.len()));
// second byte of `ö`
assert!(!s.is_char_boundary(2));
// third byte of `老`
assert!(!s.is_char_boundary(8));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#258)#### pub fn floor\_char\_boundary(&self, index: usize) -> usize
🔬This is a nightly-only experimental API. (`round_char_boundary` [#93743](https://github.com/rust-lang/rust/issues/93743))
Finds the closest `x` not exceeding `index` where `is_char_boundary(x)` is `true`.
This method can help you truncate a string so that it’s still valid UTF-8, but doesn’t exceed a given number of bytes. Note that this is done purely at the character level and can still visually split graphemes, even though the underlying characters aren’t split. For example, the emoji 🧑🔬 (scientist) could be split so that the string only includes 🧑 (person) instead.
##### Examples
```
#![feature(round_char_boundary)]
let s = "❤️🧡💛💚💙💜";
assert_eq!(s.len(), 26);
assert!(!s.is_char_boundary(13));
let closest = s.floor_char_boundary(13);
assert_eq!(closest, 10);
assert_eq!(&s[..closest], "❤️🧡");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#297)#### pub fn ceil\_char\_boundary(&self, index: usize) -> usize
🔬This is a nightly-only experimental API. (`round_char_boundary` [#93743](https://github.com/rust-lang/rust/issues/93743))
Finds the closest `x` not below `index` where `is_char_boundary(x)` is `true`.
This method is the natural complement to [`floor_char_boundary`](../primitive.str#method.floor_char_boundary). See that method for more details.
##### Panics
Panics if `index > self.len()`.
##### Examples
```
#![feature(round_char_boundary)]
let s = "❤️🧡💛💚💙💜";
assert_eq!(s.len(), 26);
assert!(!s.is_char_boundary(13));
let closest = s.ceil_char_boundary(13);
assert_eq!(closest, 14);
assert_eq!(&s[..closest], "❤️🧡💛");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#325)#### pub fn as\_bytes(&self) -> &[u8]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Converts a string slice to a byte slice. To convert the byte slice back into a string slice, use the [`from_utf8`](../str/fn.from_utf8 "from_utf8") function.
##### Examples
Basic usage:
```
let bytes = "bors".as_bytes();
assert_eq!(b"bors", bytes);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#369)1.20.0 · #### pub unsafe fn as\_bytes\_mut(&mut self) -> &mut [u8]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Converts a mutable string slice to a mutable byte slice.
##### Safety
The caller must ensure that the content of the slice is valid UTF-8 before the borrow ends and the underlying `str` is used.
Use of a `str` whose contents are not valid UTF-8 is undefined behavior.
##### Examples
Basic usage:
```
let mut s = String::from("Hello");
let bytes = unsafe { s.as_bytes_mut() };
assert_eq!(b"Hello", bytes);
```
Mutability:
```
let mut s = String::from("🗻∈🌏");
unsafe {
let bytes = s.as_bytes_mut();
bytes[0] = 0xF0;
bytes[1] = 0x9F;
bytes[2] = 0x8D;
bytes[3] = 0x94;
}
assert_eq!("🍔∈🌏", s);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#400)#### pub fn as\_ptr(&self) -> \*const u8
Converts a string slice to a raw pointer.
As string slices are a slice of bytes, the raw pointer points to a [`u8`](../primitive.u8 "u8"). This pointer will be pointing to the first byte of the string slice.
The caller must ensure that the returned pointer is never written to. If you need to mutate the contents of the string slice, use [`as_mut_ptr`](../primitive.str#method.as_mut_ptr).
##### Examples
Basic usage:
```
let s = "Hello";
let ptr = s.as_ptr();
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#415)1.36.0 · #### pub fn as\_mut\_ptr(&mut self) -> \*mut u8
Converts a mutable string slice to a raw pointer.
As string slices are a slice of bytes, the raw pointer points to a [`u8`](../primitive.u8 "u8"). This pointer will be pointing to the first byte of the string slice.
It is your responsibility to make sure that the string slice only gets modified in a way that it remains valid UTF-8.
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#441)1.20.0 · #### pub fn get<I>(&self, i: I) -> Option<&<I as SliceIndex<str>>::Output>where I: [SliceIndex](../slice/trait.sliceindex "trait std::slice::SliceIndex")<[str](../primitive.str)>,
Returns a subslice of `str`.
This is the non-panicking alternative to indexing the `str`. Returns [`None`](../option/enum.option#variant.None "None") whenever equivalent indexing operation would panic.
##### Examples
```
let v = String::from("🗻∈🌏");
assert_eq!(Some("🗻"), v.get(0..4));
// indices not on UTF-8 sequence boundaries
assert!(v.get(1..).is_none());
assert!(v.get(..8).is_none());
// out of bounds
assert!(v.get(..42).is_none());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#474)1.20.0 · #### pub fn get\_mut<I>(&mut self, i: I) -> Option<&mut <I as SliceIndex<str>>::Output>where I: [SliceIndex](../slice/trait.sliceindex "trait std::slice::SliceIndex")<[str](../primitive.str)>,
Returns a mutable subslice of `str`.
This is the non-panicking alternative to indexing the `str`. Returns [`None`](../option/enum.option#variant.None "None") whenever equivalent indexing operation would panic.
##### Examples
```
let mut v = String::from("hello");
// correct length
assert!(v.get_mut(0..5).is_some());
// out of bounds
assert!(v.get_mut(..42).is_none());
assert_eq!(Some("he"), v.get_mut(0..2).map(|v| &*v));
assert_eq!("hello", v);
{
let s = v.get_mut(0..2);
let s = s.map(|s| {
s.make_ascii_uppercase();
&*s
});
assert_eq!(Some("HE"), s);
}
assert_eq!("HEllo", v);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#507)1.20.0 · #### pub unsafe fn get\_unchecked<I>(&self, i: I) -> &<I as SliceIndex<str>>::Outputwhere I: [SliceIndex](../slice/trait.sliceindex "trait std::slice::SliceIndex")<[str](../primitive.str)>,
Returns an unchecked subslice of `str`.
This is the unchecked alternative to indexing the `str`.
##### Safety
Callers of this function are responsible that these preconditions are satisfied:
* The starting index must not exceed the ending index;
* Indexes must be within bounds of the original slice;
* Indexes must lie on UTF-8 sequence boundaries.
Failing that, the returned string slice may reference invalid memory or violate the invariants communicated by the `str` type.
##### Examples
```
let v = "🗻∈🌏";
unsafe {
assert_eq!("🗻", v.get_unchecked(0..4));
assert_eq!("∈", v.get_unchecked(4..7));
assert_eq!("🌏", v.get_unchecked(7..11));
}
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#543-546)1.20.0 · #### pub unsafe fn get\_unchecked\_mut<I>( &mut self, i: I) -> &mut <I as SliceIndex<str>>::Outputwhere I: [SliceIndex](../slice/trait.sliceindex "trait std::slice::SliceIndex")<[str](../primitive.str)>,
Returns a mutable, unchecked subslice of `str`.
This is the unchecked alternative to indexing the `str`.
##### Safety
Callers of this function are responsible that these preconditions are satisfied:
* The starting index must not exceed the ending index;
* Indexes must be within bounds of the original slice;
* Indexes must lie on UTF-8 sequence boundaries.
Failing that, the returned string slice may reference invalid memory or violate the invariants communicated by the `str` type.
##### Examples
```
let mut v = String::from("🗻∈🌏");
unsafe {
assert_eq!("🗻", v.get_unchecked_mut(0..4));
assert_eq!("∈", v.get_unchecked_mut(4..7));
assert_eq!("🌏", v.get_unchecked_mut(7..11));
}
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#599)#### pub unsafe fn slice\_unchecked(&self, begin: usize, end: usize) -> &str
👎Deprecated since 1.29.0: use `get_unchecked(begin..end)` instead
Creates a string slice from another string slice, bypassing safety checks.
This is generally not recommended, use with caution! For a safe alternative see [`str`](../primitive.str "str") and [`Index`](../ops/trait.index).
This new slice goes from `begin` to `end`, including `begin` but excluding `end`.
To get a mutable string slice instead, see the [`slice_mut_unchecked`](../primitive.str#method.slice_mut_unchecked) method.
##### Safety
Callers of this function are responsible that three preconditions are satisfied:
* `begin` must not exceed `end`.
* `begin` and `end` must be byte positions within the string slice.
* `begin` and `end` must lie on UTF-8 sequence boundaries.
##### Examples
Basic usage:
```
let s = "Löwe 老虎 Léopard";
unsafe {
assert_eq!("Löwe 老虎 Léopard", s.slice_unchecked(0, 21));
}
let s = "Hello, world!";
unsafe {
assert_eq!("world", s.slice_unchecked(7, 12));
}
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#632)1.5.0 · #### pub unsafe fn slice\_mut\_unchecked(&mut self, begin: usize, end: usize) -> &mut str
👎Deprecated since 1.29.0: use `get_unchecked_mut(begin..end)` instead
Creates a string slice from another string slice, bypassing safety checks. This is generally not recommended, use with caution! For a safe alternative see [`str`](../primitive.str "str") and [`IndexMut`](../ops/trait.indexmut).
This new slice goes from `begin` to `end`, including `begin` but excluding `end`.
To get an immutable string slice instead, see the [`slice_unchecked`](../primitive.str#method.slice_unchecked) method.
##### Safety
Callers of this function are responsible that three preconditions are satisfied:
* `begin` must not exceed `end`.
* `begin` and `end` must be byte positions within the string slice.
* `begin` and `end` must lie on UTF-8 sequence boundaries.
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#672)1.4.0 · #### pub fn split\_at(&self, mid: usize) -> (&str, &str)
Divide one string slice into two at an index.
The argument, `mid`, should be a byte offset from the start of the string. It must also be on the boundary of a UTF-8 code point.
The two slices returned go from the start of the string slice to `mid`, and from `mid` to the end of the string slice.
To get mutable string slices instead, see the [`split_at_mut`](../primitive.str#method.split_at_mut) method.
##### Panics
Panics if `mid` is not on a UTF-8 code point boundary, or if it is past the end of the last code point of the string slice.
##### Examples
Basic usage:
```
let s = "Per Martin-Löf";
let (first, last) = s.split_at(3);
assert_eq!("Per", first);
assert_eq!(" Martin-Löf", last);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#716)1.4.0 · #### pub fn split\_at\_mut(&mut self, mid: usize) -> (&mut str, &mut str)
Divide one mutable string slice into two at an index.
The argument, `mid`, should be a byte offset from the start of the string. It must also be on the boundary of a UTF-8 code point.
The two slices returned go from the start of the string slice to `mid`, and from `mid` to the end of the string slice.
To get immutable string slices instead, see the [`split_at`](../primitive.str#method.split_at) method.
##### Panics
Panics if `mid` is not on a UTF-8 code point boundary, or if it is past the end of the last code point of the string slice.
##### Examples
Basic usage:
```
let mut s = "Per Martin-Löf".to_string();
{
let (first, last) = s.split_at_mut(3);
first.make_ascii_uppercase();
assert_eq!("PER", first);
assert_eq!(" Martin-Löf", last);
}
assert_eq!("PER Martin-Löf", s);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#782)#### pub fn chars(&self) -> Chars<'\_>
Notable traits for [Chars](../str/struct.chars "struct std::str::Chars")<'a>
```
impl<'a> Iterator for Chars<'a>
type Item = char;
```
Returns an iterator over the [`char`](../primitive.char)s of a string slice.
As a string slice consists of valid UTF-8, we can iterate through a string slice by [`char`](../primitive.char). This method returns such an iterator.
It’s important to remember that [`char`](../primitive.char) represents a Unicode Scalar Value, and might not match your idea of what a ‘character’ is. Iteration over grapheme clusters may be what you actually want. This functionality is not provided by Rust’s standard library, check crates.io instead.
##### Examples
Basic usage:
```
let word = "goodbye";
let count = word.chars().count();
assert_eq!(7, count);
let mut chars = word.chars();
assert_eq!(Some('g'), chars.next());
assert_eq!(Some('o'), chars.next());
assert_eq!(Some('o'), chars.next());
assert_eq!(Some('d'), chars.next());
assert_eq!(Some('b'), chars.next());
assert_eq!(Some('y'), chars.next());
assert_eq!(Some('e'), chars.next());
assert_eq!(None, chars.next());
```
Remember, [`char`](../primitive.char)s might not match your intuition about characters:
```
let y = "y̆";
let mut chars = y.chars();
assert_eq!(Some('y'), chars.next()); // not 'y̆'
assert_eq!(Some('\u{0306}'), chars.next());
assert_eq!(None, chars.next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#839)#### pub fn char\_indices(&self) -> CharIndices<'\_>
Notable traits for [CharIndices](../str/struct.charindices "struct std::str::CharIndices")<'a>
```
impl<'a> Iterator for CharIndices<'a>
type Item = (usize, char);
```
Returns an iterator over the [`char`](../primitive.char)s of a string slice, and their positions.
As a string slice consists of valid UTF-8, we can iterate through a string slice by [`char`](../primitive.char). This method returns an iterator of both these [`char`](../primitive.char)s, as well as their byte positions.
The iterator yields tuples. The position is first, the [`char`](../primitive.char) is second.
##### Examples
Basic usage:
```
let word = "goodbye";
let count = word.char_indices().count();
assert_eq!(7, count);
let mut char_indices = word.char_indices();
assert_eq!(Some((0, 'g')), char_indices.next());
assert_eq!(Some((1, 'o')), char_indices.next());
assert_eq!(Some((2, 'o')), char_indices.next());
assert_eq!(Some((3, 'd')), char_indices.next());
assert_eq!(Some((4, 'b')), char_indices.next());
assert_eq!(Some((5, 'y')), char_indices.next());
assert_eq!(Some((6, 'e')), char_indices.next());
assert_eq!(None, char_indices.next());
```
Remember, [`char`](../primitive.char)s might not match your intuition about characters:
```
let yes = "y̆es";
let mut char_indices = yes.char_indices();
assert_eq!(Some((0, 'y')), char_indices.next()); // not (0, 'y̆')
assert_eq!(Some((1, '\u{0306}')), char_indices.next());
// note the 3 here - the last character took up two bytes
assert_eq!(Some((3, 'e')), char_indices.next());
assert_eq!(Some((4, 's')), char_indices.next());
assert_eq!(None, char_indices.next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#864)#### pub fn bytes(&self) -> Bytes<'\_>
Notable traits for [Bytes](../str/struct.bytes "struct std::str::Bytes")<'\_>
```
impl Iterator for Bytes<'_>
type Item = u8;
```
An iterator over the bytes of a string slice.
As a string slice consists of a sequence of bytes, we can iterate through a string slice by byte. This method returns such an iterator.
##### Examples
Basic usage:
```
let mut bytes = "bors".bytes();
assert_eq!(Some(b'b'), bytes.next());
assert_eq!(Some(b'o'), bytes.next());
assert_eq!(Some(b'r'), bytes.next());
assert_eq!(Some(b's'), bytes.next());
assert_eq!(None, bytes.next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#910)1.1.0 · #### pub fn split\_whitespace(&self) -> SplitWhitespace<'\_>
Notable traits for [SplitWhitespace](../str/struct.splitwhitespace "struct std::str::SplitWhitespace")<'a>
```
impl<'a> Iterator for SplitWhitespace<'a>
type Item = &'a str;
```
Splits a string slice by whitespace.
The iterator returned will return string slices that are sub-slices of the original string slice, separated by any amount of whitespace.
‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property `White_Space`. If you only want to split on ASCII whitespace instead, use [`split_ascii_whitespace`](../primitive.str#method.split_ascii_whitespace).
##### Examples
Basic usage:
```
let mut iter = "A few words".split_whitespace();
assert_eq!(Some("A"), iter.next());
assert_eq!(Some("few"), iter.next());
assert_eq!(Some("words"), iter.next());
assert_eq!(None, iter.next());
```
All kinds of whitespace are considered:
```
let mut iter = " Mary had\ta\u{2009}little \n\t lamb".split_whitespace();
assert_eq!(Some("Mary"), iter.next());
assert_eq!(Some("had"), iter.next());
assert_eq!(Some("a"), iter.next());
assert_eq!(Some("little"), iter.next());
assert_eq!(Some("lamb"), iter.next());
assert_eq!(None, iter.next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#953)1.34.0 · #### pub fn split\_ascii\_whitespace(&self) -> SplitAsciiWhitespace<'\_>
Notable traits for [SplitAsciiWhitespace](../str/struct.splitasciiwhitespace "struct std::str::SplitAsciiWhitespace")<'a>
```
impl<'a> Iterator for SplitAsciiWhitespace<'a>
type Item = &'a str;
```
Splits a string slice by ASCII whitespace.
The iterator returned will return string slices that are sub-slices of the original string slice, separated by any amount of ASCII whitespace.
To split by Unicode `Whitespace` instead, use [`split_whitespace`](../primitive.str#method.split_whitespace).
##### Examples
Basic usage:
```
let mut iter = "A few words".split_ascii_whitespace();
assert_eq!(Some("A"), iter.next());
assert_eq!(Some("few"), iter.next());
assert_eq!(Some("words"), iter.next());
assert_eq!(None, iter.next());
```
All kinds of ASCII whitespace are considered:
```
let mut iter = " Mary had\ta little \n\t lamb".split_ascii_whitespace();
assert_eq!(Some("Mary"), iter.next());
assert_eq!(Some("had"), iter.next());
assert_eq!(Some("a"), iter.next());
assert_eq!(Some("little"), iter.next());
assert_eq!(Some("lamb"), iter.next());
assert_eq!(None, iter.next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#999)#### pub fn lines(&self) -> Lines<'\_>
Notable traits for [Lines](../str/struct.lines "struct std::str::Lines")<'a>
```
impl<'a> Iterator for Lines<'a>
type Item = &'a str;
```
An iterator over the lines of a string, as string slices.
Lines are ended with either a newline (`\n`) or a carriage return with a line feed (`\r\n`).
The final line ending is optional. A string that ends with a final line ending will return the same lines as an otherwise identical string without a final line ending.
##### Examples
Basic usage:
```
let text = "foo\r\nbar\n\nbaz\n";
let mut lines = text.lines();
assert_eq!(Some("foo"), lines.next());
assert_eq!(Some("bar"), lines.next());
assert_eq!(Some(""), lines.next());
assert_eq!(Some("baz"), lines.next());
assert_eq!(None, lines.next());
```
The final line ending isn’t required:
```
let text = "foo\nbar\n\r\nbaz";
let mut lines = text.lines();
assert_eq!(Some("foo"), lines.next());
assert_eq!(Some("bar"), lines.next());
assert_eq!(Some(""), lines.next());
assert_eq!(Some("baz"), lines.next());
assert_eq!(None, lines.next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1008)#### pub fn lines\_any(&self) -> LinesAny<'\_>
Notable traits for [LinesAny](../str/struct.linesany "struct std::str::LinesAny")<'a>
```
impl<'a> Iterator for LinesAny<'a>
type Item = &'a str;
```
👎Deprecated since 1.4.0: use lines() instead now
An iterator over the lines of a string.
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1029)1.8.0 · #### pub fn encode\_utf16(&self) -> EncodeUtf16<'\_>
Notable traits for [EncodeUtf16](../str/struct.encodeutf16 "struct std::str::EncodeUtf16")<'a>
```
impl<'a> Iterator for EncodeUtf16<'a>
type Item = u16;
```
Returns an iterator of `u16` over the string encoded as UTF-16.
##### Examples
Basic usage:
```
let text = "Zażółć gęślą jaźń";
let utf8_len = text.len();
let utf16_len = text.encode_utf16().count();
assert!(utf16_len <= utf8_len);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1056)#### pub fn contains<'a, P>(&'a self, pat: P) -> boolwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Returns `true` if the given pattern matches a sub-slice of this string slice.
Returns `false` if it does not.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
Basic usage:
```
let bananas = "bananas";
assert!(bananas.contains("nana"));
assert!(!bananas.contains("apples"));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1082)#### pub fn starts\_with<'a, P>(&'a self, pat: P) -> boolwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Returns `true` if the given pattern matches a prefix of this string slice.
Returns `false` if it does not.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
Basic usage:
```
let bananas = "bananas";
assert!(bananas.starts_with("bana"));
assert!(!bananas.starts_with("nana"));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1108-1110)#### pub fn ends\_with<'a, P>(&'a self, pat: P) -> boolwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Returns `true` if the given pattern matches a suffix of this string slice.
Returns `false` if it does not.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
Basic usage:
```
let bananas = "bananas";
assert!(bananas.ends_with("anas"));
assert!(!bananas.ends_with("nana"));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1159)#### pub fn find<'a, P>(&'a self, pat: P) -> Option<usize>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Returns the byte index of the first character of this string slice that matches the pattern.
Returns [`None`](../option/enum.option#variant.None "None") if the pattern doesn’t match.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
Simple patterns:
```
let s = "Löwe 老虎 Léopard Gepardi";
assert_eq!(s.find('L'), Some(0));
assert_eq!(s.find('é'), Some(14));
assert_eq!(s.find("pard"), Some(17));
```
More complex patterns using point-free style and closures:
```
let s = "Löwe 老虎 Léopard";
assert_eq!(s.find(char::is_whitespace), Some(5));
assert_eq!(s.find(char::is_lowercase), Some(1));
assert_eq!(s.find(|c: char| c.is_whitespace() || c.is_lowercase()), Some(1));
assert_eq!(s.find(|c: char| (c < 'o') && (c > 'a')), Some(4));
```
Not finding the pattern:
```
let s = "Löwe 老虎 Léopard";
let x: &[_] = &['1', '2'];
assert_eq!(s.find(x), None);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1205-1207)#### pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Returns the byte index for the first character of the last match of the pattern in this string slice.
Returns [`None`](../option/enum.option#variant.None "None") if the pattern doesn’t match.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
Simple patterns:
```
let s = "Löwe 老虎 Léopard Gepardi";
assert_eq!(s.rfind('L'), Some(13));
assert_eq!(s.rfind('é'), Some(14));
assert_eq!(s.rfind("pard"), Some(24));
```
More complex patterns with closures:
```
let s = "Löwe 老虎 Léopard";
assert_eq!(s.rfind(char::is_whitespace), Some(12));
assert_eq!(s.rfind(char::is_lowercase), Some(20));
```
Not finding the pattern:
```
let s = "Löwe 老虎 Léopard";
let x: &[_] = &['1', '2'];
assert_eq!(s.rfind(x), None);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1327)#### pub fn split<'a, P>(&'a self, pat: P) -> Split<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Notable traits for [Split](../str/struct.split "struct std::str::Split")<'a, P>
```
impl<'a, P> Iterator for Split<'a, P>where
P: Pattern<'a>,
type Item = &'a str;
```
An iterator over substrings of this string slice, separated by characters matched by a pattern.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator will be a [`DoubleEndedIterator`](../iter/trait.doubleendediterator "DoubleEndedIterator") if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., [`char`](../primitive.char), but not for `&str`.
If the pattern allows a reverse search but its results might differ from a forward search, the [`rsplit`](../primitive.str#method.rsplit) method can be used.
##### Examples
Simple patterns:
```
let v: Vec<&str> = "Mary had a little lamb".split(' ').collect();
assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
let v: Vec<&str> = "".split('X').collect();
assert_eq!(v, [""]);
let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect();
assert_eq!(v, ["lion", "", "tiger", "leopard"]);
let v: Vec<&str> = "lion::tiger::leopard".split("::").collect();
assert_eq!(v, ["lion", "tiger", "leopard"]);
let v: Vec<&str> = "abc1def2ghi".split(char::is_numeric).collect();
assert_eq!(v, ["abc", "def", "ghi"]);
let v: Vec<&str> = "lionXtigerXleopard".split(char::is_uppercase).collect();
assert_eq!(v, ["lion", "tiger", "leopard"]);
```
If the pattern is a slice of chars, split on each occurrence of any of the characters:
```
let v: Vec<&str> = "2020-11-03 23:59".split(&['-', ' ', ':', '@'][..]).collect();
assert_eq!(v, ["2020", "11", "03", "23", "59"]);
```
A more complex pattern, using a closure:
```
let v: Vec<&str> = "abc1defXghi".split(|c| c == '1' || c == 'X').collect();
assert_eq!(v, ["abc", "def", "ghi"]);
```
If a string contains multiple contiguous separators, you will end up with empty strings in the output:
```
let x = "||||a||b|c".to_string();
let d: Vec<_> = x.split('|').collect();
assert_eq!(d, &["", "", "", "", "a", "", "b", "c"]);
```
Contiguous separators are separated by the empty string.
```
let x = "(///)".to_string();
let d: Vec<_> = x.split('/').collect();
assert_eq!(d, &["(", "", "", ")"]);
```
Separators at the start or end of a string are neighbored by empty strings.
```
let d: Vec<_> = "010".split("0").collect();
assert_eq!(d, &["", "1", ""]);
```
When the empty string is used as a separator, it separates every character in the string, along with the beginning and end of the string.
```
let f: Vec<_> = "rust".split("").collect();
assert_eq!(f, &["", "r", "u", "s", "t", ""]);
```
Contiguous separators can lead to possibly surprising behavior when whitespace is used as the separator. This code is correct:
```
let x = " a b c".to_string();
let d: Vec<_> = x.split(' ').collect();
assert_eq!(d, &["", "", "", "", "a", "", "b", "c"]);
```
It does *not* give you:
ⓘ
```
assert_eq!(d, &["a", "b", "c"]);
```
Use [`split_whitespace`](../primitive.str#method.split_whitespace) for this behavior.
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1367)1.51.0 · #### pub fn split\_inclusive<'a, P>(&'a self, pat: P) -> SplitInclusive<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Notable traits for [SplitInclusive](../str/struct.splitinclusive "struct std::str::SplitInclusive")<'a, P>
```
impl<'a, P> Iterator for SplitInclusive<'a, P>where
P: Pattern<'a>,
type Item = &'a str;
```
An iterator over substrings of this string slice, separated by characters matched by a pattern. Differs from the iterator produced by `split` in that `split_inclusive` leaves the matched part as the terminator of the substring.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
```
let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb."
.split_inclusive('\n').collect();
assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb."]);
```
If the last element of the string is matched, that element will be considered the terminator of the preceding substring. That substring will be the last item returned by the iterator.
```
let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb.\n"
.split_inclusive('\n').collect();
assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb.\n"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1422-1424)#### pub fn rsplit<'a, P>(&'a self, pat: P) -> RSplit<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Notable traits for [RSplit](../str/struct.rsplit "struct std::str::RSplit")<'a, P>
```
impl<'a, P> Iterator for RSplit<'a, P>where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
type Item = &'a str;
```
An iterator over substrings of the given string slice, separated by characters matched by a pattern and yielded in reverse order.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator requires that the pattern supports a reverse search, and it will be a [`DoubleEndedIterator`](../iter/trait.doubleendediterator "DoubleEndedIterator") if a forward/reverse search yields the same elements.
For iterating from the front, the [`split`](../primitive.str#method.split) method can be used.
##### Examples
Simple patterns:
```
let v: Vec<&str> = "Mary had a little lamb".rsplit(' ').collect();
assert_eq!(v, ["lamb", "little", "a", "had", "Mary"]);
let v: Vec<&str> = "".rsplit('X').collect();
assert_eq!(v, [""]);
let v: Vec<&str> = "lionXXtigerXleopard".rsplit('X').collect();
assert_eq!(v, ["leopard", "tiger", "", "lion"]);
let v: Vec<&str> = "lion::tiger::leopard".rsplit("::").collect();
assert_eq!(v, ["leopard", "tiger", "lion"]);
```
A more complex pattern, using a closure:
```
let v: Vec<&str> = "abc1defXghi".rsplit(|c| c == '1' || c == 'X').collect();
assert_eq!(v, ["ghi", "def", "abc"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1473)#### pub fn split\_terminator<'a, P>(&'a self, pat: P) -> SplitTerminator<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Notable traits for [SplitTerminator](../str/struct.splitterminator "struct std::str::SplitTerminator")<'a, P>
```
impl<'a, P> Iterator for SplitTerminator<'a, P>where
P: Pattern<'a>,
type Item = &'a str;
```
An iterator over substrings of the given string slice, separated by characters matched by a pattern.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
Equivalent to [`split`](../primitive.str#method.split), except that the trailing substring is skipped if empty.
This method can be used for string data that is *terminated*, rather than *separated* by a pattern.
##### Iterator behavior
The returned iterator will be a [`DoubleEndedIterator`](../iter/trait.doubleendediterator "DoubleEndedIterator") if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., [`char`](../primitive.char), but not for `&str`.
If the pattern allows a reverse search but its results might differ from a forward search, the [`rsplit_terminator`](../primitive.str#method.rsplit_terminator) method can be used.
##### Examples
Basic usage:
```
let v: Vec<&str> = "A.B.".split_terminator('.').collect();
assert_eq!(v, ["A", "B"]);
let v: Vec<&str> = "A..B..".split_terminator(".").collect();
assert_eq!(v, ["A", "", "B", ""]);
let v: Vec<&str> = "A.B:C.D".split_terminator(&['.', ':'][..]).collect();
assert_eq!(v, ["A", "B", "C", "D"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1519-1521)#### pub fn rsplit\_terminator<'a, P>(&'a self, pat: P) -> RSplitTerminator<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Notable traits for [RSplitTerminator](../str/struct.rsplitterminator "struct std::str::RSplitTerminator")<'a, P>
```
impl<'a, P> Iterator for RSplitTerminator<'a, P>where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
type Item = &'a str;
```
An iterator over substrings of `self`, separated by characters matched by a pattern and yielded in reverse order.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
Equivalent to [`split`](../primitive.str#method.split), except that the trailing substring is skipped if empty.
This method can be used for string data that is *terminated*, rather than *separated* by a pattern.
##### Iterator behavior
The returned iterator requires that the pattern supports a reverse search, and it will be double ended if a forward/reverse search yields the same elements.
For iterating from the front, the [`split_terminator`](../primitive.str#method.split_terminator) method can be used.
##### Examples
```
let v: Vec<&str> = "A.B.".rsplit_terminator('.').collect();
assert_eq!(v, ["B", "A"]);
let v: Vec<&str> = "A..B..".rsplit_terminator(".").collect();
assert_eq!(v, ["", "B", "", "A"]);
let v: Vec<&str> = "A.B:C.D".rsplit_terminator(&['.', ':'][..]).collect();
assert_eq!(v, ["D", "C", "B", "A"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1574)#### pub fn splitn<'a, P>(&'a self, n: usize, pat: P) -> SplitN<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Notable traits for [SplitN](../str/struct.splitn "struct std::str::SplitN")<'a, P>
```
impl<'a, P> Iterator for SplitN<'a, P>where
P: Pattern<'a>,
type Item = &'a str;
```
An iterator over substrings of the given string slice, separated by a pattern, restricted to returning at most `n` items.
If `n` substrings are returned, the last substring (the `n`th substring) will contain the remainder of the string.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator will not be double ended, because it is not efficient to support.
If the pattern allows a reverse search, the [`rsplitn`](../primitive.str#method.rsplitn) method can be used.
##### Examples
Simple patterns:
```
let v: Vec<&str> = "Mary had a little lambda".splitn(3, ' ').collect();
assert_eq!(v, ["Mary", "had", "a little lambda"]);
let v: Vec<&str> = "lionXXtigerXleopard".splitn(3, "X").collect();
assert_eq!(v, ["lion", "", "tigerXleopard"]);
let v: Vec<&str> = "abcXdef".splitn(1, 'X').collect();
assert_eq!(v, ["abcXdef"]);
let v: Vec<&str> = "".splitn(1, 'X').collect();
assert_eq!(v, [""]);
```
A more complex pattern, using a closure:
```
let v: Vec<&str> = "abc1defXghi".splitn(2, |c| c == '1' || c == 'X').collect();
assert_eq!(v, ["abc", "defXghi"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1623-1625)#### pub fn rsplitn<'a, P>(&'a self, n: usize, pat: P) -> RSplitN<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Notable traits for [RSplitN](../str/struct.rsplitn "struct std::str::RSplitN")<'a, P>
```
impl<'a, P> Iterator for RSplitN<'a, P>where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
type Item = &'a str;
```
An iterator over substrings of this string slice, separated by a pattern, starting from the end of the string, restricted to returning at most `n` items.
If `n` substrings are returned, the last substring (the `n`th substring) will contain the remainder of the string.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator will not be double ended, because it is not efficient to support.
For splitting from the front, the [`splitn`](../primitive.str#method.splitn) method can be used.
##### Examples
Simple patterns:
```
let v: Vec<&str> = "Mary had a little lamb".rsplitn(3, ' ').collect();
assert_eq!(v, ["lamb", "little", "Mary had a"]);
let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(3, 'X').collect();
assert_eq!(v, ["leopard", "tiger", "lionX"]);
let v: Vec<&str> = "lion::tiger::leopard".rsplitn(2, "::").collect();
assert_eq!(v, ["leopard", "lion::tiger"]);
```
A more complex pattern, using a closure:
```
let v: Vec<&str> = "abc1defXghi".rsplitn(2, |c| c == '1' || c == 'X').collect();
assert_eq!(v, ["ghi", "abc1def"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1643)1.52.0 · #### pub fn split\_once<'a, P>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Splits the string on the first occurrence of the specified delimiter and returns prefix before delimiter and suffix after delimiter.
##### Examples
```
assert_eq!("cfg".split_once('='), None);
assert_eq!("cfg=".split_once('='), Some(("cfg", "")));
assert_eq!("cfg=foo".split_once('='), Some(("cfg", "foo")));
assert_eq!("cfg=foo=bar".split_once('='), Some(("cfg", "foo=bar")));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1661-1663)1.52.0 · #### pub fn rsplit\_once<'a, P>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Splits the string on the last occurrence of the specified delimiter and returns prefix before delimiter and suffix after delimiter.
##### Examples
```
assert_eq!("cfg".rsplit_once('='), None);
assert_eq!("cfg=foo".rsplit_once('='), Some(("cfg", "foo")));
assert_eq!("cfg=foo=bar".rsplit_once('='), Some(("cfg=foo", "bar")));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1703)1.2.0 · #### pub fn matches<'a, P>(&'a self, pat: P) -> Matches<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Notable traits for [Matches](../str/struct.matches "struct std::str::Matches")<'a, P>
```
impl<'a, P> Iterator for Matches<'a, P>where
P: Pattern<'a>,
type Item = &'a str;
```
An iterator over the disjoint matches of a pattern within the given string slice.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator will be a [`DoubleEndedIterator`](../iter/trait.doubleendediterator "DoubleEndedIterator") if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., [`char`](../primitive.char), but not for `&str`.
If the pattern allows a reverse search but its results might differ from a forward search, the [`rmatches`](../primitive.str#method.matches) method can be used.
##### Examples
Basic usage:
```
let v: Vec<&str> = "abcXXXabcYYYabc".matches("abc").collect();
assert_eq!(v, ["abc", "abc", "abc"]);
let v: Vec<&str> = "1abc2abc3".matches(char::is_numeric).collect();
assert_eq!(v, ["1", "2", "3"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1739-1741)1.2.0 · #### pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Notable traits for [RMatches](../str/struct.rmatches "struct std::str::RMatches")<'a, P>
```
impl<'a, P> Iterator for RMatches<'a, P>where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
type Item = &'a str;
```
An iterator over the disjoint matches of a pattern within this string slice, yielded in reverse order.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator requires that the pattern supports a reverse search, and it will be a [`DoubleEndedIterator`](../iter/trait.doubleendediterator "DoubleEndedIterator") if a forward/reverse search yields the same elements.
For iterating from the front, the [`matches`](../primitive.str#method.matches) method can be used.
##### Examples
Basic usage:
```
let v: Vec<&str> = "abcXXXabcYYYabc".rmatches("abc").collect();
assert_eq!(v, ["abc", "abc", "abc"]);
let v: Vec<&str> = "1abc2abc3".rmatches(char::is_numeric).collect();
assert_eq!(v, ["3", "2", "1"]);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1785)1.5.0 · #### pub fn match\_indices<'a, P>(&'a self, pat: P) -> MatchIndices<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Notable traits for [MatchIndices](../str/struct.matchindices "struct std::str::MatchIndices")<'a, P>
```
impl<'a, P> Iterator for MatchIndices<'a, P>where
P: Pattern<'a>,
type Item = (usize, &'a str);
```
An iterator over the disjoint matches of a pattern within this string slice as well as the index that the match starts at.
For matches of `pat` within `self` that overlap, only the indices corresponding to the first match are returned.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator will be a [`DoubleEndedIterator`](../iter/trait.doubleendediterator "DoubleEndedIterator") if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., [`char`](../primitive.char), but not for `&str`.
If the pattern allows a reverse search but its results might differ from a forward search, the [`rmatch_indices`](../primitive.str#method.rmatch_indices) method can be used.
##### Examples
Basic usage:
```
let v: Vec<_> = "abcXXXabcYYYabc".match_indices("abc").collect();
assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]);
let v: Vec<_> = "1abcabc2".match_indices("abc").collect();
assert_eq!(v, [(1, "abc"), (4, "abc")]);
let v: Vec<_> = "ababa".match_indices("aba").collect();
assert_eq!(v, [(0, "aba")]); // only the first `aba`
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1827-1829)1.5.0 · #### pub fn rmatch\_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Notable traits for [RMatchIndices](../str/struct.rmatchindices "struct std::str::RMatchIndices")<'a, P>
```
impl<'a, P> Iterator for RMatchIndices<'a, P>where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
type Item = (usize, &'a str);
```
An iterator over the disjoint matches of a pattern within `self`, yielded in reverse order along with the index of the match.
For matches of `pat` within `self` that overlap, only the indices corresponding to the last match are returned.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Iterator behavior
The returned iterator requires that the pattern supports a reverse search, and it will be a [`DoubleEndedIterator`](../iter/trait.doubleendediterator "DoubleEndedIterator") if a forward/reverse search yields the same elements.
For iterating from the front, the [`match_indices`](../primitive.str#method.match_indices) method can be used.
##### Examples
Basic usage:
```
let v: Vec<_> = "abcXXXabcYYYabc".rmatch_indices("abc").collect();
assert_eq!(v, [(12, "abc"), (6, "abc"), (0, "abc")]);
let v: Vec<_> = "1abcabc2".rmatch_indices("abc").collect();
assert_eq!(v, [(4, "abc"), (1, "abc")]);
let v: Vec<_> = "ababa".rmatch_indices("aba").collect();
assert_eq!(v, [(2, "aba")]); // only the last `aba`
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1853)#### pub fn trim(&self) -> &str
Returns a string slice with leading and trailing whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property `White_Space`, which includes newlines.
##### Examples
Basic usage:
```
let s = "\n Hello\tworld\t\n";
assert_eq!("Hello\tworld", s.trim());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1892)1.30.0 · #### pub fn trim\_start(&self) -> &str
Returns a string slice with leading whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property `White_Space`, which includes newlines.
##### Text directionality
A string is a sequence of bytes. `start` in this context means the first position of that byte string; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side.
##### Examples
Basic usage:
```
let s = "\n Hello\tworld\t\n";
assert_eq!("Hello\tworld\t\n", s.trim_start());
```
Directionality:
```
let s = " English ";
assert!(Some('E') == s.trim_start().chars().next());
let s = " עברית ";
assert!(Some('ע') == s.trim_start().chars().next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1931)1.30.0 · #### pub fn trim\_end(&self) -> &str
Returns a string slice with trailing whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property `White_Space`, which includes newlines.
##### Text directionality
A string is a sequence of bytes. `end` in this context means the last position of that byte string; for a left-to-right language like English or Russian, this will be right side, and for right-to-left languages like Arabic or Hebrew, this will be the left side.
##### Examples
Basic usage:
```
let s = "\n Hello\tworld\t\n";
assert_eq!("\n Hello\tworld", s.trim_end());
```
Directionality:
```
let s = " English ";
assert!(Some('h') == s.trim_end().chars().rev().next());
let s = " עברית ";
assert!(Some('ת') == s.trim_end().chars().rev().next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#1971)#### pub fn trim\_left(&self) -> &str
👎Deprecated since 1.33.0: superseded by `trim_start`
Returns a string slice with leading whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property `White_Space`.
##### Text directionality
A string is a sequence of bytes. ‘Left’ in this context means the first position of that byte string; for a language like Arabic or Hebrew which are ‘right to left’ rather than ‘left to right’, this will be the *right* side, not the left.
##### Examples
Basic usage:
```
let s = " Hello\tworld\t";
assert_eq!("Hello\tworld\t", s.trim_left());
```
Directionality:
```
let s = " English";
assert!(Some('E') == s.trim_left().chars().next());
let s = " עברית";
assert!(Some('ע') == s.trim_left().chars().next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2011)#### pub fn trim\_right(&self) -> &str
👎Deprecated since 1.33.0: superseded by `trim_end`
Returns a string slice with trailing whitespace removed.
‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property `White_Space`.
##### Text directionality
A string is a sequence of bytes. ‘Right’ in this context means the last position of that byte string; for a language like Arabic or Hebrew which are ‘right to left’ rather than ‘left to right’, this will be the *left* side, not the right.
##### Examples
Basic usage:
```
let s = " Hello\tworld\t";
assert_eq!(" Hello\tworld", s.trim_right());
```
Directionality:
```
let s = "English ";
assert!(Some('h') == s.trim_right().chars().rev().next());
let s = "עברית ";
assert!(Some('ת') == s.trim_right().chars().rev().next());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2044-2046)#### pub fn trim\_matches<'a, P>(&'a self, pat: P) -> &'a strwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [DoubleEndedSearcher](../str/pattern/trait.doubleendedsearcher "trait std::str::pattern::DoubleEndedSearcher")<'a>,
Returns a string slice with all prefixes and suffixes that match a pattern repeatedly removed.
The [pattern](../str/pattern/index) can be a [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
Simple patterns:
```
assert_eq!("11foo1bar11".trim_matches('1'), "foo1bar");
assert_eq!("123foo1bar123".trim_matches(char::is_numeric), "foo1bar");
let x: &[_] = &['1', '2'];
assert_eq!("12foo1bar12".trim_matches(x), "foo1bar");
```
A more complex pattern, using a closure:
```
assert_eq!("1foo1barXX".trim_matches(|c| c == '1' || c == 'X'), "foo1bar");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2093)1.30.0 · #### pub fn trim\_start\_matches<'a, P>(&'a self, pat: P) -> &'a strwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Returns a string slice with all prefixes that match a pattern repeatedly removed.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Text directionality
A string is a sequence of bytes. `start` in this context means the first position of that byte string; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side.
##### Examples
Basic usage:
```
assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11");
assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123");
let x: &[_] = &['1', '2'];
assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2126)1.45.0 · #### pub fn strip\_prefix<'a, P>(&'a self, prefix: P) -> Option<&'a str>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Returns a string slice with the prefix removed.
If the string starts with the pattern `prefix`, returns substring after the prefix, wrapped in `Some`. Unlike `trim_start_matches`, this method removes the prefix exactly once.
If the string does not start with `prefix`, returns `None`.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
```
assert_eq!("foo:bar".strip_prefix("foo:"), Some("bar"));
assert_eq!("foo:bar".strip_prefix("bar"), None);
assert_eq!("foofoo".strip_prefix("foo"), Some("foo"));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2153-2156)1.45.0 · #### pub fn strip\_suffix<'a, P>(&'a self, suffix: P) -> Option<&'a str>where P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Returns a string slice with the suffix removed.
If the string ends with the pattern `suffix`, returns the substring before the suffix, wrapped in `Some`. Unlike `trim_end_matches`, this method removes the suffix exactly once.
If the string does not end with `suffix`, returns `None`.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Examples
```
assert_eq!("bar:foo".strip_suffix(":foo"), Some("bar"));
assert_eq!("bar:foo".strip_suffix("bar"), None);
assert_eq!("foofoo".strip_suffix("foo"), Some("foo"));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2197-2199)1.30.0 · #### pub fn trim\_end\_matches<'a, P>(&'a self, pat: P) -> &'a strwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
Returns a string slice with all suffixes that match a pattern repeatedly removed.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Text directionality
A string is a sequence of bytes. `end` in this context means the last position of that byte string; for a left-to-right language like English or Russian, this will be right side, and for right-to-left languages like Arabic or Hebrew, this will be the left side.
##### Examples
Simple patterns:
```
assert_eq!("11foo1bar11".trim_end_matches('1'), "11foo1bar");
assert_eq!("123foo1bar123".trim_end_matches(char::is_numeric), "123foo1bar");
let x: &[_] = &['1', '2'];
assert_eq!("12foo1bar12".trim_end_matches(x), "12foo1bar");
```
A more complex pattern, using a closure:
```
assert_eq!("1fooX".trim_end_matches(|c| c == '1' || c == 'X'), "1foo");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2243)#### pub fn trim\_left\_matches<'a, P>(&'a self, pat: P) -> &'a strwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
👎Deprecated since 1.33.0: superseded by `trim_start_matches`
Returns a string slice with all prefixes that match a pattern repeatedly removed.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Text directionality
A string is a sequence of bytes. ‘Left’ in this context means the first position of that byte string; for a language like Arabic or Hebrew which are ‘right to left’ rather than ‘left to right’, this will be the *right* side, not the left.
##### Examples
Basic usage:
```
assert_eq!("11foo1bar11".trim_left_matches('1'), "foo1bar11");
assert_eq!("123foo1bar123".trim_left_matches(char::is_numeric), "foo1bar123");
let x: &[_] = &['1', '2'];
assert_eq!("12foo1bar12".trim_left_matches(x), "foo1bar12");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2286-2288)#### pub fn trim\_right\_matches<'a, P>(&'a self, pat: P) -> &'a strwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>, <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [ReverseSearcher](../str/pattern/trait.reversesearcher "trait std::str::pattern::ReverseSearcher")<'a>,
👎Deprecated since 1.33.0: superseded by `trim_end_matches`
Returns a string slice with all suffixes that match a pattern repeatedly removed.
The [pattern](../str/pattern/index) can be a `&str`, [`char`](../primitive.char), a slice of [`char`](../primitive.char)s, or a function or closure that determines if a character matches.
##### Text directionality
A string is a sequence of bytes. ‘Right’ in this context means the last position of that byte string; for a language like Arabic or Hebrew which are ‘right to left’ rather than ‘left to right’, this will be the *left* side, not the right.
##### Examples
Simple patterns:
```
assert_eq!("11foo1bar11".trim_right_matches('1'), "11foo1bar");
assert_eq!("123foo1bar123".trim_right_matches(char::is_numeric), "123foo1bar");
let x: &[_] = &['1', '2'];
assert_eq!("12foo1bar12".trim_right_matches(x), "12foo1bar");
```
A more complex pattern, using a closure:
```
assert_eq!("1fooX".trim_right_matches(|c| c == '1' || c == 'X'), "1foo");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2338)#### pub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err>where F: [FromStr](../str/trait.fromstr "trait std::str::FromStr"),
Parses this string slice into another type.
Because `parse` is so general, it can cause problems with type inference. As such, `parse` is one of the few times you’ll see the syntax affectionately known as the ‘turbofish’: `::<>`. This helps the inference algorithm understand specifically which type you’re trying to parse into.
`parse` can parse into any type that implements the [`FromStr`](../str/trait.fromstr "FromStr") trait.
##### Errors
Will return [`Err`](../str/trait.fromstr#associatedtype.Err) if it’s not possible to parse this string slice into the desired type.
##### Examples
Basic usage
```
let four: u32 = "4".parse().unwrap();
assert_eq!(4, four);
```
Using the ‘turbofish’ instead of annotating `four`:
```
let four = "4".parse::<u32>();
assert_eq!(Ok(4), four);
```
Failing to parse:
```
let nope = "j".parse::<u32>();
assert!(nope.is_err());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2356)1.23.0 · #### pub fn is\_ascii(&self) -> bool
Checks if all characters in this string are within the ASCII range.
##### Examples
```
let ascii = "hello!\n";
let non_ascii = "Grüße, Jürgen ❤";
assert!(ascii.is_ascii());
assert!(!non_ascii.is_ascii());
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2378)1.23.0 · #### pub fn eq\_ignore\_ascii\_case(&self, other: &str) -> bool
Checks that two strings are an ASCII case-insensitive match.
Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`, but without allocating and copying temporaries.
##### Examples
```
assert!("Ferris".eq_ignore_ascii_case("FERRIS"));
assert!("Ferrös".eq_ignore_ascii_case("FERRöS"));
assert!(!"Ferrös".eq_ignore_ascii_case("FERRÖS"));
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2403)1.23.0 · #### pub fn make\_ascii\_uppercase(&mut self)
Converts this string to its ASCII upper case equivalent in-place.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.
To return a new uppercased value without modifying the existing one, use [`to_ascii_uppercase()`](#method.to_ascii_uppercase).
##### Examples
```
let mut s = String::from("Grüße, Jürgen ❤");
s.make_ascii_uppercase();
assert_eq!("GRüßE, JüRGEN ❤", s);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2430)1.23.0 · #### pub fn make\_ascii\_lowercase(&mut self)
Converts this string to its ASCII lower case equivalent in-place.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.
To return a new lowercased value without modifying the existing one, use [`to_ascii_lowercase()`](#method.to_ascii_lowercase).
##### Examples
```
let mut s = String::from("GRÜßE, JÜRGEN ❤");
s.make_ascii_lowercase();
assert_eq!("grÜße, jÜrgen ❤", s);
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2473)1.34.0 · #### pub fn escape\_debug(&self) -> EscapeDebug<'\_>
Notable traits for [EscapeDebug](../str/struct.escapedebug "struct std::str::EscapeDebug")<'a>
```
impl<'a> Iterator for EscapeDebug<'a>
type Item = char;
```
Return an iterator that escapes each char in `self` with [`char::escape_debug`](../primitive.char#method.escape_debug "char::escape_debug").
Note: only extended grapheme codepoints that begin the string will be escaped.
##### Examples
As an iterator:
```
for c in "❤\n!".escape_debug() {
print!("{c}");
}
println!();
```
Using `println!` directly:
```
println!("{}", "❤\n!".escape_debug());
```
Both are equivalent to:
```
println!("❤\\n!");
```
Using `to_string`:
```
assert_eq!("❤\n!".escape_debug().to_string(), "❤\\n!");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2519)1.34.0 · #### pub fn escape\_default(&self) -> EscapeDefault<'\_>
Notable traits for [EscapeDefault](../str/struct.escapedefault "struct std::str::EscapeDefault")<'a>
```
impl<'a> Iterator for EscapeDefault<'a>
type Item = char;
```
Return an iterator that escapes each char in `self` with [`char::escape_default`](../primitive.char#method.escape_default "char::escape_default").
##### Examples
As an iterator:
```
for c in "❤\n!".escape_default() {
print!("{c}");
}
println!();
```
Using `println!` directly:
```
println!("{}", "❤\n!".escape_default());
```
Both are equivalent to:
```
println!("\\u{{2764}}\\n!");
```
Using `to_string`:
```
assert_eq!("❤\n!".escape_default().to_string(), "\\u{2764}\\n!");
```
[source](https://doc.rust-lang.org/src/core/str/mod.rs.html#2557)1.34.0 · #### pub fn escape\_unicode(&self) -> EscapeUnicode<'\_>
Notable traits for [EscapeUnicode](../str/struct.escapeunicode "struct std::str::EscapeUnicode")<'a>
```
impl<'a> Iterator for EscapeUnicode<'a>
type Item = char;
```
Return an iterator that escapes each char in `self` with [`char::escape_unicode`](../primitive.char#method.escape_unicode "char::escape_unicode").
##### Examples
As an iterator:
```
for c in "❤\n!".escape_unicode() {
print!("{c}");
}
println!();
```
Using `println!` directly:
```
println!("{}", "❤\n!".escape_unicode());
```
Both are equivalent to:
```
println!("\\u{{2764}}\\u{{a}}\\u{{21}}");
```
Using `to_string`:
```
assert_eq!("❤\n!".escape_unicode().to_string(), "\\u{2764}\\u{a}\\u{21}");
```
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#271)#### pub fn replace<'a, P>(&'a self, from: P, to: &str) -> Stringwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Replaces all matches of a pattern with another string.
`replace` creates a new [`String`](struct.string "String"), and copies the data from this string slice into it. While doing so, it attempts to find matches of a pattern. If it finds any, it replaces them with the replacement string slice.
##### Examples
Basic usage:
```
let s = "this is old";
assert_eq!("this is new", s.replace("old", "new"));
assert_eq!("than an old", s.replace("is", "an"));
```
When the pattern doesn’t match:
```
let s = "this is old";
assert_eq!(s, s.replace("cookie monster", "little lamb"));
```
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#311)1.16.0 · #### pub fn replacen<'a, P>(&'a self, pat: P, to: &str, count: usize) -> Stringwhere P: [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>,
Replaces first N matches of a pattern with another string.
`replacen` creates a new [`String`](struct.string "String"), and copies the data from this string slice into it. While doing so, it attempts to find matches of a pattern. If it finds any, it replaces them with the replacement string slice at most `count` times.
##### Examples
Basic usage:
```
let s = "foo foo 123 foo";
assert_eq!("new new 123 foo", s.replacen("foo", "new", 2));
assert_eq!("faa fao 123 foo", s.replacen('o', "a", 3));
assert_eq!("foo foo new23 foo", s.replacen(char::is_numeric, "new", 1));
```
When the pattern doesn’t match:
```
let s = "this is old";
assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
```
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#368)1.2.0 · #### pub fn to\_lowercase(&self) -> String
Returns the lowercase equivalent of this string slice, as a new [`String`](struct.string "String").
‘Lowercase’ is defined according to the terms of the Unicode Derived Core Property `Lowercase`.
Since some characters can expand into multiple characters when changing the case, this function returns a [`String`](struct.string "String") instead of modifying the parameter in-place.
##### Examples
Basic usage:
```
let s = "HELLO";
assert_eq!("hello", s.to_lowercase());
```
A tricky example, with sigma:
```
let sigma = "Σ";
assert_eq!("σ", sigma.to_lowercase());
// but at the end of a word, it's ς, not σ:
let odysseus = "ὈΔΥΣΣΕΎΣ";
assert_eq!("ὀδυσσεύς", odysseus.to_lowercase());
```
Languages without case are not changed:
```
let new_year = "农历新年";
assert_eq!(new_year, new_year.to_lowercase());
```
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#459)1.2.0 · #### pub fn to\_uppercase(&self) -> String
Returns the uppercase equivalent of this string slice, as a new [`String`](struct.string "String").
‘Uppercase’ is defined according to the terms of the Unicode Derived Core Property `Uppercase`.
Since some characters can expand into multiple characters when changing the case, this function returns a [`String`](struct.string "String") instead of modifying the parameter in-place.
##### Examples
Basic usage:
```
let s = "hello";
assert_eq!("HELLO", s.to_uppercase());
```
Scripts without case are not changed:
```
let new_year = "农历新年";
assert_eq!(new_year, new_year.to_uppercase());
```
One character can become multiple:
```
let s = "tschüß";
assert_eq!("TSCHÜSS", s.to_uppercase());
```
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#531)1.16.0 · #### pub fn repeat(&self, n: usize) -> String
Creates a new [`String`](struct.string "String") by repeating a string `n` times.
##### Panics
This function will panic if the capacity would overflow.
##### Examples
Basic usage:
```
assert_eq!("abc".repeat(4), String::from("abcabcabcabc"));
```
A panic upon overflow:
ⓘ
```
// this will panic at runtime
let huge = "0123456789abcdef".repeat(usize::MAX);
```
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#561)1.23.0 · #### pub fn to\_ascii\_uppercase(&self) -> String
Returns a copy of this string where each character is mapped to its ASCII upper case equivalent.
ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.
To uppercase the value in-place, use [`make_ascii_uppercase`](../primitive.str#method.make_ascii_uppercase).
To uppercase ASCII characters in addition to non-ASCII characters, use [`to_uppercase`](#method.to_uppercase).
##### Examples
```
let s = "Grüße, Jürgen ❤";
assert_eq!("GRüßE, JüRGEN ❤", s.to_ascii_uppercase());
```
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#594)1.23.0 · #### pub fn to\_ascii\_lowercase(&self) -> String
Returns a copy of this string where each character is mapped to its ASCII lower case equivalent.
ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.
To lowercase the value in-place, use [`make_ascii_lowercase`](../primitive.str#method.make_ascii_lowercase).
To lowercase ASCII characters in addition to non-ASCII characters, use [`to_lowercase`](#method.to_lowercase).
##### Examples
```
let s = "Grüße, Jürgen ❤";
assert_eq!("grüße, jürgen ❤", s.to_ascii_lowercase());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2308)### impl Add<&str> for String
Implements the `+` operator for concatenating two strings.
This consumes the `String` on the left-hand side and re-uses its buffer (growing it if necessary). This is done to avoid allocating a new `String` and copying the entire contents on every operation, which would lead to *O*(*n*^2) running time when building an *n*-byte string by repeated concatenation.
The string on the right-hand side is only borrowed; its contents are copied into the returned `String`.
#### Examples
Concatenating two `String`s takes the first by value and borrows the second:
```
let a = String::from("hello");
let b = String::from(" world");
let c = a + &b;
// `a` is moved and can no longer be used here.
```
If you want to keep using the first `String`, you can clone it and append to the clone instead:
```
let a = String::from("hello");
let b = String::from(" world");
let c = a.clone() + &b;
// `a` is still valid here.
```
Concatenating `&str` slices can be done by converting the first to a `String`:
```
let a = "hello";
let b = " world";
let c = a.to_string() + b;
```
#### type Output = String
The resulting type after applying the `+` operator.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2312)#### fn add(self, other: &str) -> String
Performs the `+` operation. [Read more](../ops/trait.add#tymethod.add)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2323)1.12.0 · ### impl AddAssign<&str> for String
Implements the `+=` operator for appending to a `String`.
This has the same behavior as the [`push_str`](struct.string#method.push_str "String::push_str") method.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2325)#### fn add\_assign(&mut self, other: &str)
Performs the `+=` operation. [Read more](../ops/trait.addassign#tymethod.add_assign)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2604)1.43.0 · ### impl AsMut<str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2606)#### fn as\_mut(&mut self) -> &mut str
Converts this type into a mutable reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2612)### impl AsRef<[u8]> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2614)#### fn as\_ref(&self) -> &[u8]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Converts this type into a shared reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#1327-1332)### impl AsRef<OsStr> for String
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#1329-1331)#### fn as\_ref(&self) -> &OsStr
Converts this type into a shared reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/std/path.rs.html#3041-3046)### impl AsRef<Path> for String
[source](https://doc.rust-lang.org/src/std/path.rs.html#3043-3045)#### fn as\_ref(&self) -> &Path
Converts this type into a shared reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2596)### impl AsRef<str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2598)#### fn as\_ref(&self) -> &str
Converts this type into a shared reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#188)### impl Borrow<str> for String
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#190)#### fn borrow(&self) -> &str
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#196)1.36.0 · ### impl BorrowMut<str> for String
[source](https://doc.rust-lang.org/src/alloc/str.rs.html#198)#### fn borrow\_mut(&mut self) -> &mut str
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1964)### impl Clone for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1965)#### fn clone(&self) -> String
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1969)#### fn clone\_from(&mut self, source: &String)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2254)### impl Debug for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2256)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2237)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2240)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> String
Creates an empty `String`.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2429)### impl Deref for String
#### type Target = str
The resulting type after dereferencing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2433)#### fn deref(&self) -> &str
Dereferences the value.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2439)1.3.0 · ### impl DerefMut for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2441)#### fn deref\_mut(&mut self) -> &mut str
Mutably dereferences the value.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2246)### impl Display for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2248)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2076)1.2.0 · ### impl<'a> Extend<&'a char> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2077)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = &'a [char](../primitive.char)>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2082)#### fn extend\_one(&mut self, &'a char)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2087)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2094)### impl<'a> Extend<&'a str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2095)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = &'a [str](../primitive.str)>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2100)#### fn extend\_one(&mut self, s: &'a str)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2107)1.45.0 · ### impl Extend<Box<str, Global>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2108)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [Box](../boxed/struct.box "struct std::boxed::Box")<[str](../primitive.str), [Global](../alloc/struct.global "struct std::alloc::Global")>>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#371)#### fn extend\_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2128)1.19.0 · ### impl<'a> Extend<Cow<'a, str>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2129)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [Cow](../borrow/enum.cow "enum std::borrow::Cow")<'a, [str](../primitive.str)>>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2134)#### fn extend\_one(&mut self, s: Cow<'a, str>)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2115)1.4.0 · ### impl Extend<String> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2116)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [String](struct.string "struct std::string::String")>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2121)#### fn extend\_one(&mut self, s: String)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2055)### impl Extend<char> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2056)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [char](../primitive.char)>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2064)#### fn extend\_one(&mut self, c: char)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2069)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2769)1.28.0 · ### impl<'a> From<&'a String> for Cow<'a, str>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2784)#### fn from(s: &'a String) -> Cow<'a, str>
Converts a [`String`](struct.string "String") reference into a [`Borrowed`](../borrow/enum.cow#variant.Borrowed "borrow::Cow::Borrowed") variant. No heap allocation is performed, and the string is not copied.
##### Example
```
let s = "eggplant".to_string();
assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2645)1.35.0 · ### impl From<&String> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2650)#### fn from(s: &String) -> String
Converts a `&String` into a [`String`](struct.string "String").
This clones `s` and returns the clone.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2633)1.44.0 · ### impl From<&mut str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2638)#### fn from(s: &mut str) -> String
Converts a `&mut str` into a [`String`](struct.string "String").
The result is allocated on the heap.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2621)### impl From<&str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2626)#### fn from(s: &str) -> String
Converts a `&str` into a [`String`](struct.string "String").
The result is allocated on the heap.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2658)1.18.0 · ### impl From<Box<str, Global>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2673)#### fn from(s: Box<str, Global>) -> String
Converts the given boxed `str` slice to a [`String`](struct.string "String"). It is notable that the `str` slice is owned.
##### Examples
Basic usage:
```
let s1: String = String::from("hello world");
let s2: Box<str> = s1.into_boxed_str();
let s3: String = String::from(s2);
assert_eq!("hello world", s3)
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2701)1.14.0 · ### impl<'a> From<Cow<'a, str>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2718)#### fn from(s: Cow<'a, str>) -> String
Converts a clone-on-write string to an owned instance of [`String`](struct.string "String").
This extracts the owned string, clones the string if it is not already owned.
##### Example
```
// If the string is not owned...
let cow: Cow<str> = Cow::Borrowed("eggplant");
// It will allocate on the heap and copy the string.
let owned: String = String::from(cow);
assert_eq!(&owned[..], "eggplant");
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2522)1.21.0 · ### impl From<String> for Arc<str>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2534)#### fn from(v: String) -> Arc<str>
Allocate a reference-counted `str` and copy `v` into it.
##### Example
```
let unique: String = "eggplant".to_owned();
let shared: Arc<str> = Arc::from(unique);
assert_eq!("eggplant", &shared[..]);
```
[source](https://doc.rust-lang.org/src/alloc/boxed.rs.html#2264)1.6.0 · ### impl From<String> for Box<dyn Error + 'static, Global>
[source](https://doc.rust-lang.org/src/alloc/boxed.rs.html#2277)#### fn from(str\_err: String) -> Box<dyn Error + 'static, Global>
Notable traits for [Box](../boxed/struct.box "struct std::boxed::Box")<I, A>
```
impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator,
type Item = <I as Iterator>::Item;
impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static,
type Output = <F as Future>::Output;
impl<R: Read + ?Sized> Read for Box<R>
impl<W: Write + ?Sized> Write for Box<W>
```
Converts a [`String`](struct.string "String") into a box of dyn [`Error`](../error/trait.error "Error").
##### Examples
```
use std::error::Error;
use std::mem;
let a_string_error = "a string error".to_string();
let a_boxed_error = Box::<dyn Error>::from(a_string_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
```
[source](https://doc.rust-lang.org/src/alloc/boxed.rs.html#2219)### impl From<String> for Box<dyn Error + Send + Sync + 'static, Global>
[source](https://doc.rust-lang.org/src/alloc/boxed.rs.html#2234)#### fn from(err: String) -> Box<dyn Error + Send + Sync + 'static, Global>
Notable traits for [Box](../boxed/struct.box "struct std::boxed::Box")<I, A>
```
impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator,
type Item = <I as Iterator>::Item;
impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static,
type Output = <F as Future>::Output;
impl<R: Read + ?Sized> Read for Box<R>
impl<W: Write + ?Sized> Write for Box<W>
```
Converts a [`String`](struct.string "String") into a box of dyn [`Error`](../error/trait.error "Error") + [`Send`](../marker/trait.send "Send") + [`Sync`](../marker/trait.sync "Sync").
##### Examples
```
use std::error::Error;
use std::mem;
let a_string_error = "a string error".to_string();
let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_string_error);
assert!(
mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2680)1.20.0 · ### impl From<String> for Box<str, Global>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2694)#### fn from(s: String) -> Box<str, Global>
Notable traits for [Box](../boxed/struct.box "struct std::boxed::Box")<I, A>
```
impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator,
type Item = <I as Iterator>::Item;
impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static,
type Output = <F as Future>::Output;
impl<R: Read + ?Sized> Read for Box<R>
impl<W: Write + ?Sized> Write for Box<W>
```
Converts the given [`String`](struct.string "String") to a boxed `str` slice that is owned.
##### Examples
Basic usage:
```
let s1: String = String::from("hello world");
let s2: Box<str> = Box::from(s1);
let s3: String = String::from(s2);
assert_eq!("hello world", s3)
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2746)### impl<'a> From<String> for Cow<'a, str>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2762)#### fn from(s: String) -> Cow<'a, str>
Converts a [`String`](struct.string "String") into an [`Owned`](../borrow/enum.cow#variant.Owned "borrow::Cow::Owned") variant. No heap allocation is performed, and the string is not copied.
##### Example
```
let s = "eggplant".to_string();
let s2 = "eggplant".to_string();
assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
```
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#472-480)### impl From<String> for OsString
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#477-479)#### fn from(s: String) -> OsString
Converts a [`String`](struct.string "String") into an [`OsString`](../ffi/struct.osstring "OsString").
This conversion does not allocate or copy memory.
[source](https://doc.rust-lang.org/src/std/path.rs.html#1670-1678)### impl From<String> for PathBuf
[source](https://doc.rust-lang.org/src/std/path.rs.html#1675-1677)#### fn from(s: String) -> PathBuf
Converts a [`String`](struct.string "String") into a [`PathBuf`](../path/struct.pathbuf "PathBuf")
This conversion does not allocate or copy memory.
[source](https://doc.rust-lang.org/src/alloc/rc.rs.html#1918)1.21.0 · ### impl From<String> for Rc<str>
[source](https://doc.rust-lang.org/src/alloc/rc.rs.html#1930)#### fn from(v: String) -> Rc<str>
Allocate a reference-counted string slice and copy `v` into it.
##### Example
```
let original: String = "statue".to_owned();
let shared: Rc<str> = Rc::from(original);
assert_eq!("statue", &shared[..]);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2814)1.14.0 · ### impl From<String> for Vec<u8, Global>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2829)#### fn from(string: String) -> Vec<u8, Global>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Converts the given [`String`](struct.string "String") to a vector [`Vec`](../vec/struct.vec "Vec") that holds values of type [`u8`](../primitive.u8 "u8").
##### Examples
Basic usage:
```
let s1 = String::from("hello world");
let v1 = Vec::from(s1);
for b in v1 {
println!("{b}");
}
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2959)1.46.0 · ### impl From<char> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2969)#### fn from(c: char) -> String
Allocates an owned [`String`](struct.string "String") from a single character.
##### Example
```
let c: char = 'a';
let s: String = String::from(c);
assert_eq!("a", &s[..]);
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1986)1.17.0 · ### impl<'a> FromIterator<&'a char> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1987)#### fn from\_iter<I>(iter: I) -> Stringwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = &'a [char](../primitive.char)>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1996)### impl<'a> FromIterator<&'a str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1997)#### fn from\_iter<I>(iter: I) -> Stringwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = &'a [str](../primitive.str)>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2025)1.45.0 · ### impl FromIterator<Box<str, Global>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2026)#### fn from\_iter<I>(iter: I) -> Stringwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [Box](../boxed/struct.box "struct std::boxed::Box")<[str](../primitive.str), [Global](../alloc/struct.global "struct std::alloc::Global")>>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2035)1.19.0 · ### impl<'a> FromIterator<Cow<'a, str>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2036)#### fn from\_iter<I>(iter: I) -> Stringwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [Cow](../borrow/enum.cow "enum std::borrow::Cow")<'a, [str](../primitive.str)>>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2807)1.12.0 · ### impl<'a> FromIterator<String> for Cow<'a, str>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2808)#### fn from\_iter<I>(it: I) -> Cow<'a, str>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [String](struct.string "struct std::string::String")>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2006)1.4.0 · ### impl FromIterator<String> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2007)#### fn from\_iter<I>(iter: I) -> Stringwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [String](struct.string "struct std::string::String")>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1976)### impl FromIterator<char> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1977)#### fn from\_iter<I>(iter: I) -> Stringwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [char](../primitive.char)>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2456)### impl FromStr for String
#### type Err = Infallible
The associated error which can be returned from parsing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2459)#### fn from\_str(s: &str) -> Result<String, <String as FromStr>::Err>
Parses a string `s` to return a value of this type. [Read more](../str/trait.fromstr#tymethod.from_str)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2262)### impl Hash for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2264)#### fn hash<H>(&self, hasher: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2331)### impl Index<Range<usize>> for String
#### type Output = str
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2335)#### fn index(&self, index: Range<usize>) -> &str
Performs the indexing (`container[index]`) operation. [Read more](../ops/trait.index#tymethod.index)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2349)### impl Index<RangeFrom<usize>> for String
#### type Output = str
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2353)#### fn index(&self, index: RangeFrom<usize>) -> &str
Performs the indexing (`container[index]`) operation. [Read more](../ops/trait.index#tymethod.index)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2358)### impl Index<RangeFull> for String
#### type Output = str
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2362)#### fn index(&self, \_index: RangeFull) -> &str
Performs the indexing (`container[index]`) operation. [Read more](../ops/trait.index#tymethod.index)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2367)1.26.0 · ### impl Index<RangeInclusive<usize>> for String
#### type Output = str
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2371)#### fn index(&self, index: RangeInclusive<usize>) -> &str
Performs the indexing (`container[index]`) operation. [Read more](../ops/trait.index#tymethod.index)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2340)### impl Index<RangeTo<usize>> for String
#### type Output = str
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2344)#### fn index(&self, index: RangeTo<usize>) -> &str
Performs the indexing (`container[index]`) operation. [Read more](../ops/trait.index#tymethod.index)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2376)1.26.0 · ### impl Index<RangeToInclusive<usize>> for String
#### type Output = str
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2380)#### fn index(&self, index: RangeToInclusive<usize>) -> &str
Performs the indexing (`container[index]`) operation. [Read more](../ops/trait.index#tymethod.index)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2386)1.3.0 · ### impl IndexMut<Range<usize>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2388)#### fn index\_mut(&mut self, index: Range<usize>) -> &mut str
Performs the mutable indexing (`container[index]`) operation. [Read more](../ops/trait.indexmut#tymethod.index_mut)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2400)1.3.0 · ### impl IndexMut<RangeFrom<usize>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2402)#### fn index\_mut(&mut self, index: RangeFrom<usize>) -> &mut str
Performs the mutable indexing (`container[index]`) operation. [Read more](../ops/trait.indexmut#tymethod.index_mut)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2407)1.3.0 · ### impl IndexMut<RangeFull> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2409)#### fn index\_mut(&mut self, \_index: RangeFull) -> &mut str
Performs the mutable indexing (`container[index]`) operation. [Read more](../ops/trait.indexmut#tymethod.index_mut)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2414)1.26.0 · ### impl IndexMut<RangeInclusive<usize>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2416)#### fn index\_mut(&mut self, index: RangeInclusive<usize>) -> &mut str
Performs the mutable indexing (`container[index]`) operation. [Read more](../ops/trait.indexmut#tymethod.index_mut)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2393)1.3.0 · ### impl IndexMut<RangeTo<usize>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2395)#### fn index\_mut(&mut self, index: RangeTo<usize>) -> &mut str
Performs the mutable indexing (`container[index]`) operation. [Read more](../ops/trait.indexmut#tymethod.index_mut)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2421)1.26.0 · ### impl IndexMut<RangeToInclusive<usize>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2423)#### fn index\_mut(&mut self, index: RangeToInclusive<usize>) -> &mut str
Performs the mutable indexing (`container[index]`) operation. [Read more](../ops/trait.indexmut#tymethod.index_mut)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#365)### impl Ord for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#365)#### fn cmp(&self, other: &String) -> Ordering
This method returns an [`Ordering`](../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2227)### impl<'a, 'b> PartialEq<&'a str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2227)#### fn eq(&self, other: &&'a str) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2227)#### fn ne(&self, other: &&'a str) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2233)### impl<'a, 'b> PartialEq<Cow<'a, str>> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2233)#### fn eq(&self, other: &Cow<'a, str>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2233)#### fn ne(&self, other: &Cow<'a, str>) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2227)### impl<'a, 'b> PartialEq<String> for &'a str
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2227)#### fn eq(&self, other: &String) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2227)#### fn ne(&self, other: &String) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2233)### impl<'a, 'b> PartialEq<String> for Cow<'a, str>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2233)#### fn eq(&self, other: &String) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2233)#### fn ne(&self, other: &String) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2185)### impl PartialEq<String> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2187)#### fn eq(&self, other: &String) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2191)#### fn ne(&self, other: &String) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2226)### impl<'a, 'b> PartialEq<String> for str
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2226)#### fn eq(&self, other: &String) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2226)#### fn ne(&self, other: &String) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2226)### impl<'a, 'b> PartialEq<str> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2226)#### fn eq(&self, other: &str) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2226)#### fn ne(&self, other: &str) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#365)### impl PartialOrd<String> for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#365)#### fn partial\_cmp(&self, other: &String) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2151)### impl<'a, 'b> Pattern<'a> for &'b String
A convenience impl that delegates to the impl for `&str`.
#### Examples
```
assert_eq!(String::from("Hello world").find("world"), Some(6));
```
#### type Searcher = <&'b str as Pattern<'a>>::Searcher
🔬This is a nightly-only experimental API. (`pattern` [#27721](https://github.com/rust-lang/rust/issues/27721))
Associated searcher for this pattern
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2154)#### fn into\_searcher(self, haystack: &'a str) -> <&'b str as Pattern<'a>>::Searcher
🔬This is a nightly-only experimental API. (`pattern` [#27721](https://github.com/rust-lang/rust/issues/27721))
Constructs the associated searcher from `self` and the `haystack` to search in. [Read more](../str/pattern/trait.pattern#tymethod.into_searcher)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2159)#### fn is\_contained\_in(self, haystack: &'a str) -> bool
🔬This is a nightly-only experimental API. (`pattern` [#27721](https://github.com/rust-lang/rust/issues/27721))
Checks whether the pattern matches anywhere in the haystack
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2164)#### fn is\_prefix\_of(self, haystack: &'a str) -> bool
🔬This is a nightly-only experimental API. (`pattern` [#27721](https://github.com/rust-lang/rust/issues/27721))
Checks whether the pattern matches at the front of the haystack
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2169)#### fn strip\_prefix\_of(self, haystack: &'a str) -> Option<&'a str>
🔬This is a nightly-only experimental API. (`pattern` [#27721](https://github.com/rust-lang/rust/issues/27721))
Removes the pattern from the front of haystack, if it matches.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2174)#### fn is\_suffix\_of(self, haystack: &'a str) -> bool
🔬This is a nightly-only experimental API. (`pattern` [#27721](https://github.com/rust-lang/rust/issues/27721))
Checks whether the pattern matches at the back of the haystack
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2179)#### fn strip\_suffix\_of(self, haystack: &'a str) -> Option<&'a str>
🔬This is a nightly-only experimental API. (`pattern` [#27721](https://github.com/rust-lang/rust/issues/27721))
Removes the pattern from the back of haystack, if it matches.
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#969-974)1.16.0 · ### impl ToSocketAddrs for String
#### type Iter = IntoIter<SocketAddr, Global>
Returned iterator over socket addresses which this type may correspond to. [Read more](../net/trait.tosocketaddrs#associatedtype.Iter)
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#971-973)#### fn to\_socket\_addrs(&self) -> Result<IntoIter<SocketAddr>>
Converts this object to an iterator of resolved [`SocketAddr`](../net/enum.socketaddr "SocketAddr")s. [Read more](../net/trait.tosocketaddrs#tymethod.to_socket_addrs)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2588)1.17.0 · ### impl ToString for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2590)#### fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2836)### impl Write for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2838)#### fn write\_str(&mut self, s: &str) -> Result<(), Error>
Writes a string slice into this writer, returning whether the write succeeded. [Read more](../fmt/trait.write#tymethod.write_str)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2844)#### fn write\_char(&mut self, c: char) -> Result<(), Error>
Writes a [`char`](../primitive.char "char") into this writer, returning whether the write succeeded. [Read more](../fmt/trait.write#method.write_char)
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#191)#### fn write\_fmt(&mut self, args: Arguments<'\_>) -> Result<(), Error>
Glue for usage of the [`write!`](../macro.write "write!") macro with implementors of this trait. [Read more](../fmt/trait.write#method.write_fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#365)### impl Eq for String
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#365)### impl StructuralEq for String
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for String
### impl Send for String
### impl Sync for String
### impl Unpin for String
### impl UnwindSafe for String
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::string::FromUtf8Error Struct std::string::FromUtf8Error
=================================
```
pub struct FromUtf8Error { /* private fields */ }
```
A possible error value when converting a `String` from a UTF-8 byte vector.
This type is the error type for the [`from_utf8`](struct.string#method.from_utf8) method on [`String`](struct.string "String"). It is designed in such a way to carefully avoid reallocations: the [`into_bytes`](struct.fromutf8error#method.into_bytes) method will give back the byte vector that was used in the conversion attempt.
The [`Utf8Error`](../str/struct.utf8error "std::str::Utf8Error") type provided by [`std::str`](https://doc.rust-lang.org/core/str/index.html "std::str") represents an error that may occur when converting a slice of [`u8`](../primitive.u8 "u8")s to a [`&str`](../primitive.str "&str"). In this sense, it’s an analogue to `FromUtf8Error`, and you can get one from a `FromUtf8Error` through the [`utf8_error`](struct.fromutf8error#method.utf8_error) method.
Examples
--------
Basic usage:
```
// some invalid bytes, in a vector
let bytes = vec![0, 159];
let value = String::from_utf8(bytes);
assert!(value.is_err());
assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1855)### impl FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1872)1.26.0 · #### pub fn as\_bytes(&self) -> &[u8]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Returns a slice of [`u8`](../primitive.u8 "u8")s bytes that were attempted to convert to a `String`.
##### Examples
Basic usage:
```
// some invalid bytes, in a vector
let bytes = vec![0, 159];
let value = String::from_utf8(bytes);
assert_eq!(&[0, 159], value.unwrap_err().as_bytes());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1896)#### pub fn into\_bytes(self) -> Vec<u8, Global>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Returns the bytes that were attempted to convert to a `String`.
This method is carefully constructed to avoid allocation. It will consume the error, moving out the bytes, so that a copy of the bytes does not need to be made.
##### Examples
Basic usage:
```
// some invalid bytes, in a vector
let bytes = vec![0, 159];
let value = String::from_utf8(bytes);
assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());
```
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1925)#### pub fn utf8\_error(&self) -> Utf8Error
Fetch a `Utf8Error` to get more details about the conversion failure.
The [`Utf8Error`](../str/struct.utf8error "Utf8Error") type provided by [`std::str`](https://doc.rust-lang.org/core/str/index.html "std::str") represents an error that may occur when converting a slice of [`u8`](../primitive.u8 "u8")s to a [`&str`](../primitive.str "&str"). In this sense, it’s an analogue to `FromUtf8Error`. See its documentation for more details on using it.
##### Examples
Basic usage:
```
// some invalid bytes, in a vector
let bytes = vec![0, 159];
let error = String::from_utf8(bytes).unwrap_err().utf8_error();
// the first byte is invalid here
assert_eq!(1, error.valid_up_to());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#406)### impl Clone for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#406)#### fn clone(&self) -> FromUtf8Error
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)### impl Debug for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1931)### impl Display for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1932)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1946)### impl Error for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#1948)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)### impl PartialEq<FromUtf8Error> for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)#### fn eq(&self, other: &FromUtf8Error) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)### impl Eq for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)### impl StructuralEq for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)### impl StructuralPartialEq for FromUtf8Error
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for FromUtf8Error
### impl Send for FromUtf8Error
### impl Sync for FromUtf8Error
### impl Unpin for FromUtf8Error
### impl UnwindSafe for FromUtf8Error
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../error/trait.error "trait std::error::Error") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Type Definition std::string::ParseError Type Definition std::string::ParseError
=======================================
```
pub type ParseError = Infallible;
```
A type alias for [`Infallible`](../convert/enum.infallible "convert::Infallible").
This alias exists for backwards compatibility, and may be eventually deprecated.
rust Struct std::string::Drain Struct std::string::Drain
=========================
```
pub struct Drain<'a> { /* private fields */ }
```
A draining iterator for `String`.
This struct is created by the [`drain`](struct.string#method.drain) method on [`String`](struct.string "String"). See its documentation for more.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2894)### impl<'a> Drain<'a>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2908)1.55.0 · #### pub fn as\_str(&self) -> &str
Returns the remaining (sub)string of this iterator as a slice.
##### Examples
```
let mut s = String::from("abc");
let mut drain = s.drain(..);
assert_eq!(drain.as_str(), "abc");
let _ = drain.next().unwrap();
assert_eq!(drain.as_str(), "bc");
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2921)1.55.0 · ### impl<'a> AsRef<[u8]> for Drain<'a>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2922)#### fn as\_ref(&self) -> &[u8]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Converts this type into a shared reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2914)1.55.0 · ### impl<'a> AsRef<str> for Drain<'a>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2915)#### fn as\_ref(&self) -> &str
Converts this type into a shared reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2869)1.17.0 · ### impl Debug for Drain<'\_>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2870)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2947)### impl DoubleEndedIterator for Drain<'\_>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2949)#### fn next\_back(&mut self) -> Option<char>
Removes and returns an element from the end of the iterator. [Read more](../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2881)### impl Drop for Drain<'\_>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2882)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2928)### impl Iterator for Drain<'\_>
#### type Item = char
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2932)#### fn next(&mut self) -> Option<char>
Advances the iterator and returns the next value. [Read more](../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2936)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2941)#### fn last(self) -> Option<char>
Consumes the iterator, returning the last element. [Read more](../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Notable traits for [Filter](../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../iter/struct.peekable#method.peek) and [`peek_mut`](../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Notable traits for [SkipWhile](../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Notable traits for [TakeWhile](../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../primitive.reference) St, Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../option/enum.option#variant.None "None"). [Read more](../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../default/trait.default "trait std::default::Default") + [Extend](../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../primitive.reference) T>, P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../ops/trait.try "trait std::ops::Try")<Output = [()](../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../ops/trait.try "trait std::ops::Try")>::[Residual](../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../ops/trait.residual "trait std::ops::Residual")<[Option](../option/enum.option "enum std::option::Option")<Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../ops/trait.try "trait std::ops::Try")<Output = [bool](../primitive.bool)>, <R as [Try](../ops/trait.try "trait std::ops::Try")>::[Residual](../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../ops/trait.residual "trait std::ops::Residual")<[Option](../option/enum.option "enum std::option::Option")<Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)#### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)#### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)1.0.0 · #### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../default/trait.default "trait std::default::Default") + [Extend](../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../default/trait.default "trait std::default::Default") + [Extend](../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../primitive.reference) T>,
Notable traits for [Copied](../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../primitive.reference) T>,
Notable traits for [Cloned](../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../iter/trait.product "trait std::iter::Product")<Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../iter/trait.iterator "Iterator") with those of another. [Read more](../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../option/enum.option "enum std::option::Option")<[Ordering](../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../iter/trait.iterator "Iterator") are [lexicographically](../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../iter/trait.iterator "Iterator") are [lexicographically](../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../iter/trait.iterator "Iterator") are [lexicographically](../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../iter/trait.iterator "Iterator") are [lexicographically](../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../option/enum.option "enum std::option::Option")<[Ordering](../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2955)1.26.0 · ### impl FusedIterator for Drain<'\_>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2878)### impl Send for Drain<'\_>
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2876)### impl Sync for Drain<'\_>
Auto Trait Implementations
--------------------------
### impl<'a> RefUnwindSafe for Drain<'a>
### impl<'a> Unpin for Drain<'a>
### impl<'a> UnwindSafe for Drain<'a>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Module std::i128 Module std::i128
================
👎Deprecating in a future Rust version: all constants in this module replaced by associated constants on `i128`
Constants for the 128-bit signed integer type.
*[See also the `i128` primitive type](../primitive.i128 "i128").*
New code should use the associated constants directly on the primitive type.
Constants
---------
[MAX](constant.max "std::i128::MAX constant")Deprecation planned
The largest value that can be represented by this integer type. Use [`i128::MAX`](../primitive.i128#associatedconstant.MAX "i128::MAX") instead.
[MIN](constant.min "std::i128::MIN constant")Deprecation planned
The smallest value that can be represented by this integer type. Use [`i128::MIN`](../primitive.i128#associatedconstant.MIN "i128::MIN") instead.
rust Constant std::i128::MAX Constant std::i128::MAX
=======================
```
pub const MAX: i128 = i128::MAX; // 170_141_183_460_469_231_731_687_303_715_884_105_727i128
```
👎Deprecating in a future Rust version: replaced by the `MAX` associated constant on this type
The largest value that can be represented by this integer type. Use [`i128::MAX`](../primitive.i128#associatedconstant.MAX "i128::MAX") instead.
Examples
--------
```
// deprecated way
let max = std::i128::MAX;
// intended way
let max = i128::MAX;
```
rust Constant std::i128::MIN Constant std::i128::MIN
=======================
```
pub const MIN: i128 = i128::MIN; // -170_141_183_460_469_231_731_687_303_715_884_105_728i128
```
👎Deprecating in a future Rust version: replaced by the `MIN` associated constant on this type
The smallest value that can be represented by this integer type. Use [`i128::MIN`](../primitive.i128#associatedconstant.MIN "i128::MIN") instead.
Examples
--------
```
// deprecated way
let min = std::i128::MIN;
// intended way
let min = i128::MIN;
```
rust Struct std::sync::RwLock Struct std::sync::RwLock
========================
```
pub struct RwLock<T: ?Sized> { /* private fields */ }
```
A reader-writer lock
This type of lock allows a number of readers or at most one writer at any point in time. The write portion of this lock typically allows modification of the underlying data (exclusive access) and the read portion of this lock typically allows for read-only access (shared access).
In comparison, a [`Mutex`](struct.mutex) does not distinguish between readers or writers that acquire the lock, therefore blocking any threads waiting for the lock to become available. An `RwLock` will allow any number of readers to acquire the lock as long as a writer is not holding the lock.
The priority policy of the lock is dependent on the underlying operating system’s implementation, and this type does not guarantee that any particular policy will be used. In particular, a writer which is waiting to acquire the lock in `write` might or might not block concurrent calls to `read`, e.g.:
Potential deadlock example
```
// Thread 1 | // Thread 2
let _rg = lock.read(); |
| // will block
| let _wg = lock.write();
// may deadlock |
let _rg = lock.read(); |
```
The type parameter `T` represents the data that this lock protects. It is required that `T` satisfies [`Send`](../marker/trait.send "Send") to be shared across threads and [`Sync`](../marker/trait.sync "Sync") to allow concurrent access through readers. The RAII guards returned from the locking methods implement [`Deref`](../ops/trait.deref "Deref") (and [`DerefMut`](../ops/trait.derefmut "DerefMut") for the `write` methods) to allow access to the content of the lock.
Poisoning
---------
An `RwLock`, like [`Mutex`](struct.mutex), will become poisoned on a panic. Note, however, that an `RwLock` may only be poisoned if a panic occurs while it is locked exclusively (write mode). If a panic occurs in any reader, then the lock will not be poisoned.
Examples
--------
```
use std::sync::RwLock;
let lock = RwLock::new(5);
// many reader locks can be held at once
{
let r1 = lock.read().unwrap();
let r2 = lock.read().unwrap();
assert_eq!(*r1, 5);
assert_eq!(*r2, 5);
} // read locks are dropped at this point
// only one write lock may be held, however
{
let mut w = lock.write().unwrap();
*w += 1;
assert_eq!(*w, 6);
} // write lock is dropped here
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#146-166)### impl<T> RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#159-165)const: 1.63.0 · #### pub const fn new(t: T) -> RwLock<T>
Creates a new instance of an `RwLock<T>` which is unlocked.
##### Examples
```
use std::sync::RwLock;
let lock = RwLock::new(5);
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#168-476)### impl<T: ?Sized> RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#210-215)#### pub fn read(&self) -> LockResult<RwLockReadGuard<'\_, T>>
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns. This method does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.
Returns an RAII guard which will release this thread’s shared access once it is dropped.
##### Errors
This function will return an error if the RwLock is poisoned. An RwLock is poisoned whenever a writer panics while holding an exclusive lock. The failure will occur immediately after the lock has been acquired.
##### Panics
This function might panic when called if the lock is already held by the current thread.
##### Examples
```
use std::sync::{Arc, RwLock};
use std::thread;
let lock = Arc::new(RwLock::new(1));
let c_lock = Arc::clone(&lock);
let n = lock.read().unwrap();
assert_eq!(*n, 1);
thread::spawn(move || {
let r = c_lock.read();
assert!(r.is_ok());
}).join().unwrap();
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#255-263)#### pub fn try\_read(&self) -> TryLockResult<RwLockReadGuard<'\_, T>>
Attempts to acquire this rwlock with shared read access.
If the access could not be granted at this time, then `Err` is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.
This function does not block.
This function does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.
##### Errors
This function will return the [`Poisoned`](enum.trylockerror#variant.Poisoned) error if the RwLock is poisoned. An RwLock is poisoned whenever a writer panics while holding an exclusive lock. `Poisoned` will only be returned if the lock would have otherwise been acquired.
This function will return the [`WouldBlock`](enum.trylockerror#variant.WouldBlock) error if the RwLock could not be acquired because it was already locked exclusively.
##### Examples
```
use std::sync::RwLock;
let lock = RwLock::new(1);
match lock.try_read() {
Ok(n) => assert_eq!(*n, 1),
Err(_) => unreachable!(),
};
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#298-303)#### pub fn write(&self) -> LockResult<RwLockWriteGuard<'\_, T>>
Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.
This function will not return while other writers or other readers currently have access to the lock.
Returns an RAII guard which will drop the write access of this rwlock when dropped.
##### Errors
This function will return an error if the RwLock is poisoned. An RwLock is poisoned whenever a writer panics while holding an exclusive lock. An error will be returned when the lock is acquired.
##### Panics
This function might panic when called if the lock is already held by the current thread.
##### Examples
```
use std::sync::RwLock;
let lock = RwLock::new(1);
let mut n = lock.write().unwrap();
*n = 2;
assert!(lock.try_read().is_err());
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#344-352)#### pub fn try\_write(&self) -> TryLockResult<RwLockWriteGuard<'\_, T>>
Attempts to lock this rwlock with exclusive write access.
If the lock could not be acquired at this time, then `Err` is returned. Otherwise, an RAII guard is returned which will release the lock when it is dropped.
This function does not block.
This function does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.
##### Errors
This function will return the [`Poisoned`](enum.trylockerror#variant.Poisoned) error if the RwLock is poisoned. An RwLock is poisoned whenever a writer panics while holding an exclusive lock. `Poisoned` will only be returned if the lock would have otherwise been acquired.
This function will return the [`WouldBlock`](enum.trylockerror#variant.WouldBlock) error if the RwLock could not be acquired because it was already locked exclusively.
##### Examples
```
use std::sync::RwLock;
let lock = RwLock::new(1);
let n = lock.read().unwrap();
assert_eq!(*n, 1);
assert!(lock.try_write().is_err());
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#377-379)1.2.0 · #### pub fn is\_poisoned(&self) -> bool
Determines whether the lock is poisoned.
If another thread is active, the lock can still become poisoned at any time. You should not trust a `false` value for program correctness without additional synchronization.
##### Examples
```
use std::sync::{Arc, RwLock};
use std::thread;
let lock = Arc::new(RwLock::new(0));
let c_lock = Arc::clone(&lock);
let _ = thread::spawn(move || {
let _lock = c_lock.write().unwrap();
panic!(); // the lock gets poisoned
}).join();
assert_eq!(lock.is_poisoned(), true);
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#416-418)#### pub fn clear\_poison(&self)
🔬This is a nightly-only experimental API. (`mutex_unpoison` [#96469](https://github.com/rust-lang/rust/issues/96469))
Clear the poisoned state from a lock
If the lock is poisoned, it will remain poisoned until this function is called. This allows recovering from a poisoned state and marking that it has recovered. For example, if the value is overwritten by a known-good value, then the mutex can be marked as un-poisoned. Or possibly, the value could be inspected to determine if it is in a consistent state, and if so the poison is removed.
##### Examples
```
#![feature(mutex_unpoison)]
use std::sync::{Arc, RwLock};
use std::thread;
let lock = Arc::new(RwLock::new(0));
let c_lock = Arc::clone(&lock);
let _ = thread::spawn(move || {
let _lock = c_lock.write().unwrap();
panic!(); // the mutex gets poisoned
}).join();
assert_eq!(lock.is_poisoned(), true);
let guard = lock.write().unwrap_or_else(|mut e| {
**e.get_mut() = 1;
lock.clear_poison();
e.into_inner()
});
assert_eq!(lock.is_poisoned(), false);
assert_eq!(*guard, 1);
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#442-448)1.6.0 · #### pub fn into\_inner(self) -> LockResult<T>where T: [Sized](../marker/trait.sized "trait std::marker::Sized"),
Consumes this `RwLock`, returning the underlying data.
##### Errors
This function will return an error if the RwLock is poisoned. An RwLock is poisoned whenever a writer panics while holding an exclusive lock. An error will only be returned if the lock would have otherwise been acquired.
##### Examples
```
use std::sync::RwLock;
let lock = RwLock::new(String::new());
{
let mut s = lock.write().unwrap();
*s = "modified".to_owned();
}
assert_eq!(lock.into_inner().unwrap(), "modified");
```
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#472-475)1.6.0 · #### pub fn get\_mut(&mut self) -> LockResult<&mut T>
Returns a mutable reference to the underlying data.
Since this call borrows the `RwLock` mutably, no actual locking needs to take place – the mutable borrow statically guarantees no locks exist.
##### Errors
This function will return an error if the RwLock is poisoned. An RwLock is poisoned whenever a writer panics while holding an exclusive lock. An error will only be returned if the lock would have otherwise been acquired.
##### Examples
```
use std::sync::RwLock;
let mut lock = RwLock::new(0);
*lock.get_mut().unwrap() = 10;
assert_eq!(*lock.read().unwrap(), 10);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#479-502)### impl<T: ?Sized + Debug> Debug for RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#480-501)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#505-510)1.10.0 · ### impl<T: Default> Default for RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#507-509)#### fn default() -> RwLock<T>
Creates a new `RwLock<T>`, with the `Default` value for T.
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#513-519)1.24.0 · ### impl<T> From<T> for RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#516-518)#### fn from(t: T) -> Self
Creates a new instance of an `RwLock<T>` which is unlocked. This is equivalent to [`RwLock::new`](struct.rwlock#method.new "RwLock::new").
[source](https://doc.rust-lang.org/src/std/panic.rs.html#72)1.12.0 · ### impl<T: ?Sized> RefUnwindSafe for RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#86)### impl<T: ?Sized + Send> Send for RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#88)### impl<T: ?Sized + Send + Sync> Sync for RwLock<T>
[source](https://doc.rust-lang.org/src/std/panic.rs.html#67)1.9.0 · ### impl<T: ?Sized> UnwindSafe for RwLock<T>
Auto Trait Implementations
--------------------------
### impl<T: ?Sized> Unpin for RwLock<T>where T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#577)### impl<T> From<!> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#578)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: !) -> T
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Type Definition std::sync::TryLockResult Type Definition std::sync::TryLockResult
========================================
```
pub type TryLockResult<Guard> = Result<Guard, TryLockError<Guard>>;
```
A type alias for the result of a nonblocking locking method.
For more information, see [`LockResult`](type.lockresult "LockResult"). A `TryLockResult` doesn’t necessarily hold the associated guard in the [`Err`](../result/enum.result#variant.Err "Err") type as the lock might not have been acquired for other reasons.
rust Struct std::sync::MutexGuard Struct std::sync::MutexGuard
============================
```
pub struct MutexGuard<'a, T: ?Sized + 'a> { /* private fields */ }
```
An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
The data protected by the mutex can be accessed through this guard via its [`Deref`](../ops/trait.deref "Deref") and [`DerefMut`](../ops/trait.derefmut "DerefMut") implementations.
This structure is created by the [`lock`](struct.mutex#method.lock) and [`try_lock`](struct.mutex#method.try_lock) methods on [`Mutex`](struct.mutex "Mutex").
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#535-539)1.16.0 · ### impl<T: ?Sized + Debug> Debug for MutexGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#536-538)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#508-514)### impl<T: ?Sized> Deref for MutexGuard<'\_, T>
#### type Target = T
The resulting type after dereferencing.
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#511-513)#### fn deref(&self) -> &T
Dereferences the value.
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#517-521)### impl<T: ?Sized> DerefMut for MutexGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#518-520)#### fn deref\_mut(&mut self) -> &mut T
Mutably dereferences the value.
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#542-546)1.20.0 · ### impl<T: ?Sized + Display> Display for MutexGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#543-545)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#524-532)### impl<T: ?Sized> Drop for MutexGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#526-531)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#202)### impl<T: ?Sized> !Send for MutexGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#204)1.19.0 · ### impl<T: ?Sized + Sync> Sync for MutexGuard<'\_, T>
Auto Trait Implementations
--------------------------
### impl<'a, T: ?Sized> RefUnwindSafe for MutexGuard<'a, T>
### impl<'a, T: ?Sized> Unpin for MutexGuard<'a, T>
### impl<'a, T: ?Sized> UnwindSafe for MutexGuard<'a, T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Module std::sync Module std::sync
================
Useful synchronization primitives.
### The need for synchronization
Conceptually, a Rust program is a series of operations which will be executed on a computer. The timeline of events happening in the program is consistent with the order of the operations in the code.
Consider the following code, operating on some global static variables:
```
static mut A: u32 = 0;
static mut B: u32 = 0;
static mut C: u32 = 0;
fn main() {
unsafe {
A = 3;
B = 4;
A = A + B;
C = B;
println!("{A} {B} {C}");
C = A;
}
}
```
It appears as if some variables stored in memory are changed, an addition is performed, result is stored in `A` and the variable `C` is modified twice.
When only a single thread is involved, the results are as expected: the line `7 4 4` gets printed.
As for what happens behind the scenes, when optimizations are enabled the final generated machine code might look very different from the code:
* The first store to `C` might be moved before the store to `A` or `B`, *as if* we had written `C = 4; A = 3; B = 4`.
* Assignment of `A + B` to `A` might be removed, since the sum can be stored in a temporary location until it gets printed, with the global variable never getting updated.
* The final result could be determined just by looking at the code at compile time, so [constant folding](https://en.wikipedia.org/wiki/Constant_folding) might turn the whole block into a simple `println!("7 4 4")`.
The compiler is allowed to perform any combination of these optimizations, as long as the final optimized code, when executed, produces the same results as the one without optimizations.
Due to the [concurrency](https://en.wikipedia.org/wiki/Concurrency_(computer_science)) involved in modern computers, assumptions about the program’s execution order are often wrong. Access to global variables can lead to nondeterministic results, **even if** compiler optimizations are disabled, and it is **still possible** to introduce synchronization bugs.
Note that thanks to Rust’s safety guarantees, accessing global (static) variables requires `unsafe` code, assuming we don’t use any of the synchronization primitives in this module.
### Out-of-order execution
Instructions can execute in a different order from the one we define, due to various reasons:
* The **compiler** reordering instructions: If the compiler can issue an instruction at an earlier point, it will try to do so. For example, it might hoist memory loads at the top of a code block, so that the CPU can start [prefetching](https://en.wikipedia.org/wiki/Cache_prefetching) the values from memory.
In single-threaded scenarios, this can cause issues when writing signal handlers or certain kinds of low-level code. Use [compiler fences](atomic/fn.compiler_fence) to prevent this reordering.
* A **single processor** executing instructions [out-of-order](https://en.wikipedia.org/wiki/Out-of-order_execution): Modern CPUs are capable of [superscalar](https://en.wikipedia.org/wiki/Superscalar_processor) execution, i.e., multiple instructions might be executing at the same time, even though the machine code describes a sequential process.
This kind of reordering is handled transparently by the CPU.
* A **multiprocessor** system executing multiple hardware threads at the same time: In multi-threaded scenarios, you can use two kinds of primitives to deal with synchronization:
+ [memory fences](atomic/fn.fence) to ensure memory accesses are made visible to other CPUs in the right order.
+ [atomic operations](atomic/index) to ensure simultaneous access to the same memory location doesn’t lead to undefined behavior.
### Higher-level synchronization objects
Most of the low-level synchronization primitives are quite error-prone and inconvenient to use, which is why the standard library also exposes some higher-level synchronization objects.
These abstractions can be built out of lower-level primitives. For efficiency, the sync objects in the standard library are usually implemented with help from the operating system’s kernel, which is able to reschedule the threads while they are blocked on acquiring a lock.
The following is an overview of the available synchronization objects:
* [`Arc`](struct.arc): Atomically Reference-Counted pointer, which can be used in multithreaded environments to prolong the lifetime of some data until all the threads have finished using it.
* [`Barrier`](struct.barrier): Ensures multiple threads will wait for each other to reach a point in the program, before continuing execution all together.
* [`Condvar`](struct.condvar): Condition Variable, providing the ability to block a thread while waiting for an event to occur.
* [`mpsc`](mpsc/index): Multi-producer, single-consumer queues, used for message-based communication. Can provide a lightweight inter-thread synchronisation mechanism, at the cost of some extra memory.
* [`Mutex`](struct.mutex): Mutual Exclusion mechanism, which ensures that at most one thread at a time is able to access some data.
* [`Once`](struct.once): Used for thread-safe, one-time initialization of a global variable.
* [`RwLock`](struct.rwlock): Provides a mutual exclusion mechanism which allows multiple readers at the same time, while allowing only one writer at a time. In some cases, this can be more efficient than a mutex.
Modules
-------
[atomic](atomic/index "std::sync::atomic mod")
Atomic types
[mpsc](mpsc/index "std::sync::mpsc mod")
Multi-producer, single-consumer FIFO queue communication primitives.
Structs
-------
[Exclusive](struct.exclusive "std::sync::Exclusive struct")Experimental
`Exclusive` provides only *mutable* access, also referred to as *exclusive* access to the underlying value. It provides no *immutable*, or *shared* access to the underlying value.
[LazyLock](struct.lazylock "std::sync::LazyLock struct")Experimental
A value which is initialized on the first access.
[OnceLock](struct.oncelock "std::sync::OnceLock struct")Experimental
A synchronization primitive which can be written to only once.
[Arc](struct.arc "std::sync::Arc struct")
A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
[Barrier](struct.barrier "std::sync::Barrier struct")
A barrier enables multiple threads to synchronize the beginning of some computation.
[BarrierWaitResult](struct.barrierwaitresult "std::sync::BarrierWaitResult struct")
A `BarrierWaitResult` is returned by [`Barrier::wait()`](struct.barrier#method.wait "Barrier::wait()") when all threads in the [`Barrier`](struct.barrier "Barrier") have rendezvoused.
[Condvar](struct.condvar "std::sync::Condvar struct")
A Condition Variable
[Mutex](struct.mutex "std::sync::Mutex struct")
A mutual exclusion primitive useful for protecting shared data
[MutexGuard](struct.mutexguard "std::sync::MutexGuard struct")
An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
[Once](struct.once "std::sync::Once struct")
A synchronization primitive which can be used to run a one-time global initialization. Useful for one-time initialization for FFI or related functionality. This type can only be constructed with [`Once::new()`](struct.once#method.new "Once::new()").
[OnceState](struct.oncestate "std::sync::OnceState struct")
State yielded to [`Once::call_once_force()`](struct.once#method.call_once_force "Once::call_once_force()")’s closure parameter. The state can be used to query the poison status of the [`Once`](struct.once "Once").
[PoisonError](struct.poisonerror "std::sync::PoisonError struct")
A type of error which can be returned whenever a lock is acquired.
[RwLock](struct.rwlock "std::sync::RwLock struct")
A reader-writer lock
[RwLockReadGuard](struct.rwlockreadguard "std::sync::RwLockReadGuard struct")
RAII structure used to release the shared read access of a lock when dropped.
[RwLockWriteGuard](struct.rwlockwriteguard "std::sync::RwLockWriteGuard struct")
RAII structure used to release the exclusive write access of a lock when dropped.
[WaitTimeoutResult](struct.waittimeoutresult "std::sync::WaitTimeoutResult struct")
A type indicating whether a timed wait on a condition variable returned due to a time out or not.
[Weak](struct.weak "std::sync::Weak struct")
`Weak` is a version of [`Arc`](struct.arc "Arc") that holds a non-owning reference to the managed allocation. The allocation is accessed by calling [`upgrade`](struct.weak#method.upgrade) on the `Weak` pointer, which returns an `[Option](../option/enum.option "Option")<[Arc](struct.arc "Arc")<T>>`.
Enums
-----
[TryLockError](enum.trylockerror "std::sync::TryLockError enum")
An enumeration of possible errors associated with a [`TryLockResult`](type.trylockresult "TryLockResult") which can occur while trying to acquire a lock, from the [`try_lock`](struct.mutex#method.try_lock) method on a [`Mutex`](struct.mutex) or the [`try_read`](struct.rwlock#method.try_read) and [`try_write`](struct.rwlock#method.try_write) methods on an [`RwLock`](struct.rwlock).
Constants
---------
[ONCE\_INIT](constant.once_init "std::sync::ONCE_INIT constant")Deprecated
Initialization value for static [`Once`](struct.once "Once") values.
Type Definitions
----------------
[LockResult](type.lockresult "std::sync::LockResult type")
A type alias for the result of a lock method which can be poisoned.
[TryLockResult](type.trylockresult "std::sync::TryLockResult type")
A type alias for the result of a nonblocking locking method.
rust Type Definition std::sync::LockResult Type Definition std::sync::LockResult
=====================================
```
pub type LockResult<Guard> = Result<Guard, PoisonError<Guard>>;
```
A type alias for the result of a lock method which can be poisoned.
The [`Ok`](../result/enum.result#variant.Ok "Ok") variant of this result indicates that the primitive was not poisoned, and the `Guard` is contained within. The [`Err`](../result/enum.result#variant.Err "Err") variant indicates that the primitive was poisoned. Note that the [`Err`](../result/enum.result#variant.Err "Err") variant *also* carries the associated guard, and it can be acquired through the [`into_inner`](struct.poisonerror#method.into_inner) method.
rust Constant std::sync::ONCE_INIT Constant std::sync::ONCE\_INIT
==============================
```
pub const ONCE_INIT: Once;
```
👎Deprecated since 1.38.0: the `new` function is now preferred
Initialization value for static [`Once`](struct.once "Once") values.
Examples
--------
```
use std::sync::{Once, ONCE_INIT};
static START: Once = ONCE_INIT;
```
rust Struct std::sync::LazyLock Struct std::sync::LazyLock
==========================
```
pub struct LazyLock<T, F = fn() -> T> { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
A value which is initialized on the first access.
This type is a thread-safe `Lazy`, and can be used in statics.
Examples
--------
```
#![feature(once_cell)]
use std::collections::HashMap;
use std::sync::LazyLock;
static HASHMAP: LazyLock<HashMap<i32, String>> = LazyLock::new(|| {
println!("initializing");
let mut m = HashMap::new();
m.insert(13, "Spica".to_string());
m.insert(74, "Hoyten".to_string());
m
});
fn main() {
println!("ready");
std::thread::spawn(|| {
println!("{:?}", HASHMAP.get(&13));
}).join().unwrap();
println!("{:?}", HASHMAP.get(&74));
// Prints:
// ready
// initializing
// Some("Spica")
// Some("Hoyten")
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#48-55)### impl<T, F> LazyLock<T, F>
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#52-54)#### pub const fn new(f: F) -> LazyLock<T, F>
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Creates a new lazy value with the given initializing function.
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#57-81)### impl<T, F: FnOnce() -> T> LazyLock<T, F>
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#75-80)#### pub fn force(this: &LazyLock<T, F>) -> &T
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Forces the evaluation of this lazy value and returns a reference to result. This is equivalent to the `Deref` impl, but is explicit.
##### Examples
```
#![feature(once_cell)]
use std::sync::LazyLock;
let lazy = LazyLock::new(|| 92);
assert_eq!(LazyLock::force(&lazy), &92);
assert_eq!(&*lazy, &92);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#100-104)### impl<T: Debug, F> Debug for LazyLock<T, F>
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#101-103)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#92-97)### impl<T: Default> Default for LazyLock<T>
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#94-96)#### fn default() -> LazyLock<T>
Creates a new lazy value using `Default` as the initializing function.
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#84-89)### impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F>
#### type Target = T
The resulting type after dereferencing.
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#86-88)#### fn deref(&self) -> &T
Dereferences the value.
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#116)### impl<T, F: UnwindSafe> RefUnwindSafe for LazyLock<T, F>where [OnceLock](struct.oncelock "struct std::sync::OnceLock")<T>: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#112)### impl<T, F: Send> Sync for LazyLock<T, F>where [OnceLock](struct.oncelock "struct std::sync::OnceLock")<T>: [Sync](../marker/trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#118)### impl<T, F: UnwindSafe> UnwindSafe for LazyLock<T, F>where [OnceLock](struct.oncelock "struct std::sync::OnceLock")<T>: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Auto Trait Implementations
--------------------------
### impl<T, F> Send for LazyLock<T, F>where F: [Send](../marker/trait.send "trait std::marker::Send"), T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T, F> Unpin for LazyLock<T, F>where F: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"), T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::Weak Struct std::sync::Weak
======================
```
pub struct Weak<T>where T: ?Sized,{ /* private fields */ }
```
`Weak` is a version of [`Arc`](struct.arc "Arc") that holds a non-owning reference to the managed allocation. The allocation is accessed by calling [`upgrade`](struct.weak#method.upgrade) on the `Weak` pointer, which returns an `[Option](../option/enum.option "Option")<[Arc](struct.arc "Arc")<T>>`.
Since a `Weak` reference does not count towards ownership, it will not prevent the value stored in the allocation from being dropped, and `Weak` itself makes no guarantees about the value still being present. Thus it may return [`None`](../option/enum.option#variant.None "None") when [`upgrade`](struct.weak#method.upgrade)d. Note however that a `Weak` reference *does* prevent the allocation itself (the backing store) from being deallocated.
A `Weak` pointer is useful for keeping a temporary reference to the allocation managed by [`Arc`](struct.arc "Arc") without preventing its inner value from being dropped. It is also used to prevent circular references between [`Arc`](struct.arc "Arc") pointers, since mutual owning references would never allow either [`Arc`](struct.arc "Arc") to be dropped. For example, a tree could have strong [`Arc`](struct.arc "Arc") pointers from parent nodes to children, and `Weak` pointers from children back to their parents.
The typical way to obtain a `Weak` pointer is to call [`Arc::downgrade`](struct.arc#method.downgrade "Arc::downgrade").
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1783)### impl<T> Weak<T>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1800)1.10.0 (const: [unstable](https://github.com/rust-lang/rust/issues/95091 "Tracking issue for const_weak_new")) · #### pub fn new() -> Weak<T>
Constructs a new `Weak<T>`, without allocating any memory. Calling [`upgrade`](struct.weak#method.upgrade) on the return value always gives [`None`](../option/enum.option#variant.None "None").
##### Examples
```
use std::sync::Weak;
let empty: Weak<i64> = Weak::new();
assert!(empty.upgrade().is_none());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1812)### impl<T> Weak<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1840)1.45.0 · #### pub fn as\_ptr(&self) -> \*const T
Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
The pointer is valid only if there are some strong references. The pointer may be dangling, unaligned or even [`null`](../ptr/fn.null "ptr::null") otherwise.
##### Examples
```
use std::sync::Arc;
use std::ptr;
let strong = Arc::new("hello".to_owned());
let weak = Arc::downgrade(&strong);
// Both point to the same object
assert!(ptr::eq(&*strong, weak.as_ptr()));
// The strong here keeps it alive, so we can still access the object.
assert_eq!("hello", unsafe { &*weak.as_ptr() });
drop(strong);
// But not any more. We can do weak.as_ptr(), but accessing the pointer would lead to
// undefined behaviour.
// assert_eq!("hello", unsafe { &*weak.as_ptr() });
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1884)1.45.0 · #### pub fn into\_raw(self) -> \*const T
Consumes the `Weak<T>` and turns it into a raw pointer.
This converts the weak pointer into a raw pointer, while still preserving the ownership of one weak reference (the weak count is not modified by this operation). It can be turned back into the `Weak<T>` with [`from_raw`](struct.weak#method.from_raw).
The same restrictions of accessing the target of the pointer as with [`as_ptr`](struct.weak#method.as_ptr) apply.
##### Examples
```
use std::sync::{Arc, Weak};
let strong = Arc::new("hello".to_owned());
let weak = Arc::downgrade(&strong);
let raw = weak.into_raw();
assert_eq!(1, Arc::weak_count(&strong));
assert_eq!("hello", unsafe { &*raw });
drop(unsafe { Weak::from_raw(raw) });
assert_eq!(0, Arc::weak_count(&strong));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1932)1.45.0 · #### pub unsafe fn from\_raw(ptr: \*const T) -> Weak<T>
Converts a raw pointer previously created by [`into_raw`](struct.weak#method.into_raw) back into `Weak<T>`.
This can be used to safely get a strong reference (by calling [`upgrade`](struct.weak#method.upgrade) later) or to deallocate the weak count by dropping the `Weak<T>`.
It takes ownership of one weak reference (with the exception of pointers created by [`new`](struct.weak#method.new), as these don’t own anything; the method still works on them).
##### Safety
The pointer must have originated from the [`into_raw`](struct.weak#method.into_raw) and must still own its potential weak reference.
It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this takes ownership of one weak reference currently represented as a raw pointer (the weak count is not modified by this operation) and therefore it must be paired with a previous call to [`into_raw`](struct.weak#method.into_raw).
##### Examples
```
use std::sync::{Arc, Weak};
let strong = Arc::new("hello".to_owned());
let raw_1 = Arc::downgrade(&strong).into_raw();
let raw_2 = Arc::downgrade(&strong).into_raw();
assert_eq!(2, Arc::weak_count(&strong));
assert_eq!("hello", &*unsafe { Weak::from_raw(raw_1) }.upgrade().unwrap());
assert_eq!(1, Arc::weak_count(&strong));
drop(strong);
// Decrement the last weak count.
assert!(unsafe { Weak::from_raw(raw_2) }.upgrade().is_none());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1952)### impl<T> Weak<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1979)#### pub fn upgrade(&self) -> Option<Arc<T>>
Attempts to upgrade the `Weak` pointer to an [`Arc`](struct.arc "Arc"), delaying dropping of the inner value if successful.
Returns [`None`](../option/enum.option#variant.None "None") if the inner value has since been dropped.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
let weak_five = Arc::downgrade(&five);
let strong_five: Option<Arc<_>> = weak_five.upgrade();
assert!(strong_five.is_some());
// Destroy all strong pointers.
drop(strong_five);
drop(five);
assert!(weak_five.upgrade().is_none());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2017)1.41.0 · #### pub fn strong\_count(&self) -> usize
Gets the number of strong (`Arc`) pointers pointing to this allocation.
If `self` was created using [`Weak::new`](struct.weak#method.new "Weak::new"), this will return 0.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2034)1.41.0 · #### pub fn weak\_count(&self) -> usize
Gets an approximation of the number of `Weak` pointers pointing to this allocation.
If `self` was created using [`Weak::new`](struct.weak#method.new "Weak::new"), or if there are no remaining strong pointers, this will return 0.
##### Accuracy
Due to implementation details, the returned value can be off by 1 in either direction when other threads are manipulating any `Arc`s or `Weak`s pointing to the same allocation.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2114)1.39.0 · #### pub fn ptr\_eq(&self, other: &Weak<T>) -> bool
Returns `true` if the two `Weak`s point to the same allocation (similar to [`ptr::eq`](../ptr/fn.eq "ptr::eq")), or if both don’t point to any allocation (because they were created with `Weak::new()`).
##### Notes
Since this compares pointers it means that `Weak::new()` will equal each other, even though they don’t point to any allocation.
##### Examples
```
use std::sync::Arc;
let first_rc = Arc::new(5);
let first = Arc::downgrade(&first_rc);
let second = Arc::downgrade(&first_rc);
assert!(first.ptr_eq(&second));
let third_rc = Arc::new(5);
let third = Arc::downgrade(&third_rc);
assert!(!first.ptr_eq(&third));
```
Comparing `Weak::new`.
```
use std::sync::{Arc, Weak};
let first = Weak::new();
let second = Weak::new();
assert!(first.ptr_eq(&second));
let third_rc = Arc::new(());
let third = Arc::downgrade(&third_rc);
assert!(!first.ptr_eq(&third));
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2120)### impl<T> Clone for Weak<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2133)#### fn clone(&self) -> Weak<T>
Makes a clone of the `Weak` pointer that points to the same allocation.
##### Examples
```
use std::sync::{Arc, Weak};
let weak_five = Arc::downgrade(&Arc::new(5));
let _ = Weak::clone(&weak_five);
```
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#306)### impl<T> Debug for Weak<T>where T: [Debug](../fmt/trait.debug "trait std::fmt::Debug") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#307)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2155)1.10.0 · ### impl<T> Default for Weak<T>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2170)#### fn default() -> Weak<T>
Constructs a new `Weak<T>`, without allocating memory. Calling [`upgrade`](struct.weak#method.upgrade) on the return value always gives [`None`](../option/enum.option#variant.None "None").
##### Examples
```
use std::sync::Weak;
let empty: Weak<i64> = Default::default();
assert!(empty.upgrade().is_none());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2176)### impl<T> Drop for Weak<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2201)#### fn drop(&mut self)
Drops the `Weak` pointer.
##### Examples
```
use std::sync::{Arc, Weak};
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("dropped!");
}
}
let foo = Arc::new(Foo);
let weak_foo = Arc::downgrade(&foo);
let other_weak_foo = Weak::clone(&weak_foo);
drop(weak_foo); // Doesn't print anything
drop(foo); // Prints "dropped!"
assert!(other_weak_foo.upgrade().is_none());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#301)### impl<T, U> CoerceUnsized<Weak<U>> for Weak<T>where T: [Unsize](../marker/trait.unsize "trait std::marker::Unsize")<U> + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), U: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#303)### impl<T, U> DispatchFromDyn<Weak<U>> for Weak<T>where T: [Unsize](../marker/trait.unsize "trait std::marker::Unsize")<U> + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), U: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#296)### impl<T> Send for Weak<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync") + [Send](../marker/trait.send "trait std::marker::Send") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#298)### impl<T> Sync for Weak<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync") + [Send](../marker/trait.send "trait std::marker::Send") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Auto Trait Implementations
--------------------------
### impl<T: ?Sized> RefUnwindSafe for Weak<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T: ?Sized> Unpin for Weak<T>
### impl<T: ?Sized> UnwindSafe for Weak<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::Arc Struct std::sync::Arc
=====================
```
pub struct Arc<T>where T: ?Sized,{ /* private fields */ }
```
A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
The type `Arc<T>` provides shared ownership of a value of type `T`, allocated in the heap. Invoking [`clone`](../clone/trait.clone#tymethod.clone) on `Arc` produces a new `Arc` instance, which points to the same allocation on the heap as the source `Arc`, while increasing a reference count. When the last `Arc` pointer to a given allocation is destroyed, the value stored in that allocation (often referred to as “inner value”) is also dropped.
Shared references in Rust disallow mutation by default, and `Arc` is no exception: you cannot generally obtain a mutable reference to something inside an `Arc`. If you need to mutate through an `Arc`, use [`Mutex`](struct.mutex), [`RwLock`](struct.rwlock), or one of the [`Atomic`](atomic/index) types.
### Thread Safety
Unlike [`Rc<T>`](../rc/struct.rc), `Arc<T>` uses atomic operations for its reference counting. This means that it is thread-safe. The disadvantage is that atomic operations are more expensive than ordinary memory accesses. If you are not sharing reference-counted allocations between threads, consider using [`Rc<T>`](../rc/struct.rc) for lower overhead. [`Rc<T>`](../rc/struct.rc) is a safe default, because the compiler will catch any attempt to send an [`Rc<T>`](../rc/struct.rc) between threads. However, a library might choose `Arc<T>` in order to give library consumers more flexibility.
`Arc<T>` will implement [`Send`](../marker/trait.send) and [`Sync`](../marker/trait.sync) as long as the `T` implements [`Send`](../marker/trait.send) and [`Sync`](../marker/trait.sync). Why can’t you put a non-thread-safe type `T` in an `Arc<T>` to make it thread-safe? This may be a bit counter-intuitive at first: after all, isn’t the point of `Arc<T>` thread safety? The key is this: `Arc<T>` makes it thread safe to have multiple ownership of the same data, but it doesn’t add thread safety to its data. Consider `Arc<[RefCell<T>](../cell/struct.refcell)>`. [`RefCell<T>`](../cell/struct.refcell) isn’t [`Sync`](../marker/trait.sync), and if `Arc<T>` was always [`Send`](../marker/trait.send), `Arc<[RefCell<T>](../cell/struct.refcell)>` would be as well. But then we’d have a problem: [`RefCell<T>`](../cell/struct.refcell) is not thread safe; it keeps track of the borrowing count using non-atomic operations.
In the end, this means that you may need to pair `Arc<T>` with some sort of [`std::sync`](index) type, usually [`Mutex<T>`](struct.mutex).
### Breaking cycles with `Weak`
The [`downgrade`](struct.arc#method.downgrade) method can be used to create a non-owning [`Weak`](struct.weak "Weak") pointer. A [`Weak`](struct.weak "Weak") pointer can be [`upgrade`](struct.weak#method.upgrade)d to an `Arc`, but this will return [`None`](../option/enum.option#variant.None "None") if the value stored in the allocation has already been dropped. In other words, `Weak` pointers do not keep the value inside the allocation alive; however, they *do* keep the allocation (the backing store for the value) alive.
A cycle between `Arc` pointers will never be deallocated. For this reason, [`Weak`](struct.weak "Weak") is used to break cycles. For example, a tree could have strong `Arc` pointers from parent nodes to children, and [`Weak`](struct.weak "Weak") pointers from children back to their parents.
Cloning references
------------------
Creating a new reference from an existing reference-counted pointer is done using the `Clone` trait implemented for [`Arc<T>`](struct.arc "Arc") and [`Weak<T>`](struct.weak "Weak").
```
use std::sync::Arc;
let foo = Arc::new(vec![1.0, 2.0, 3.0]);
// The two syntaxes below are equivalent.
let a = foo.clone();
let b = Arc::clone(&foo);
// a, b, and foo are all Arcs that point to the same memory location
```
###
`Deref` behavior
`Arc<T>` automatically dereferences to `T` (via the [`Deref`](../ops/trait.deref) trait), so you can call `T`’s methods on a value of type `Arc<T>`. To avoid name clashes with `T`’s methods, the methods of `Arc<T>` itself are associated functions, called using [fully qualified syntax](../../book/ch19-03-advanced-traits#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name):
```
use std::sync::Arc;
let my_arc = Arc::new(());
let my_weak = Arc::downgrade(&my_arc);
```
`Arc<T>`’s implementations of traits like `Clone` may also be called using fully qualified syntax. Some people prefer to use fully qualified syntax, while others prefer using method-call syntax.
```
use std::sync::Arc;
let arc = Arc::new(());
// Method-call syntax
let arc2 = arc.clone();
// Fully qualified syntax
let arc3 = Arc::clone(&arc);
```
[`Weak<T>`](struct.weak "Weak") does not auto-dereference to `T`, because the inner value may have already been dropped.
Examples
--------
Sharing some immutable data between threads:
```
use std::sync::Arc;
use std::thread;
let five = Arc::new(5);
for _ in 0..10 {
let five = Arc::clone(&five);
thread::spawn(move || {
println!("{five:?}");
});
}
```
Sharing a mutable [`AtomicUsize`](atomic/struct.atomicusize "sync::atomic::AtomicUsize"):
```
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
let val = Arc::new(AtomicUsize::new(5));
for _ in 0..10 {
let val = Arc::clone(&val);
thread::spawn(move || {
let v = val.fetch_add(1, Ordering::SeqCst);
println!("{v:?}");
});
}
```
See the [`rc` documentation](../rc/index#examples) for more examples of reference counting in general.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#330)### impl<T> Arc<T>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#343)#### pub fn new(data: T) -> Arc<T>
Constructs a new `Arc<T>`.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#408-410)1.60.0 · #### pub fn new\_cyclic<F>(data\_fn: F) -> Arc<T>where F: [FnOnce](../ops/trait.fnonce "trait std::ops::FnOnce")(&[Weak](struct.weak "struct std::sync::Weak")<T>) -> T,
Constructs a new `Arc<T>` while giving you a `Weak<T>` to the allocation, to allow you to construct a `T` which holds a weak pointer to itself.
Generally, a structure circularly referencing itself, either directly or indirectly, should not hold a strong reference to itself to prevent a memory leak. Using this function, you get access to the weak pointer during the initialization of `T`, before the `Arc<T>` is created, such that you can clone and store it inside the `T`.
`new_cyclic` first allocates the managed allocation for the `Arc<T>`, then calls your closure, giving it a `Weak<T>` to this allocation, and only afterwards completes the construction of the `Arc<T>` by placing the `T` returned from your closure into the allocation.
Since the new `Arc<T>` is not fully-constructed until `Arc<T>::new_cyclic` returns, calling [`upgrade`](struct.weak#method.upgrade) on the weak reference inside your closure will fail and result in a `None` value.
##### Panics
If `data_fn` panics, the panic is propagated to the caller, and the temporary [`Weak<T>`](struct.weak "Weak<T>") is dropped normally.
##### Example
```
use std::sync::{Arc, Weak};
struct Gadget {
me: Weak<Gadget>,
}
impl Gadget {
/// Construct a reference counted Gadget.
fn new() -> Arc<Self> {
// `me` is a `Weak<Gadget>` pointing at the new allocation of the
// `Arc` we're constructing.
Arc::new_cyclic(|me| {
// Create the actual struct here.
Gadget { me: me.clone() }
})
}
/// Return a reference counted pointer to Self.
fn me(&self) -> Arc<Self> {
self.me.upgrade().unwrap()
}
}
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#484)#### pub fn new\_uninit() -> Arc<MaybeUninit<T>>
🔬This is a nightly-only experimental API. (`new_uninit` [#63291](https://github.com/rust-lang/rust/issues/63291))
Constructs a new `Arc` with uninitialized contents.
##### Examples
```
#![feature(new_uninit)]
#![feature(get_mut_unchecked)]
use std::sync::Arc;
let mut five = Arc::<u32>::new_uninit();
// Deferred initialization:
Arc::get_mut(&mut five).unwrap().write(5);
let five = unsafe { five.assume_init() };
assert_eq!(*five, 5)
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#517)#### pub fn new\_zeroed() -> Arc<MaybeUninit<T>>
🔬This is a nightly-only experimental API. (`new_uninit` [#63291](https://github.com/rust-lang/rust/issues/63291))
Constructs a new `Arc` with uninitialized contents, with the memory being filled with `0` bytes.
See [`MaybeUninit::zeroed`](../mem/union.maybeuninit#method.zeroed) for examples of correct and incorrect usage of this method.
##### Examples
```
#![feature(new_uninit)]
use std::sync::Arc;
let zero = Arc::<u32>::new_zeroed();
let zero = unsafe { zero.assume_init() };
assert_eq!(*zero, 0)
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#532)1.33.0 · #### pub fn pin(data: T) -> Pin<Arc<T>>
Notable traits for [Pin](../pin/struct.pin "struct std::pin::Pin")<P>
```
impl<P> Future for Pin<P>where
P: DerefMut,
<P as Deref>::Target: Future,
type Output = <<P as Deref>::Target as Future>::Output;
```
Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then `data` will be pinned in memory and unable to be moved.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#539)#### pub fn try\_pin(data: T) -> Result<Pin<Arc<T>>, AllocError>
🔬This is a nightly-only experimental API. (`allocator_api` [#32838](https://github.com/rust-lang/rust/issues/32838))
Constructs a new `Pin<Arc<T>>`, return an error if allocation fails.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#556)#### pub fn try\_new(data: T) -> Result<Arc<T>, AllocError>
🔬This is a nightly-only experimental API. (`allocator_api` [#32838](https://github.com/rust-lang/rust/issues/32838))
Constructs a new `Arc<T>`, returning an error if allocation fails.
##### Examples
```
#![feature(allocator_api)]
use std::sync::Arc;
let five = Arc::try_new(5)?;
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#590)#### pub fn try\_new\_uninit() -> Result<Arc<MaybeUninit<T>>, AllocError>
🔬This is a nightly-only experimental API. (`allocator_api` [#32838](https://github.com/rust-lang/rust/issues/32838))
Constructs a new `Arc` with uninitialized contents, returning an error if allocation fails.
##### Examples
```
#![feature(new_uninit, allocator_api)]
#![feature(get_mut_unchecked)]
use std::sync::Arc;
let mut five = Arc::<u32>::try_new_uninit()?;
// Deferred initialization:
Arc::get_mut(&mut five).unwrap().write(5);
let five = unsafe { five.assume_init() };
assert_eq!(*five, 5);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#623)#### pub fn try\_new\_zeroed() -> Result<Arc<MaybeUninit<T>>, AllocError>
🔬This is a nightly-only experimental API. (`allocator_api` [#32838](https://github.com/rust-lang/rust/issues/32838))
Constructs a new `Arc` with uninitialized contents, with the memory being filled with `0` bytes, returning an error if allocation fails.
See [`MaybeUninit::zeroed`](../mem/union.maybeuninit#method.zeroed) for examples of correct and incorrect usage of this method.
##### Examples
```
#![feature(new_uninit, allocator_api)]
use std::sync::Arc;
let zero = Arc::<u32>::try_new_zeroed()?;
let zero = unsafe { zero.assume_init() };
assert_eq!(*zero, 0);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#653)1.4.0 · #### pub fn try\_unwrap(this: Arc<T>) -> Result<T, Arc<T>>
Returns the inner value, if the `Arc` has exactly one strong reference.
Otherwise, an [`Err`](../result/enum.result#variant.Err "Err") is returned with the same `Arc` that was passed in.
This will succeed even if there are outstanding weak references.
##### Examples
```
use std::sync::Arc;
let x = Arc::new(3);
assert_eq!(Arc::try_unwrap(x), Ok(3));
let x = Arc::new(4);
let _y = Arc::clone(&x);
assert_eq!(*Arc::try_unwrap(x).unwrap_err(), 4);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#672)### impl<T> Arc<[T]>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#698)#### pub fn new\_uninit\_slice(len: usize) -> Arc<[MaybeUninit<T>]>
🔬This is a nightly-only experimental API. (`new_uninit` [#63291](https://github.com/rust-lang/rust/issues/63291))
Constructs a new atomically reference-counted slice with uninitialized contents.
##### Examples
```
#![feature(new_uninit)]
#![feature(get_mut_unchecked)]
use std::sync::Arc;
let mut values = Arc::<[u32]>::new_uninit_slice(3);
// Deferred initialization:
let data = Arc::get_mut(&mut values).unwrap();
data[0].write(1);
data[1].write(2);
data[2].write(3);
let values = unsafe { values.assume_init() };
assert_eq!(*values, [1, 2, 3])
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#725)#### pub fn new\_zeroed\_slice(len: usize) -> Arc<[MaybeUninit<T>]>
🔬This is a nightly-only experimental API. (`new_uninit` [#63291](https://github.com/rust-lang/rust/issues/63291))
Constructs a new atomically reference-counted slice with uninitialized contents, with the memory being filled with `0` bytes.
See [`MaybeUninit::zeroed`](../mem/union.maybeuninit#method.zeroed) for examples of correct and incorrect usage of this method.
##### Examples
```
#![feature(new_uninit)]
use std::sync::Arc;
let values = Arc::<[u32]>::new_zeroed_slice(3);
let values = unsafe { values.assume_init() };
assert_eq!(*values, [0, 0, 0])
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#739)### impl<T> Arc<MaybeUninit<T>>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#772)#### pub unsafe fn assume\_init(self) -> Arc<T>
🔬This is a nightly-only experimental API. (`new_uninit` [#63291](https://github.com/rust-lang/rust/issues/63291))
Converts to `Arc<T>`.
##### Safety
As with [`MaybeUninit::assume_init`](../mem/union.maybeuninit#method.assume_init), it is up to the caller to guarantee that the inner value really is in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behavior.
##### Examples
```
#![feature(new_uninit)]
#![feature(get_mut_unchecked)]
use std::sync::Arc;
let mut five = Arc::<u32>::new_uninit();
// Deferred initialization:
Arc::get_mut(&mut five).unwrap().write(5);
let five = unsafe { five.assume_init() };
assert_eq!(*five, 5)
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#777)### impl<T> Arc<[MaybeUninit<T>]>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#813)#### pub unsafe fn assume\_init(self) -> Arc<[T]>
🔬This is a nightly-only experimental API. (`new_uninit` [#63291](https://github.com/rust-lang/rust/issues/63291))
Converts to `Arc<[T]>`.
##### Safety
As with [`MaybeUninit::assume_init`](../mem/union.maybeuninit#method.assume_init), it is up to the caller to guarantee that the inner value really is in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behavior.
##### Examples
```
#![feature(new_uninit)]
#![feature(get_mut_unchecked)]
use std::sync::Arc;
let mut values = Arc::<[u32]>::new_uninit_slice(3);
// Deferred initialization:
let data = Arc::get_mut(&mut values).unwrap();
data[0].write(1);
data[1].write(2);
data[2].write(3);
let values = unsafe { values.assume_init() };
assert_eq!(*values, [1, 2, 3])
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#818)### impl<T> Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#835)1.17.0 · #### pub fn into\_raw(this: Arc<T>) -> \*const T
Consumes the `Arc`, returning the wrapped pointer.
To avoid a memory leak the pointer must be converted back to an `Arc` using [`Arc::from_raw`](struct.arc#method.from_raw "Arc::from_raw").
##### Examples
```
use std::sync::Arc;
let x = Arc::new("hello".to_owned());
let x_ptr = Arc::into_raw(x);
assert_eq!(unsafe { &*x_ptr }, "hello");
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#859)1.45.0 · #### pub fn as\_ptr(this: &Arc<T>) -> \*const T
Provides a raw pointer to the data.
The counts are not affected in any way and the `Arc` is not consumed. The pointer is valid for as long as there are strong counts in the `Arc`.
##### Examples
```
use std::sync::Arc;
let x = Arc::new("hello".to_owned());
let y = Arc::clone(&x);
let x_ptr = Arc::as_ptr(&x);
assert_eq!(x_ptr, Arc::as_ptr(&y));
assert_eq!(unsafe { &*x_ptr }, "hello");
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#906)1.17.0 · #### pub unsafe fn from\_raw(ptr: \*const T) -> Arc<T>
Constructs an `Arc<T>` from a raw pointer.
The raw pointer must have been previously returned by a call to [`Arc<U>::into_raw`](struct.arc#method.into_raw) where `U` must have the same size and alignment as `T`. This is trivially true if `U` is `T`. Note that if `U` is not `T` but has the same size and alignment, this is basically like transmuting references of different types. See [`mem::transmute`](../mem/fn.transmute) for more information on what restrictions apply in this case.
The user of `from_raw` has to make sure a specific value of `T` is only dropped once.
This function is unsafe because improper use may lead to memory unsafety, even if the returned `Arc<T>` is never accessed.
##### Examples
```
use std::sync::Arc;
let x = Arc::new("hello".to_owned());
let x_ptr = Arc::into_raw(x);
unsafe {
// Convert back to an `Arc` to prevent leak.
let x = Arc::from_raw(x_ptr);
assert_eq!(&*x, "hello");
// Further calls to `Arc::from_raw(x_ptr)` would be memory-unsafe.
}
// The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#931)1.4.0 · #### pub fn downgrade(this: &Arc<T>) -> Weak<T>
Creates a new [`Weak`](struct.weak "Weak") pointer to this allocation.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
let weak_five = Arc::downgrade(&five);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#985)1.15.0 · #### pub fn weak\_count(this: &Arc<T>) -> usize
Gets the number of [`Weak`](struct.weak "Weak") pointers to this allocation.
##### Safety
This method by itself is safe, but using it correctly requires extra care. Another thread can change the weak count at any time, including potentially between calling this method and acting on the result.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
let _weak_five = Arc::downgrade(&five);
// This assertion is deterministic because we haven't shared
// the `Arc` or `Weak` between threads.
assert_eq!(1, Arc::weak_count(&five));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1015)1.15.0 · #### pub fn strong\_count(this: &Arc<T>) -> usize
Gets the number of strong (`Arc`) pointers to this allocation.
##### Safety
This method by itself is safe, but using it correctly requires extra care. Another thread can change the strong count at any time, including potentially between calling this method and acting on the result.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
let _also_five = Arc::clone(&five);
// This assertion is deterministic because we haven't shared
// the `Arc` between threads.
assert_eq!(2, Arc::strong_count(&five));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1047)1.51.0 · #### pub unsafe fn increment\_strong\_count(ptr: \*const T)
Increments the strong reference count on the `Arc<T>` associated with the provided pointer by one.
##### Safety
The pointer must have been obtained through `Arc::into_raw`, and the associated `Arc` instance must be valid (i.e. the strong count must be at least 1) for the duration of this method.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
unsafe {
let ptr = Arc::into_raw(five);
Arc::increment_strong_count(ptr);
// This assertion is deterministic because we haven't shared
// the `Arc` between threads.
let five = Arc::from_raw(ptr);
assert_eq!(2, Arc::strong_count(&five));
}
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1086)1.51.0 · #### pub unsafe fn decrement\_strong\_count(ptr: \*const T)
Decrements the strong reference count on the `Arc<T>` associated with the provided pointer by one.
##### Safety
The pointer must have been obtained through `Arc::into_raw`, and the associated `Arc` instance must be valid (i.e. the strong count must be at least 1) when invoking this method. This method can be used to release the final `Arc` and backing storage, but **should not** be called after the final `Arc` has been released.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
unsafe {
let ptr = Arc::into_raw(five);
Arc::increment_strong_count(ptr);
// Those assertions are deterministic because we haven't shared
// the `Arc` between threads.
let five = Arc::from_raw(ptr);
assert_eq!(2, Arc::strong_count(&five));
Arc::decrement_strong_count(ptr);
assert_eq!(1, Arc::strong_count(&five));
}
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1131)1.17.0 · #### pub fn ptr\_eq(this: &Arc<T>, other: &Arc<T>) -> bool
Returns `true` if the two `Arc`s point to the same allocation (in a vein similar to [`ptr::eq`](../ptr/fn.eq "ptr::eq")).
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
let same_five = Arc::clone(&five);
let other_five = Arc::new(5);
assert!(Arc::ptr_eq(&five, &same_five));
assert!(!Arc::ptr_eq(&five, &other_five));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1388)### impl<T> Arc<T>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1442)1.4.0 · #### pub fn make\_mut(this: &mut Arc<T>) -> &mut T
Makes a mutable reference into the given `Arc`.
If there are other `Arc` pointers to the same allocation, then `make_mut` will [`clone`](../clone/trait.clone#tymethod.clone) the inner value to a new allocation to ensure unique ownership. This is also referred to as clone-on-write.
However, if there are no other `Arc` pointers to this allocation, but some [`Weak`](struct.weak "Weak") pointers, then the [`Weak`](struct.weak "Weak") pointers will be dissociated and the inner value will not be cloned.
See also [`get_mut`](struct.arc#method.get_mut), which will fail rather than cloning the inner value or dissociating [`Weak`](struct.weak "Weak") pointers.
##### Examples
```
use std::sync::Arc;
let mut data = Arc::new(5);
*Arc::make_mut(&mut data) += 1; // Won't clone anything
let mut other_data = Arc::clone(&data); // Won't clone inner data
*Arc::make_mut(&mut data) += 1; // Clones inner data
*Arc::make_mut(&mut data) += 1; // Won't clone anything
*Arc::make_mut(&mut other_data) *= 2; // Won't clone anything
// Now `data` and `other_data` point to different allocations.
assert_eq!(*data, 8);
assert_eq!(*other_data, 12);
```
[`Weak`](struct.weak "Weak") pointers will be dissociated:
```
use std::sync::Arc;
let mut data = Arc::new(75);
let weak = Arc::downgrade(&data);
assert!(75 == *data);
assert!(75 == *weak.upgrade().unwrap());
*Arc::make_mut(&mut data) += 1;
assert!(76 == *data);
assert!(weak.upgrade().is_none());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1526)#### pub fn unwrap\_or\_clone(this: Arc<T>) -> T
🔬This is a nightly-only experimental API. (`arc_unwrap_or_clone` [#93610](https://github.com/rust-lang/rust/issues/93610))
If we have the only reference to `T` then unwrap it. Otherwise, clone `T` and return the clone.
Assuming `arc_t` is of type `Arc<T>`, this function is functionally equivalent to `(*arc_t).clone()`, but will avoid cloning the inner value where possible.
##### Examples
```
#![feature(arc_unwrap_or_clone)]
let inner = String::from("test");
let ptr = inner.as_ptr();
let arc = Arc::new(inner);
let inner = Arc::unwrap_or_clone(arc);
// The inner value was not cloned
assert!(ptr::eq(ptr, inner.as_ptr()));
let arc = Arc::new(inner);
let arc2 = arc.clone();
let inner = Arc::unwrap_or_clone(arc);
// Because there were 2 references, we had to clone the inner value.
assert!(!ptr::eq(ptr, inner.as_ptr()));
// `arc2` is the last reference, so when we unwrap it we get back
// the original `String`.
let inner = Arc::unwrap_or_clone(arc2);
assert!(ptr::eq(ptr, inner.as_ptr()));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1531)### impl<T> Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1558)1.4.0 · #### pub fn get\_mut(this: &mut Arc<T>) -> Option<&mut T>
Returns a mutable reference into the given `Arc`, if there are no other `Arc` or [`Weak`](struct.weak "Weak") pointers to the same allocation.
Returns [`None`](../option/enum.option#variant.None "None") otherwise, because it is not safe to mutate a shared value.
See also [`make_mut`](struct.arc#method.make_mut), which will [`clone`](../clone/trait.clone#tymethod.clone) the inner value when there are other `Arc` pointers.
##### Examples
```
use std::sync::Arc;
let mut x = Arc::new(3);
*Arc::get_mut(&mut x).unwrap() = 4;
assert_eq!(*x, 4);
let _y = Arc::clone(&x);
assert!(Arc::get_mut(&mut x).is_none());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1600)#### pub unsafe fn get\_mut\_unchecked(this: &mut Arc<T>) -> &mut T
🔬This is a nightly-only experimental API. (`get_mut_unchecked` [#63292](https://github.com/rust-lang/rust/issues/63292))
Returns a mutable reference into the given `Arc`, without any check.
See also [`get_mut`](struct.arc#method.get_mut), which is safe and does appropriate checks.
##### Safety
Any other `Arc` or [`Weak`](struct.weak "Weak") pointers to the same allocation must not be dereferenced for the duration of the returned borrow. This is trivially the case if no such pointers exist, for example immediately after `Arc::new`.
##### Examples
```
#![feature(get_mut_unchecked)]
use std::sync::Arc;
let mut x = Arc::new(String::new());
unsafe {
Arc::get_mut_unchecked(&mut x).push_str("foo")
}
assert_eq!(*x, "foo");
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1707)### impl Arc<dyn Any + Send + Sync + 'static>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1728-1730)1.29.0 · #### pub fn downcast<T>(self) -> Result<Arc<T>, Arc<dyn Any + Send + Sync + 'static>>where T: [Any](../any/trait.any "trait std::any::Any") + [Send](../marker/trait.send "trait std::marker::Send") + [Sync](../marker/trait.sync "trait std::marker::Sync"),
Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
##### Examples
```
use std::any::Any;
use std::sync::Arc;
fn print_if_string(value: Arc<dyn Any + Send + Sync>) {
if let Ok(string) = value.downcast::<String>() {
println!("String ({}): {}", string.len(), string);
}
}
let my_string = "Hello World".to_string();
print_if_string(Arc::new(my_string));
print_if_string(Arc::new(0i8));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1771-1773)#### pub unsafe fn downcast\_unchecked<T>(self) -> Arc<T>where T: [Any](../any/trait.any "trait std::any::Any") + [Send](../marker/trait.send "trait std::marker::Send") + [Sync](../marker/trait.sync "trait std::marker::Sync"),
🔬This is a nightly-only experimental API. (`downcast_unchecked` [#90850](https://github.com/rust-lang/rust/issues/90850))
Downcasts the `Arc<dyn Any + Send + Sync>` to a concrete type.
For a safe alternative see [`downcast`](struct.arc#method.downcast).
##### Examples
```
#![feature(downcast_unchecked)]
use std::any::Any;
use std::sync::Arc;
let x: Arc<dyn Any + Send + Sync> = Arc::new(1_usize);
unsafe {
assert_eq!(*x.downcast_unchecked::<usize>(), 1);
}
```
##### Safety
The contained value must be of type `T`. Calling this method with the incorrect type is *undefined behavior*.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#376-381)1.64.0 · ### impl<T: AsFd> AsFd for Arc<T>
This impl allows implementing traits that require `AsFd` on Arc.
```
use std::net::UdpSocket;
use std::sync::Arc;
trait MyTrait: AsFd {}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}
```
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#378-380)#### fn as\_fd(&self) -> BorrowedFd<'\_>
Available on **Unix** only.Borrows the file descriptor. [Read more](../os/unix/io/trait.asfd#tymethod.as_fd)
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#246-251)1.63.0 · ### impl<T: AsRawFd> AsRawFd for Arc<T>
This impl allows implementing traits that require `AsRawFd` on Arc.
```
use std::net::UdpSocket;
use std::sync::Arc;
trait MyTrait: AsRawFd {
}
impl MyTrait for Arc<UdpSocket> {}
impl MyTrait for Box<UdpSocket> {}
```
[source](https://doc.rust-lang.org/src/std/os/fd/raw.rs.html#248-250)#### fn as\_raw\_fd(&self) -> RawFd
Available on **Unix** only.Extracts the raw file descriptor. [Read more](../os/unix/io/trait.asrawfd#tymethod.as_raw_fd)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2736)1.5.0 · ### impl<T> AsRef<T> for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2737)#### fn as\_ref(&self) -> &T
Converts this type into a shared reference of the (usually inferred) input type.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2729)### impl<T> Borrow<T> for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2730)#### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1327)### impl<T> Clone for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1343)#### fn clone(&self) -> Arc<T>
Makes a clone of the `Arc` pointer.
This creates another pointer to the same allocation, increasing the strong reference count.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
let _ = Arc::clone(&five);
```
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2422)### impl<T> Debug for Arc<T>where T: [Debug](../fmt/trait.debug "trait std::fmt::Debug") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2423)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2437)### impl<T> Default for Arc<T>where T: [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2448)#### fn default() -> Arc<T>
Creates a new `Arc<T>`, with the `Default` value for `T`.
##### Examples
```
use std::sync::Arc;
let x: Arc<i32> = Default::default();
assert_eq!(*x, 0);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1376)### impl<T> Deref for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
#### type Target = T
The resulting type after dereferencing.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1380)#### fn deref(&self) -> &T
Dereferences the value.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2415)### impl<T> Display for Arc<T>where T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2416)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1636)### impl<T> Drop for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#1663)#### fn drop(&mut self)
Drops the `Arc`.
This will decrement the strong reference count. If the strong reference count reaches zero then the only other references (if any) are [`Weak`](struct.weak "Weak"), so we `drop` the inner value.
##### Examples
```
use std::sync::Arc;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("dropped!");
}
}
let foo = Arc::new(Foo);
let foo2 = Arc::clone(&foo);
drop(foo); // Doesn't print anything
drop(foo2); // Prints "dropped!"
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2769)1.52.0 · ### impl<T> Error for Arc<T>where T: [Error](../error/trait.error "trait std::error::Error") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2771)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2776)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2780)#### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2784)#### fn provide(&'a self, req: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2484)1.21.0 · ### impl<T> From<&[T]> for Arc<[T]>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2496)#### fn from(v: &[T]) -> Arc<[T]>
Allocate a reference-counted slice and fill it by cloning `v`’s items.
##### Example
```
let original: &[i32] = &[1, 2, 3];
let shared: Arc<[i32]> = Arc::from(original);
assert_eq!(&[1, 2, 3], &shared[..]);
```
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#878)1.24.0 · ### impl From<&CStr> for Arc<CStr>
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#882)#### fn from(s: &CStr) -> Arc<CStr>
Converts a `&CStr` into a `Arc<CStr>`, by copying the contents into a newly allocated [`Arc`](struct.arc "Arc").
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#1046-1053)1.24.0 · ### impl From<&OsStr> for Arc<OsStr>
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#1049-1052)#### fn from(s: &OsStr) -> Arc<OsStr>
Copies the string into a newly allocated `[Arc](struct.arc "Arc")<[OsStr](../ffi/struct.osstr "OsStr")>`.
[source](https://doc.rust-lang.org/src/std/path.rs.html#1802-1809)1.24.0 · ### impl From<&Path> for Arc<Path>
[source](https://doc.rust-lang.org/src/std/path.rs.html#1805-1808)#### fn from(s: &Path) -> Arc<Path>
Converts a [`Path`](../path/struct.path "Path") into an [`Arc`](struct.arc "Arc") by copying the [`Path`](../path/struct.path "Path") data into a new [`Arc`](struct.arc "Arc") buffer.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2503)1.21.0 · ### impl From<&str> for Arc<str>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2514)#### fn from(v: &str) -> Arc<str>
Allocate a reference-counted `str` and copy `v` into it.
##### Example
```
let shared: Arc<str> = Arc::from("eggplant");
assert_eq!("eggplant", &shared[..]);
```
[source](https://doc.rust-lang.org/src/alloc/task.rs.html#101)1.51.0 · ### impl<W> From<Arc<W>> for RawWakerwhere W: 'static + [Wake](../task/trait.wake "trait std::task::Wake") + [Send](../marker/trait.send "trait std::marker::Send") + [Sync](../marker/trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/task.rs.html#105)#### fn from(waker: Arc<W>) -> RawWaker
Use a `Wake`-able type as a `RawWaker`.
No heap allocations or atomic operations are used for this conversion.
[source](https://doc.rust-lang.org/src/alloc/task.rs.html#89)1.51.0 · ### impl<W> From<Arc<W>> for Wakerwhere W: 'static + [Wake](../task/trait.wake "trait std::task::Wake") + [Send](../marker/trait.send "trait std::marker::Send") + [Sync](../marker/trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/task.rs.html#93)#### fn from(waker: Arc<W>) -> Waker
Use a `Wake`-able type as a `Waker`.
No heap allocations or atomic operations are used for this conversion.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2612)1.62.0 · ### impl From<Arc<str>> for Arc<[u8]>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2624)#### fn from(rc: Arc<str>) -> Arc<[u8]>
Converts an atomically reference-counted string slice into a byte slice.
##### Example
```
let string: Arc<str> = Arc::from("eggplant");
let bytes: Arc<[u8]> = Arc::from(string);
assert_eq!("eggplant".as_bytes(), bytes.as_ref());
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2541)1.21.0 · ### impl<T> From<Box<T, Global>> for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2553)#### fn from(v: Box<T, Global>) -> Arc<T>
Move a boxed object to a new, reference-counted allocation.
##### Example
```
let unique: Box<str> = Box::from("eggplant");
let shared: Arc<str> = Arc::from(unique);
assert_eq!("eggplant", &shared[..]);
```
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#866)1.24.0 · ### impl From<CString> for Arc<CStr>
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#870)#### fn from(s: CString) -> Arc<CStr>
Converts a [`CString`](../ffi/struct.cstring "CString") into an `[Arc](struct.arc "Arc")<[CStr](../ffi/struct.cstr "CStr")>` by moving the [`CString`](../ffi/struct.cstring "CString") data into a new [`Arc`](struct.arc "Arc") buffer.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2585)1.45.0 · ### impl<'a, B> From<Cow<'a, B>> for Arc<B>where B: [ToOwned](../borrow/trait.toowned "trait std::borrow::ToOwned") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), [Arc](struct.arc "struct std::sync::Arc")<B>: [From](../convert/trait.from "trait std::convert::From")<[&'a](../primitive.reference) B>, [Arc](struct.arc "struct std::sync::Arc")<B>: [From](../convert/trait.from "trait std::convert::From")<<B as [ToOwned](../borrow/trait.toowned "trait std::borrow::ToOwned")>::[Owned](../borrow/trait.toowned#associatedtype.Owned "type std::borrow::ToOwned::Owned")>,
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2603)#### fn from(cow: Cow<'a, B>) -> Arc<B>
Create an atomically reference-counted pointer from a clone-on-write pointer by copying its content.
##### Example
```
let cow: Cow<str> = Cow::Borrowed("eggplant");
let shared: Arc<str> = Arc::from(cow);
assert_eq!("eggplant", &shared[..]);
```
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#1035-1043)1.24.0 · ### impl From<OsString> for Arc<OsStr>
[source](https://doc.rust-lang.org/src/std/ffi/os_str.rs.html#1039-1042)#### fn from(s: OsString) -> Arc<OsStr>
Converts an [`OsString`](../ffi/struct.osstring "OsString") into an `[Arc](struct.arc "Arc")<[OsStr](../ffi/struct.osstr "OsStr")>` by moving the [`OsString`](../ffi/struct.osstring "OsString") data into a new [`Arc`](struct.arc "Arc") buffer.
[source](https://doc.rust-lang.org/src/std/path.rs.html#1791-1799)1.24.0 · ### impl From<PathBuf> for Arc<Path>
[source](https://doc.rust-lang.org/src/std/path.rs.html#1795-1798)#### fn from(s: PathBuf) -> Arc<Path>
Converts a [`PathBuf`](../path/struct.pathbuf "PathBuf") into an `[Arc](struct.arc "Arc")<[Path](../path/struct.path "Path")>` by moving the [`PathBuf`](../path/struct.pathbuf "PathBuf") data into a new [`Arc`](struct.arc "Arc") buffer.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2522)1.21.0 · ### impl From<String> for Arc<str>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2534)#### fn from(v: String) -> Arc<str>
Allocate a reference-counted `str` and copy `v` into it.
##### Example
```
let unique: String = "eggplant".to_owned();
let shared: Arc<str> = Arc::from(unique);
assert_eq!("eggplant", &shared[..]);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2462)1.6.0 · ### impl<T> From<T> for Arc<T>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2477)#### fn from(t: T) -> Arc<T>
Converts a `T` into an `Arc<T>`
The conversion moves the value into a newly allocated `Arc`. It is equivalent to calling `Arc::new(t)`.
##### Example
```
let x = 5;
let arc = Arc::new(5);
assert_eq!(Arc::from(x), arc);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2560)1.21.0 · ### impl<T> From<Vec<T, Global>> for Arc<[T]>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2572)#### fn from(v: Vec<T, Global>) -> Arc<[T]>
Allocate a reference-counted slice and move `v`’s items into it.
##### Example
```
let unique: Vec<i32> = vec![1, 2, 3];
let shared: Arc<[i32]> = Arc::from(unique);
assert_eq!(&[1, 2, 3], &shared[..]);
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2645)1.37.0 · ### impl<T> FromIterator<T> for Arc<[T]>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2684)#### fn from\_iter<I>(iter: I) -> Arc<[T]>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Takes each element in the `Iterator` and collects it into an `Arc<[T]>`.
##### Performance characteristics
###### [The general case](#the-general-case)
In the general case, collecting into `Arc<[T]>` is done by first collecting into a `Vec<T>`. That is, when writing the following:
```
let evens: Arc<[u8]> = (0..10).filter(|&x| x % 2 == 0).collect();
```
this behaves as if we wrote:
```
let evens: Arc<[u8]> = (0..10).filter(|&x| x % 2 == 0)
.collect::<Vec<_>>() // The first set of allocations happens here.
.into(); // A second allocation for `Arc<[T]>` happens here.
```
This will allocate as many times as needed for constructing the `Vec<T>` and then it will allocate once for turning the `Vec<T>` into the `Arc<[T]>`.
###### [Iterators of known length](#iterators-of-known-length)
When your `Iterator` implements `TrustedLen` and is of an exact size, a single allocation will be made for the `Arc<[T]>`. For example:
```
let evens: Arc<[u8]> = (0..10).collect(); // Just a single allocation happens here.
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2454)### impl<T> Hash for Arc<T>where T: [Hash](../hash/trait.hash "trait std::hash::Hash") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2455)#### fn hash<H>(&self, state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2392)### impl<T> Ord for Arc<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2407)#### fn cmp(&self, other: &Arc<T>) -> Ordering
Comparison for two `Arc`s.
The two are compared by calling `cmp()` on their inner values.
##### Examples
```
use std::sync::Arc;
use std::cmp::Ordering;
let five = Arc::new(5);
assert_eq!(Ordering::Less, five.cmp(&Arc::new(6)));
```
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2258)### impl<T> PartialEq<Arc<T>> for Arc<T>where T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<T> + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2277)#### fn eq(&self, other: &Arc<T>) -> bool
Equality for two `Arc`s.
Two `Arc`s are equal if their inner values are equal, even if they are stored in different allocation.
If `T` also implements `Eq` (implying reflexivity of equality), two `Arc`s that point to the same allocation are always equal.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
assert!(five == Arc::new(5));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2298)#### fn ne(&self, other: &Arc<T>) -> bool
Inequality for two `Arc`s.
Two `Arc`s are unequal if their inner values are unequal.
If `T` also implements `Eq` (implying reflexivity of equality), two `Arc`s that point to the same value are never unequal.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
assert!(five != Arc::new(6));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2304)### impl<T> PartialOrd<Arc<T>> for Arc<T>where T: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<T> + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2319)#### fn partial\_cmp(&self, other: &Arc<T>) -> Option<Ordering>
Partial comparison for two `Arc`s.
The two are compared by calling `partial_cmp()` on their inner values.
##### Examples
```
use std::sync::Arc;
use std::cmp::Ordering;
let five = Arc::new(5);
assert_eq!(Some(Ordering::Less), five.partial_cmp(&Arc::new(6)));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2336)#### fn lt(&self, other: &Arc<T>) -> bool
Less-than comparison for two `Arc`s.
The two are compared by calling `<` on their inner values.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
assert!(five < Arc::new(6));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2353)#### fn le(&self, other: &Arc<T>) -> bool
‘Less than or equal to’ comparison for two `Arc`s.
The two are compared by calling `<=` on their inner values.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
assert!(five <= Arc::new(5));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2370)#### fn gt(&self, other: &Arc<T>) -> bool
Greater-than comparison for two `Arc`s.
The two are compared by calling `>` on their inner values.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
assert!(five > Arc::new(4));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2387)#### fn ge(&self, other: &Arc<T>) -> bool
‘Greater than or equal to’ comparison for two `Arc`s.
The two are compared by calling `>=` on their inner values.
##### Examples
```
use std::sync::Arc;
let five = Arc::new(5);
assert!(five >= Arc::new(5));
```
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2429)### impl<T> Pointer for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2430)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2631)1.43.0 · ### impl<T, const N: usize> TryFrom<Arc<[T]>> for Arc<[T; N]>
#### type Error = Arc<[T]>
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2634)#### fn try\_from( boxed\_slice: Arc<[T]>) -> Result<Arc<[T; N]>, <Arc<[T; N]> as TryFrom<Arc<[T]>>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#249)### impl<T, U> CoerceUnsized<Arc<U>> for Arc<T>where T: [Unsize](../marker/trait.unsize "trait std::marker::Unsize")<U> + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), U: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#252)### impl<T, U> DispatchFromDyn<Arc<U>> for Arc<T>where T: [Unsize](../marker/trait.unsize "trait std::marker::Unsize")<U> + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), U: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2412)### impl<T> Eq for Arc<T>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#241)### impl<T> Send for Arc<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync") + [Send](../marker/trait.send "trait std::marker::Send") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#243)### impl<T> Sync for Arc<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync") + [Send](../marker/trait.send "trait std::marker::Send") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2743)1.33.0 · ### impl<T> Unpin for Arc<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#246)1.9.0 · ### impl<T> UnwindSafe for Arc<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Auto Trait Implementations
--------------------------
### impl<T: ?Sized> RefUnwindSafe for Arc<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#577)### impl<T> From<!> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#578)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: !) -> T
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../error/trait.error "trait std::error::Error") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::RwLockReadGuard Struct std::sync::RwLockReadGuard
=================================
```
pub struct RwLockReadGuard<'a, T: ?Sized + 'a> { /* private fields */ }
```
RAII structure used to release the shared read access of a lock when dropped.
This structure is created by the [`read`](struct.rwlock#method.read) and [`try_read`](struct.rwlock#method.try_read) methods on [`RwLock`](struct.rwlock "RwLock").
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#543-547)1.16.0 · ### impl<T: Debug> Debug for RwLockReadGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#544-546)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#571-578)### impl<T: ?Sized> Deref for RwLockReadGuard<'\_, T>
#### type Target = T
The resulting type after dereferencing.
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#574-577)#### fn deref(&self) -> &T
Dereferences the value.
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#550-554)1.20.0 · ### impl<T: ?Sized + Display> Display for RwLockReadGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#551-553)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#599-606)### impl<T: ?Sized> Drop for RwLockReadGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#600-605)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#115)### impl<T: ?Sized> !Send for RwLockReadGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#118)1.23.0 · ### impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'\_, T>
Auto Trait Implementations
--------------------------
### impl<'a, T: ?Sized> RefUnwindSafe for RwLockReadGuard<'a, T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T: ?Sized> Unpin for RwLockReadGuard<'a, T>
### impl<'a, T: ?Sized> UnwindSafe for RwLockReadGuard<'a, T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::Mutex Struct std::sync::Mutex
=======================
```
pub struct Mutex<T: ?Sized> { /* private fields */ }
```
A mutual exclusion primitive useful for protecting shared data
This mutex will block threads waiting for the lock to become available. The mutex can be created via a [`new`](struct.mutex#method.new) constructor. Each mutex has a type parameter which represents the data that it is protecting. The data can only be accessed through the RAII guards returned from [`lock`](struct.mutex#method.lock) and [`try_lock`](struct.mutex#method.try_lock), which guarantees that the data is only ever accessed when the mutex is locked.
Poisoning
---------
The mutexes in this module implement a strategy called “poisoning” where a mutex is considered poisoned whenever a thread panics while holding the mutex. Once a mutex is poisoned, all other threads are unable to access the data by default as it is likely tainted (some invariant is not being upheld).
For a mutex, this means that the [`lock`](struct.mutex#method.lock) and [`try_lock`](struct.mutex#method.try_lock) methods return a [`Result`](../result/enum.result "Result") which indicates whether a mutex has been poisoned or not. Most usage of a mutex will simply [`unwrap()`](../result/enum.result#method.unwrap) these results, propagating panics among threads to ensure that a possibly invalid invariant is not witnessed.
A poisoned mutex, however, does not prevent all access to the underlying data. The [`PoisonError`](struct.poisonerror) type has an [`into_inner`](struct.poisonerror#method.into_inner) method which will return the guard that would have otherwise been returned on a successful lock. This allows access to the data, despite the lock being poisoned.
Examples
--------
```
use std::sync::{Arc, Mutex};
use std::thread;
use std::sync::mpsc::channel;
const N: usize = 10;
// Spawn a few threads to increment a shared variable (non-atomically), and
// let the main thread know once all increments are done.
//
// Here we're using an Arc to share memory among threads, and the data inside
// the Arc is protected with a mutex.
let data = Arc::new(Mutex::new(0));
let (tx, rx) = channel();
for _ in 0..N {
let (data, tx) = (Arc::clone(&data), tx.clone());
thread::spawn(move || {
// The shared state can only be accessed once the lock is held.
// Our non-atomic increment is safe because we're the only thread
// which can access the shared state when the lock is held.
//
// We unwrap() the return value to assert that we are not expecting
// threads to ever fail while holding the lock.
let mut data = data.lock().unwrap();
*data += 1;
if *data == N {
tx.send(()).unwrap();
}
// the lock is unlocked here when `data` goes out of scope.
});
}
rx.recv().unwrap();
```
To recover from a poisoned mutex:
```
use std::sync::{Arc, Mutex};
use std::thread;
let lock = Arc::new(Mutex::new(0_u32));
let lock2 = Arc::clone(&lock);
let _ = thread::spawn(move || -> () {
// This thread will acquire the mutex first, unwrapping the result of
// `lock` because the lock has not been poisoned.
let _guard = lock2.lock().unwrap();
// This panic while holding the lock (`_guard` is in scope) will poison
// the mutex.
panic!();
}).join();
// The lock is poisoned by this point, but the returned result can be
// pattern matched on to return the underlying guard on both branches.
let mut guard = match lock.lock() {
Ok(guard) => guard,
Err(poisoned) => poisoned.into_inner(),
};
*guard += 1;
```
It is sometimes necessary to manually drop the mutex guard to unlock it sooner than the end of the enclosing scope.
```
use std::sync::{Arc, Mutex};
use std::thread;
const N: usize = 3;
let data_mutex = Arc::new(Mutex::new(vec![1, 2, 3, 4]));
let res_mutex = Arc::new(Mutex::new(0));
let mut threads = Vec::with_capacity(N);
(0..N).for_each(|_| {
let data_mutex_clone = Arc::clone(&data_mutex);
let res_mutex_clone = Arc::clone(&res_mutex);
threads.push(thread::spawn(move || {
let mut data = data_mutex_clone.lock().unwrap();
// This is the result of some important and long-ish work.
let result = data.iter().fold(0, |acc, x| acc + x * 2);
data.push(result);
drop(data);
*res_mutex_clone.lock().unwrap() += result;
}));
});
let mut data = data_mutex.lock().unwrap();
// This is the result of some important and long-ish work.
let result = data.iter().fold(0, |acc, x| acc + x * 2);
data.push(result);
// We drop the `data` explicitly because it's not necessary anymore and the
// thread still has work to do. This allow other threads to start working on
// the data immediately, without waiting for the rest of the unrelated work
// to be done here.
//
// It's even more important here than in the threads because we `.join` the
// threads after that. If we had not dropped the mutex guard, a thread could
// be waiting forever for it, causing a deadlock.
drop(data);
// Here the mutex guard is not assigned to a variable and so, even if the
// scope does not end after this line, the mutex is still released: there is
// no deadlock.
*res_mutex.lock().unwrap() += result;
threads.into_iter().for_each(|thread| {
thread
.join()
.expect("The thread creating or execution failed !")
});
assert_eq!(*res_mutex.lock().unwrap(), 800);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#206-226)### impl<T> Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#219-225)const: 1.63.0 · #### pub const fn new(t: T) -> Mutex<T>
Creates a new mutex in an unlocked state ready for use.
##### Examples
```
use std::sync::Mutex;
let mutex = Mutex::new(0);
```
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#228-456)### impl<T: ?Sized> Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#265-270)#### pub fn lock(&self) -> LockResult<MutexGuard<'\_, T>>
Acquires a mutex, blocking the current thread until it is able to do so.
This function will block the local thread until it is available to acquire the mutex. Upon returning, the thread is the only thread with the lock held. An RAII guard is returned to allow scoped unlock of the lock. When the guard goes out of scope, the mutex will be unlocked.
The exact behavior on locking a mutex in the thread which already holds the lock is left unspecified. However, this function will not return on the second call (it might panic or deadlock, for example).
##### Errors
If another user of this mutex panicked while holding the mutex, then this call will return an error once the mutex is acquired.
##### Panics
This function might panic when called if the lock is already held by the current thread.
##### Examples
```
use std::sync::{Arc, Mutex};
use std::thread;
let mutex = Arc::new(Mutex::new(0));
let c_mutex = Arc::clone(&mutex);
thread::spawn(move || {
*c_mutex.lock().unwrap() = 10;
}).join().expect("thread::spawn failed");
assert_eq!(*mutex.lock().unwrap(), 10);
```
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#312-320)#### pub fn try\_lock(&self) -> TryLockResult<MutexGuard<'\_, T>>
Attempts to acquire this lock.
If the lock could not be acquired at this time, then [`Err`](../result/enum.result#variant.Err "Err") is returned. Otherwise, an RAII guard is returned. The lock will be unlocked when the guard is dropped.
This function does not block.
##### Errors
If another user of this mutex panicked while holding the mutex, then this call will return the [`Poisoned`](enum.trylockerror#variant.Poisoned) error if the mutex would otherwise be acquired.
If the mutex could not be acquired because it is already locked, then this call will return the [`WouldBlock`](enum.trylockerror#variant.WouldBlock) error.
##### Examples
```
use std::sync::{Arc, Mutex};
use std::thread;
let mutex = Arc::new(Mutex::new(0));
let c_mutex = Arc::clone(&mutex);
thread::spawn(move || {
let mut lock = c_mutex.try_lock();
if let Ok(ref mut mutex) = lock {
**mutex = 10;
} else {
println!("try_lock failed");
}
}).join().expect("thread::spawn failed");
assert_eq!(*mutex.lock().unwrap(), 10);
```
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#338-340)#### pub fn unlock(guard: MutexGuard<'\_, T>)
🔬This is a nightly-only experimental API. (`mutex_unlock` [#81872](https://github.com/rust-lang/rust/issues/81872))
Immediately drops the guard, and consequently unlocks the mutex.
This function is equivalent to calling [`drop`](../mem/fn.drop "drop") on the guard but is more self-documenting. Alternately, the guard will be automatically dropped when it goes out of scope.
```
#![feature(mutex_unlock)]
use std::sync::Mutex;
let mutex = Mutex::new(0);
let mut guard = mutex.lock().unwrap();
*guard += 20;
Mutex::unlock(guard);
```
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#365-367)1.2.0 · #### pub fn is\_poisoned(&self) -> bool
Determines whether the mutex is poisoned.
If another thread is active, the mutex can still become poisoned at any time. You should not trust a `false` value for program correctness without additional synchronization.
##### Examples
```
use std::sync::{Arc, Mutex};
use std::thread;
let mutex = Arc::new(Mutex::new(0));
let c_mutex = Arc::clone(&mutex);
let _ = thread::spawn(move || {
let _lock = c_mutex.lock().unwrap();
panic!(); // the mutex gets poisoned
}).join();
assert_eq!(mutex.is_poisoned(), true);
```
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#404-406)#### pub fn clear\_poison(&self)
🔬This is a nightly-only experimental API. (`mutex_unpoison` [#96469](https://github.com/rust-lang/rust/issues/96469))
Clear the poisoned state from a mutex
If the mutex is poisoned, it will remain poisoned until this function is called. This allows recovering from a poisoned state and marking that it has recovered. For example, if the value is overwritten by a known-good value, then the mutex can be marked as un-poisoned. Or possibly, the value could be inspected to determine if it is in a consistent state, and if so the poison is removed.
##### Examples
```
#![feature(mutex_unpoison)]
use std::sync::{Arc, Mutex};
use std::thread;
let mutex = Arc::new(Mutex::new(0));
let c_mutex = Arc::clone(&mutex);
let _ = thread::spawn(move || {
let _lock = c_mutex.lock().unwrap();
panic!(); // the mutex gets poisoned
}).join();
assert_eq!(mutex.is_poisoned(), true);
let x = mutex.lock().unwrap_or_else(|mut e| {
**e.get_mut() = 1;
mutex.clear_poison();
e.into_inner()
});
assert_eq!(mutex.is_poisoned(), false);
assert_eq!(*x, 1);
```
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#424-430)1.6.0 · #### pub fn into\_inner(self) -> LockResult<T>where T: [Sized](../marker/trait.sized "trait std::marker::Sized"),
Consumes this mutex, returning the underlying data.
##### Errors
If another user of this mutex panicked while holding the mutex, then this call will return an error instead.
##### Examples
```
use std::sync::Mutex;
let mutex = Mutex::new(0);
assert_eq!(mutex.into_inner().unwrap(), 0);
```
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#452-455)1.6.0 · #### pub fn get\_mut(&mut self) -> LockResult<&mut T>
Returns a mutable reference to the underlying data.
Since this call borrows the `Mutex` mutably, no actual locking needs to take place – the mutable borrow statically guarantees no locks exist.
##### Errors
If another user of this mutex panicked while holding the mutex, then this call will return an error instead.
##### Examples
```
use std::sync::Mutex;
let mut mutex = Mutex::new(0);
*mutex.get_mut().unwrap() = 10;
assert_eq!(*mutex.lock().unwrap(), 10);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#476-499)### impl<T: ?Sized + Debug> Debug for Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#477-498)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#468-473)1.10.0 · ### impl<T: ?Sized + Default> Default for Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#470-472)#### fn default() -> Mutex<T>
Creates a `Mutex<T>`, with the `Default` value for T.
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#459-465)1.24.0 · ### impl<T> From<T> for Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#462-464)#### fn from(t: T) -> Self
Creates a new mutex in an unlocked state ready for use. This is equivalent to [`Mutex::new`](struct.mutex#method.new "Mutex::new").
[source](https://doc.rust-lang.org/src/std/panic.rs.html#70)1.12.0 · ### impl<T: ?Sized> RefUnwindSafe for Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#174)### impl<T: ?Sized + Send> Send for Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#176)### impl<T: ?Sized + Send> Sync for Mutex<T>
[source](https://doc.rust-lang.org/src/std/panic.rs.html#65)1.9.0 · ### impl<T: ?Sized> UnwindSafe for Mutex<T>
Auto Trait Implementations
--------------------------
### impl<T: ?Sized> Unpin for Mutex<T>where T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#577)### impl<T> From<!> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#578)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: !) -> T
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Enum std::sync::TryLockError Enum std::sync::TryLockError
============================
```
pub enum TryLockError<T> {
Poisoned(PoisonError<T>),
WouldBlock,
}
```
An enumeration of possible errors associated with a [`TryLockResult`](type.trylockresult "TryLockResult") which can occur while trying to acquire a lock, from the [`try_lock`](struct.mutex#method.try_lock) method on a [`Mutex`](struct.mutex) or the [`try_read`](struct.rwlock#method.try_read) and [`try_write`](struct.rwlock#method.try_write) methods on an [`RwLock`](struct.rwlock).
Variants
--------
### `Poisoned([PoisonError](struct.poisonerror "struct std::sync::PoisonError")<T>)`
The lock could not be acquired because another thread failed while holding the lock.
### `WouldBlock`
The lock could not be acquired at this time because the operation would otherwise block.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#225-232)### impl<T> Debug for TryLockError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#226-231)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#235-243)### impl<T> Display for TryLockError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#236-242)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#246-262)### impl<T> Error for TryLockError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#248-253)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#256-261)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#218-222)### impl<T> From<PoisonError<T>> for TryLockError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#219-221)#### fn from(err: PoisonError<T>) -> TryLockError<T>
Converts to this type from the input type.
Auto Trait Implementations
--------------------------
### impl<T> RefUnwindSafe for TryLockError<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T> Send for TryLockError<T>where T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T> Sync for TryLockError<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<T> Unpin for TryLockError<T>where T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T> UnwindSafe for TryLockError<T>where T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../error/trait.error "trait std::error::Error") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::BarrierWaitResult Struct std::sync::BarrierWaitResult
===================================
```
pub struct BarrierWaitResult(_);
```
A `BarrierWaitResult` is returned by [`Barrier::wait()`](struct.barrier#method.wait "Barrier::wait()") when all threads in the [`Barrier`](struct.barrier "Barrier") have rendezvoused.
Examples
--------
```
use std::sync::Barrier;
let barrier = Barrier::new(1);
let barrier_wait_result = barrier.wait();
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#153-174)### impl BarrierWaitResult
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#171-173)#### pub fn is\_leader(&self) -> bool
Returns `true` if this thread is the “leader thread” for the call to [`Barrier::wait()`](struct.barrier#method.wait "Barrier::wait()").
Only one thread will have `true` returned from their result, all other threads will have `false` returned.
##### Examples
```
use std::sync::Barrier;
let barrier = Barrier::new(1);
let barrier_wait_result = barrier.wait();
println!("{:?}", barrier_wait_result.is_leader());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#147-151)1.16.0 · ### impl Debug for BarrierWaitResult
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#148-150)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for BarrierWaitResult
### impl Send for BarrierWaitResult
### impl Sync for BarrierWaitResult
### impl Unpin for BarrierWaitResult
### impl UnwindSafe for BarrierWaitResult
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::RwLockWriteGuard Struct std::sync::RwLockWriteGuard
==================================
```
pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> { /* private fields */ }
```
RAII structure used to release the exclusive write access of a lock when dropped.
This structure is created by the [`write`](struct.rwlock#method.write) and [`try_write`](struct.rwlock#method.try_write) methods on [`RwLock`](struct.rwlock "RwLock").
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#557-561)1.16.0 · ### impl<T: Debug> Debug for RwLockWriteGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#558-560)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#581-588)### impl<T: ?Sized> Deref for RwLockWriteGuard<'\_, T>
#### type Target = T
The resulting type after dereferencing.
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#584-587)#### fn deref(&self) -> &T
Dereferences the value.
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#591-596)### impl<T: ?Sized> DerefMut for RwLockWriteGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#592-595)#### fn deref\_mut(&mut self) -> &mut T
Mutably dereferences the value.
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#564-568)1.20.0 · ### impl<T: ?Sized + Display> Display for RwLockWriteGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#565-567)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#609-617)### impl<T: ?Sized> Drop for RwLockWriteGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#610-616)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#141)### impl<T: ?Sized> !Send for RwLockWriteGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#144)1.23.0 · ### impl<T: ?Sized + Sync> Sync for RwLockWriteGuard<'\_, T>
Auto Trait Implementations
--------------------------
### impl<'a, T: ?Sized> RefUnwindSafe for RwLockWriteGuard<'a, T>
### impl<'a, T: ?Sized> Unpin for RwLockWriteGuard<'a, T>
### impl<'a, T: ?Sized> UnwindSafe for RwLockWriteGuard<'a, T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::Barrier Struct std::sync::Barrier
=========================
```
pub struct Barrier { /* private fields */ }
```
A barrier enables multiple threads to synchronize the beginning of some computation.
Examples
--------
```
use std::sync::{Arc, Barrier};
use std::thread;
let mut handles = Vec::with_capacity(10);
let barrier = Arc::new(Barrier::new(10));
for _ in 0..10 {
let c = Arc::clone(&barrier);
// The same messages will be printed together.
// You will NOT see any interleaving.
handles.push(thread::spawn(move|| {
println!("before wait");
c.wait();
println!("after wait");
}));
}
// Wait for other threads to finish.
for handle in handles {
handle.join().unwrap();
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#67-144)### impl Barrier
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#84-90)#### pub fn new(n: usize) -> Barrier
Creates a new barrier that can block a given number of threads.
A barrier will block `n`-1 threads which call [`wait()`](struct.barrier#method.wait) and then wake up all threads at once when the `n`th thread calls [`wait()`](struct.barrier#method.wait).
##### Examples
```
use std::sync::Barrier;
let barrier = Barrier::new(10);
```
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#126-143)#### pub fn wait(&self) -> BarrierWaitResult
Blocks the current thread until all threads have rendezvoused here.
Barriers are re-usable after all threads have rendezvoused once, and can be used continuously.
A single (arbitrary) thread will receive a [`BarrierWaitResult`](struct.barrierwaitresult "BarrierWaitResult") that returns `true` from [`BarrierWaitResult::is_leader()`](struct.barrierwaitresult#method.is_leader "BarrierWaitResult::is_leader()") when returning from this function, and all other threads will receive a result that will return `false` from [`BarrierWaitResult::is_leader()`](struct.barrierwaitresult#method.is_leader "BarrierWaitResult::is_leader()").
##### Examples
```
use std::sync::{Arc, Barrier};
use std::thread;
let mut handles = Vec::with_capacity(10);
let barrier = Arc::new(Barrier::new(10));
for _ in 0..10 {
let c = Arc::clone(&barrier);
// The same messages will be printed together.
// You will NOT see any interleaving.
handles.push(thread::spawn(move|| {
println!("before wait");
c.wait();
println!("after wait");
}));
}
// Wait for other threads to finish.
for handle in handles {
handle.join().unwrap();
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#61-65)1.16.0 · ### impl Debug for Barrier
[source](https://doc.rust-lang.org/src/std/sync/barrier.rs.html#62-64)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for Barrier
### impl Send for Barrier
### impl Sync for Barrier
### impl Unpin for Barrier
### impl UnwindSafe for Barrier
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::Once Struct std::sync::Once
======================
```
pub struct Once { /* private fields */ }
```
A synchronization primitive which can be used to run a one-time global initialization. Useful for one-time initialization for FFI or related functionality. This type can only be constructed with [`Once::new()`](struct.once#method.new "Once::new()").
Examples
--------
```
use std::sync::Once;
static START: Once = Once::new();
START.call_once(|| {
// run initialization here
});
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#194-448)### impl Once
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#200-205)1.2.0 (const: 1.32.0) · #### pub const fn new() -> Once
Creates a new `Once` value.
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#266-277)#### pub fn call\_once<F>(&self, f: F)where F: [FnOnce](../ops/trait.fnonce "trait std::ops::FnOnce")(),
Performs an initialization routine once and only once. The given closure will be executed if this is the first time `call_once` has been called, and otherwise the routine will *not* be invoked.
This method will block the calling thread if another initialization routine is currently running.
When this function returns, it is guaranteed that some initialization has run and completed (it might not be the closure specified). It is also guaranteed that any memory writes performed by the executed closure can be reliably observed by other threads at this point (there is a happens-before relation between the closure and code executing after the return).
If the given closure recursively invokes `call_once` on the same [`Once`](struct.once "Once") instance the exact behavior is not specified, allowed outcomes are a panic or a deadlock.
##### Examples
```
use std::sync::Once;
static mut VAL: usize = 0;
static INIT: Once = Once::new();
// Accessing a `static mut` is unsafe much of the time, but if we do so
// in a synchronized fashion (e.g., write once or read all) then we're
// good to go!
//
// This function will only call `expensive_computation` once, and will
// otherwise always return the value returned from the first invocation.
fn get_cached_val() -> usize {
unsafe {
INIT.call_once(|| {
VAL = expensive_computation();
});
VAL
}
}
fn expensive_computation() -> usize {
// ...
}
```
##### Panics
The closure `f` will only be executed once if this is called concurrently amongst many threads. If that closure panics, however, then it will *poison* this [`Once`](struct.once "Once") instance, causing all future invocations of `call_once` to also panic.
This is similar to [poisoning with mutexes](struct.mutex#poisoning).
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#324-335)1.51.0 · #### pub fn call\_once\_force<F>(&self, f: F)where F: [FnOnce](../ops/trait.fnonce "trait std::ops::FnOnce")(&[OnceState](struct.oncestate "struct std::sync::OnceState")),
Performs the same function as [`call_once()`](struct.once#method.call_once) except ignores poisoning.
Unlike [`call_once()`](struct.once#method.call_once), if this [`Once`](struct.once "Once") has been poisoned (i.e., a previous call to [`call_once()`](struct.once#method.call_once) or [`call_once_force()`](struct.once#method.call_once_force) caused a panic), calling [`call_once_force()`](struct.once#method.call_once_force) will still invoke the closure `f` and will *not* result in an immediate panic. If `f` panics, the [`Once`](struct.once "Once") will remain in a poison state. If `f` does *not* panic, the [`Once`](struct.once "Once") will no longer be in a poison state and all future calls to [`call_once()`](struct.once#method.call_once) or [`call_once_force()`](struct.once#method.call_once_force) will be no-ops.
The closure `f` is yielded a [`OnceState`](struct.oncestate "OnceState") structure which can be used to query the poison status of the [`Once`](struct.once "Once").
##### Examples
```
use std::sync::Once;
use std::thread;
static INIT: Once = Once::new();
// poison the once
let handle = thread::spawn(|| {
INIT.call_once(|| panic!());
});
assert!(handle.join().is_err());
// poisoning propagates
let handle = thread::spawn(|| {
INIT.call_once(|| {});
});
assert!(handle.join().is_err());
// call_once_force will still run and reset the poisoned state
INIT.call_once_force(|state| {
assert!(state.is_poisoned());
});
// once any success happens, we stop propagating the poison
INIT.call_once(|| {});
```
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#380-386)1.43.0 · #### pub fn is\_completed(&self) -> bool
Returns `true` if some [`call_once()`](struct.once#method.call_once) call has completed successfully. Specifically, `is_completed` will return false in the following situations:
* [`call_once()`](struct.once#method.call_once) was not called at all,
* [`call_once()`](struct.once#method.call_once) was called, but has not yet completed,
* the [`Once`](struct.once "Once") instance is poisoned
This function returning `false` does not mean that [`Once`](struct.once "Once") has not been executed. For example, it may have been executed in the time between when `is_completed` starts executing and when it returns, in which case the `false` return value would be stale (but still permissible).
##### Examples
```
use std::sync::Once;
static INIT: Once = Once::new();
assert_eq!(INIT.is_completed(), false);
INIT.call_once(|| {
assert_eq!(INIT.is_completed(), false);
});
assert_eq!(INIT.is_completed(), true);
```
```
use std::sync::Once;
use std::thread;
static INIT: Once = Once::new();
assert_eq!(INIT.is_completed(), false);
let handle = thread::spawn(|| {
INIT.call_once(|| panic!());
});
assert!(handle.join().is_err());
assert_eq!(INIT.is_completed(), false);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#498-502)1.16.0 · ### impl Debug for Once
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#499-501)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#134)1.59.0 · ### impl RefUnwindSafe for Once
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#128)### impl Send for Once
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#126)### impl Sync for Once
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#131)1.59.0 · ### impl UnwindSafe for Once
Auto Trait Implementations
--------------------------
### impl Unpin for Once
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::PoisonError Struct std::sync::PoisonError
=============================
```
pub struct PoisonError<T> { /* private fields */ }
```
A type of error which can be returned whenever a lock is acquired.
Both [`Mutex`](struct.mutex)es and [`RwLock`](struct.rwlock)s are poisoned whenever a thread fails while the lock is held. The precise semantics for when a lock is poisoned is documented on each lock, but once a lock is poisoned then all future acquisitions will return this error.
Examples
--------
```
use std::sync::{Arc, Mutex};
use std::thread;
let mutex = Arc::new(Mutex::new(1));
// poison the mutex
let c_mutex = Arc::clone(&mutex);
let _ = thread::spawn(move || {
let mut data = c_mutex.lock().unwrap();
*data = 2;
panic!();
}).join();
match mutex.lock() {
Ok(_) => unreachable!(),
Err(p_err) => {
let data = p_err.get_ref();
println!("recovered: {data}");
}
};
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#163-215)### impl<T> PoisonError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#169-171)1.2.0 · #### pub fn new(guard: T) -> PoisonError<T>
Creates a `PoisonError`.
This is generally created by methods like [`Mutex::lock`](struct.mutex#method.lock) or [`RwLock::read`](struct.rwlock#method.read).
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#198-200)1.2.0 · #### pub fn into\_inner(self) -> T
Consumes this error indicating that a lock is poisoned, returning the underlying guard to allow access regardless.
##### Examples
```
use std::collections::HashSet;
use std::sync::{Arc, Mutex};
use std::thread;
let mutex = Arc::new(Mutex::new(HashSet::new()));
// poison the mutex
let c_mutex = Arc::clone(&mutex);
let _ = thread::spawn(move || {
let mut data = c_mutex.lock().unwrap();
data.insert(10);
panic!();
}).join();
let p_err = mutex.lock().unwrap_err();
let data = p_err.into_inner();
println!("recovered {} items", data.len());
```
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#205-207)1.2.0 · #### pub fn get\_ref(&self) -> &T
Reaches into this error indicating that a lock is poisoned, returning a reference to the underlying guard to allow access regardless.
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#212-214)1.2.0 · #### pub fn get\_mut(&mut self) -> &mut T
Reaches into this error indicating that a lock is poisoned, returning a mutable reference to the underlying guard to allow access regardless.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#142-146)### impl<T> Debug for PoisonError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#143-145)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#149-153)### impl<T> Display for PoisonError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#150-152)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#156-161)### impl<T> Error for PoisonError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#158-160)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#218-222)### impl<T> From<PoisonError<T>> for TryLockError<T>
[source](https://doc.rust-lang.org/src/std/sync/poison.rs.html#219-221)#### fn from(err: PoisonError<T>) -> TryLockError<T>
Converts to this type from the input type.
Auto Trait Implementations
--------------------------
### impl<T> RefUnwindSafe for PoisonError<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T> Send for PoisonError<T>where T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T> Sync for PoisonError<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<T> Unpin for PoisonError<T>where T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T> UnwindSafe for PoisonError<T>where T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../error/trait.error "trait std::error::Error") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::Exclusive Struct std::sync::Exclusive
===========================
```
#[repr(transparent)]pub struct Exclusive<T>where T: ?Sized,{ /* private fields */ }
```
🔬This is a nightly-only experimental API. (`exclusive_wrapper` [#98407](https://github.com/rust-lang/rust/issues/98407))
`Exclusive` provides only *mutable* access, also referred to as *exclusive* access to the underlying value. It provides no *immutable*, or *shared* access to the underlying value.
While this may seem not very useful, it allows `Exclusive` to *unconditionally* implement [`Sync`](../marker/trait.sync). Indeed, the safety requirements of `Sync` state that for `Exclusive` to be `Sync`, it must be sound to *share* across threads, that is, it must be sound for `&Exclusive` to cross thread boundaries. By design, a `&Exclusive` has no API whatsoever, making it useless, thus harmless, thus memory safe.
Certain constructs like [`Future`](../future/trait.future "Future")s can only be used with *exclusive* access, and are often `Send` but not `Sync`, so `Exclusive` can be used as hint to the rust compiler that something is `Sync` in practice.
### Examples
Using a non-`Sync` future prevents the wrapping struct from being `Sync`
ⓘ
```
use core::cell::Cell;
async fn other() {}
fn assert_sync<T: Sync>(t: T) {}
struct State<F> {
future: F
}
assert_sync(State {
future: async {
let cell = Cell::new(1);
let cell_ref = &cell;
other().await;
let value = cell_ref.get();
}
});
```
`Exclusive` ensures the struct is `Sync` without stripping the future of its functionality.
```
#![feature(exclusive_wrapper)]
use core::cell::Cell;
use core::sync::Exclusive;
async fn other() {}
fn assert_sync<T: Sync>(t: T) {}
struct State<F> {
future: Exclusive<F>
}
assert_sync(State {
future: Exclusive::new(async {
let cell = Cell::new(1);
let cell_ref = &cell;
other().await;
let value = cell_ref.get();
})
});
```
### Parallels with a mutex
In some sense, `Exclusive` can be thought of as a *compile-time* version of a mutex, as the borrow-checker guarantees that only one `&mut` can exist for any value. This is a parallel with the fact that `&` and `&mut` references together can be thought of as a *compile-time* version of a read-write lock.
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#99)### impl<T> Exclusive<T>
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#103)#### pub const fn new(t: T) -> Exclusive<T>
Notable traits for [Exclusive](struct.exclusive "struct std::sync::Exclusive")<T>
```
impl<T> Future for Exclusive<T>where
T: Future + ?Sized,
type Output = <T as Future>::Output;
```
🔬This is a nightly-only experimental API. (`exclusive_wrapper` [#98407](https://github.com/rust-lang/rust/issues/98407))
Wrap a value in an `Exclusive`
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#110)#### pub const fn into\_inner(self) -> T
🔬This is a nightly-only experimental API. (`exclusive_wrapper` [#98407](https://github.com/rust-lang/rust/issues/98407))
Unwrap the value contained in the `Exclusive`
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#115)### impl<T> Exclusive<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#119)#### pub const fn get\_mut(&mut self) -> &mut T
🔬This is a nightly-only experimental API. (`exclusive_wrapper` [#98407](https://github.com/rust-lang/rust/issues/98407))
Get exclusive access to the underlying value.
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#131)#### pub const fn get\_pin\_mut(self: Pin<&mut Exclusive<T>>) -> Pin<&mut T>
Notable traits for [Pin](../pin/struct.pin "struct std::pin::Pin")<P>
```
impl<P> Future for Pin<P>where
P: DerefMut,
<P as Deref>::Target: Future,
type Output = <<P as Deref>::Target as Future>::Output;
```
🔬This is a nightly-only experimental API. (`exclusive_wrapper` [#98407](https://github.com/rust-lang/rust/issues/98407))
Get pinned exclusive access to the underlying value.
`Exclusive` is considered to *structurally pin* the underlying value, which means *unpinned* `Exclusive`s can produce *unpinned* access to the underlying value, but *pinned* `Exclusive`s only produce *pinned* access to the underlying value.
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#142)#### pub const fn from\_mut(r: &mut T) -> &mut Exclusive<T>
Notable traits for [Exclusive](struct.exclusive "struct std::sync::Exclusive")<T>
```
impl<T> Future for Exclusive<T>where
T: Future + ?Sized,
type Output = <T as Future>::Output;
```
🔬This is a nightly-only experimental API. (`exclusive_wrapper` [#98407](https://github.com/rust-lang/rust/issues/98407))
Build a *mutable* references to an `Exclusive<T>` from a *mutable* reference to a `T`. This allows you to skip building an `Exclusive` with [`Exclusive::new`](struct.exclusive#method.new "Exclusive::new").
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#152)#### pub const fn from\_pin\_mut(r: Pin<&mut T>) -> Pin<&mut Exclusive<T>>
Notable traits for [Pin](../pin/struct.pin "struct std::pin::Pin")<P>
```
impl<P> Future for Pin<P>where
P: DerefMut,
<P as Deref>::Target: Future,
type Output = <<P as Deref>::Target as Future>::Output;
```
🔬This is a nightly-only experimental API. (`exclusive_wrapper` [#98407](https://github.com/rust-lang/rust/issues/98407))
Build a *pinned mutable* references to an `Exclusive<T>` from a *pinned mutable* reference to a `T`. This allows you to skip building an `Exclusive` with [`Exclusive::new`](struct.exclusive#method.new "Exclusive::new").
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#93)### impl<T> Debug for Exclusive<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#94)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#82)### impl<T> Default for Exclusive<T>where T: [Default](../default/trait.default "trait std::default::Default") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#82)#### fn default() -> Exclusive<T>
Notable traits for [Exclusive](struct.exclusive "struct std::sync::Exclusive")<T>
```
impl<T> Future for Exclusive<T>where
T: Future + ?Sized,
type Output = <T as Future>::Output;
```
Returns the “default value” for a type. [Read more](../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#160)### impl<T> From<T> for Exclusive<T>
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#161)#### fn from(t: T) -> Exclusive<T>
Notable traits for [Exclusive](struct.exclusive "struct std::sync::Exclusive")<T>
```
impl<T> Future for Exclusive<T>where
T: Future + ?Sized,
type Output = <T as Future>::Output;
```
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#167)### impl<T> Future for Exclusive<T>where T: [Future](../future/trait.future "trait std::future::Future") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
#### type Output = <T as Future>::Output
The type of value produced on completion.
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#170)#### fn poll( self: Pin<&mut Exclusive<T>>, cx: &mut Context<'\_>) -> Poll<<Exclusive<T> as Future>::Output>
Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. [Read more](../future/trait.future#tymethod.poll)
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#90)### impl<T> Sync for Exclusive<T>where T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Auto Trait Implementations
--------------------------
### impl<T: ?Sized> RefUnwindSafe for Exclusive<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T: ?Sized> Send for Exclusive<T>where T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T: ?Sized> Unpin for Exclusive<T>where T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> UnwindSafe for Exclusive<T>where T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#577)### impl<T> From<!> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#578)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: !) -> T
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/future/into_future.rs.html#132)### impl<F> IntoFuture for Fwhere F: [Future](../future/trait.future "trait std::future::Future"),
#### type Output = <F as Future>::Output
The output that the future will produce on completion.
#### type IntoFuture = F
Which kind of future are we turning this into?
[source](https://doc.rust-lang.org/src/core/future/into_future.rs.html#136)#### fn into\_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. [Read more](../future/trait.intofuture#tymethod.into_future)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::Condvar Struct std::sync::Condvar
=========================
```
pub struct Condvar { /* private fields */ }
```
A Condition Variable
Condition variables represent the ability to block a thread such that it consumes no CPU time while waiting for an event to occur. Condition variables are typically associated with a boolean predicate (a condition) and a mutex. The predicate is always verified inside of the mutex before determining that a thread must block.
Functions in this module will block the current **thread** of execution. Note that any attempt to use multiple mutexes on the same condition variable may result in a runtime panic.
Examples
--------
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
// Inside of our lock, spawn a new thread, and then wait for it to start.
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
*started = true;
// We notify the condvar that the value has changed.
cvar.notify_one();
});
// Wait for the thread to start up.
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
while !*started {
started = cvar.wait(started).unwrap();
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#113-549)### impl Condvar
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#128-130)const: 1.63.0 · #### pub const fn new() -> Condvar
Creates a new condition variable which is ready to be waited on and notified.
##### Examples
```
use std::sync::Condvar;
let condvar = Condvar::new();
```
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#188-195)#### pub fn wait<'a, T>( &self, guard: MutexGuard<'a, T>) -> LockResult<MutexGuard<'a, T>>
Blocks the current thread until this condition variable receives a notification.
This function will atomically unlock the mutex specified (represented by `guard`) and block the current thread. This means that any calls to [`notify_one`](struct.condvar#method.notify_one) or [`notify_all`](struct.condvar#method.notify_all) which happen logically after the mutex is unlocked are candidates to wake this thread up. When this function call returns, the lock specified will have been re-acquired.
Note that this function is susceptible to spurious wakeups. Condition variables normally have a boolean predicate associated with them, and the predicate must always be checked each time this function returns to protect against spurious wakeups.
##### Errors
This function will return an error if the mutex being waited on is poisoned when this thread re-acquires the lock. For more information, see information about [poisoning](struct.mutex#poisoning) on the [`Mutex`](struct.mutex) type.
##### Panics
This function may [`panic!`](../macro.panic "panic!") if it is used with more than one mutex over time.
##### Examples
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
*started = true;
// We notify the condvar that the value has changed.
cvar.notify_one();
});
// Wait for the thread to start up.
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
// As long as the value inside the `Mutex<bool>` is `false`, we wait.
while !*started {
started = cvar.wait(started).unwrap();
}
```
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#240-252)1.42.0 · #### pub fn wait\_while<'a, T, F>( &self, guard: MutexGuard<'a, T>, condition: F) -> LockResult<MutexGuard<'a, T>>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../primitive.reference) T) -> [bool](../primitive.bool),
Blocks the current thread until this condition variable receives a notification and the provided condition is false.
This function will atomically unlock the mutex specified (represented by `guard`) and block the current thread. This means that any calls to [`notify_one`](struct.condvar#method.notify_one) or [`notify_all`](struct.condvar#method.notify_all) which happen logically after the mutex is unlocked are candidates to wake this thread up. When this function call returns, the lock specified will have been re-acquired.
##### Errors
This function will return an error if the mutex being waited on is poisoned when this thread re-acquires the lock. For more information, see information about [poisoning](struct.mutex#poisoning) on the [`Mutex`](struct.mutex) type.
##### Examples
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
let pair = Arc::new((Mutex::new(true), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut pending = lock.lock().unwrap();
*pending = false;
// We notify the condvar that the value has changed.
cvar.notify_one();
});
// Wait for the thread to start up.
let (lock, cvar) = &*pair;
// As long as the value inside the `Mutex<bool>` is `true`, we wait.
let _guard = cvar.wait_while(lock.lock().unwrap(), |pending| { *pending }).unwrap();
```
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#309-316)#### pub fn wait\_timeout\_ms<'a, T>( &self, guard: MutexGuard<'a, T>, ms: u32) -> LockResult<(MutexGuard<'a, T>, bool)>
👎Deprecated since 1.6.0: replaced by `std::sync::Condvar::wait_timeout`
Waits on this condition variable for a notification, timing out after a specified duration.
The semantics of this function are equivalent to [`wait`](struct.condvar#method.wait) except that the thread will be blocked for roughly no longer than `ms` milliseconds. This method should not be used for precise timing due to anomalies such as preemption or platform differences that might not cause the maximum amount of time waited to be precisely `ms`.
Note that the best effort is made to ensure that the time waited is measured with a monotonic clock, and not affected by the changes made to the system time.
The returned boolean is `false` only if the timeout is known to have elapsed.
Like [`wait`](struct.condvar#method.wait), the lock specified will be re-acquired when this function returns, regardless of whether the timeout elapsed or not.
##### Examples
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
*started = true;
// We notify the condvar that the value has changed.
cvar.notify_one();
});
// Wait for the thread to start up.
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
// As long as the value inside the `Mutex<bool>` is `false`, we wait.
loop {
let result = cvar.wait_timeout_ms(started, 10).unwrap();
// 10 milliseconds have passed, or maybe the value changed!
started = result.0;
if *started == true {
// We received the notification and the value has been updated, we can leave.
break
}
}
```
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#380-391)1.5.0 · #### pub fn wait\_timeout<'a, T>( &self, guard: MutexGuard<'a, T>, dur: Duration) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
Waits on this condition variable for a notification, timing out after a specified duration.
The semantics of this function are equivalent to [`wait`](struct.condvar#method.wait) except that the thread will be blocked for roughly no longer than `dur`. This method should not be used for precise timing due to anomalies such as preemption or platform differences that might not cause the maximum amount of time waited to be precisely `dur`.
Note that the best effort is made to ensure that the time waited is measured with a monotonic clock, and not affected by the changes made to the system time. This function is susceptible to spurious wakeups. Condition variables normally have a boolean predicate associated with them, and the predicate must always be checked each time this function returns to protect against spurious wakeups. Additionally, it is typically desirable for the timeout to not exceed some duration in spite of spurious wakes, thus the sleep-duration is decremented by the amount slept. Alternatively, use the `wait_timeout_while` method to wait with a timeout while a predicate is true.
The returned [`WaitTimeoutResult`](struct.waittimeoutresult "WaitTimeoutResult") value indicates if the timeout is known to have elapsed.
Like [`wait`](struct.condvar#method.wait), the lock specified will be re-acquired when this function returns, regardless of whether the timeout elapsed or not.
##### Examples
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
use std::time::Duration;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
*started = true;
// We notify the condvar that the value has changed.
cvar.notify_one();
});
// wait for the thread to start up
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
// as long as the value inside the `Mutex<bool>` is `false`, we wait
loop {
let result = cvar.wait_timeout(started, Duration::from_millis(10)).unwrap();
// 10 milliseconds have passed, or maybe the value changed!
started = result.0;
if *started == true {
// We received the notification and the value has been updated, we can leave.
break
}
}
```
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#446-466)1.42.0 · #### pub fn wait\_timeout\_while<'a, T, F>( &self, guard: MutexGuard<'a, T>, dur: Duration, condition: F) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../primitive.reference) T) -> [bool](../primitive.bool),
Waits on this condition variable for a notification, timing out after a specified duration.
The semantics of this function are equivalent to [`wait_while`](struct.condvar#method.wait_while) except that the thread will be blocked for roughly no longer than `dur`. This method should not be used for precise timing due to anomalies such as preemption or platform differences that might not cause the maximum amount of time waited to be precisely `dur`.
Note that the best effort is made to ensure that the time waited is measured with a monotonic clock, and not affected by the changes made to the system time.
The returned [`WaitTimeoutResult`](struct.waittimeoutresult "WaitTimeoutResult") value indicates if the timeout is known to have elapsed without the condition being met.
Like [`wait_while`](struct.condvar#method.wait_while), the lock specified will be re-acquired when this function returns, regardless of whether the timeout elapsed or not.
##### Examples
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
use std::time::Duration;
let pair = Arc::new((Mutex::new(true), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut pending = lock.lock().unwrap();
*pending = false;
// We notify the condvar that the value has changed.
cvar.notify_one();
});
// wait for the thread to start up
let (lock, cvar) = &*pair;
let result = cvar.wait_timeout_while(
lock.lock().unwrap(),
Duration::from_millis(100),
|&mut pending| pending,
).unwrap();
if result.1.timed_out() {
// timed-out without the condition ever evaluating to false.
}
// access the locked mutex via result.0
```
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#506-508)#### pub fn notify\_one(&self)
Wakes up one blocked thread on this condvar.
If there is a blocked thread on this condition variable, then it will be woken up from its call to [`wait`](struct.condvar#method.wait) or [`wait_timeout`](struct.condvar#method.wait_timeout). Calls to `notify_one` are not buffered in any way.
To wake up all threads, see [`notify_all`](struct.condvar#method.notify_all).
##### Examples
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
*started = true;
// We notify the condvar that the value has changed.
cvar.notify_one();
});
// Wait for the thread to start up.
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
// As long as the value inside the `Mutex<bool>` is `false`, we wait.
while !*started {
started = cvar.wait(started).unwrap();
}
```
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#546-548)#### pub fn notify\_all(&self)
Wakes up all blocked threads on this condvar.
This method will ensure that any current waiters on the condition variable are awoken. Calls to `notify_all()` are not buffered in any way.
To wake up only one thread, see [`notify_one`](struct.condvar#method.notify_one).
##### Examples
```
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move|| {
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
*started = true;
// We notify the condvar that the value has changed.
cvar.notify_all();
});
// Wait for the thread to start up.
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
// As long as the value inside the `Mutex<bool>` is `false`, we wait.
while !*started {
started = cvar.wait(started).unwrap();
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#552-556)1.16.0 · ### impl Debug for Condvar
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#553-555)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#559-564)1.10.0 · ### impl Default for Condvar
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#561-563)#### fn default() -> Condvar
Creates a `Condvar` which is ready to be waited on and notified.
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for Condvar
### impl Send for Condvar
### impl Sync for Condvar
### impl Unpin for Condvar
### impl UnwindSafe for Condvar
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::OnceLock Struct std::sync::OnceLock
==========================
```
pub struct OnceLock<T> { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
A synchronization primitive which can be written to only once.
This type is a thread-safe `OnceCell`.
Examples
--------
```
#![feature(once_cell)]
use std::sync::OnceLock;
static CELL: OnceLock<String> = OnceLock::new();
assert!(CELL.get().is_none());
std::thread::spawn(|| {
let value: &String = CELL.get_or_init(|| {
"Hello, World!".to_string()
});
assert_eq!(value, "Hello, World!");
}).join().unwrap();
let value: Option<&String> = CELL.get();
assert!(value.is_some());
assert_eq!(value.unwrap().as_str(), "Hello, World!");
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#60-328)### impl<T> OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#64-70)#### pub const fn new() -> OnceLock<T>
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Creates a new empty cell.
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#77-84)#### pub fn get(&self) -> Option<&T>
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Gets the reference to the underlying value.
Returns `None` if the cell is empty, or being initialized. This method never blocks.
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#90-97)#### pub fn get\_mut(&mut self) -> Option<&mut T>
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Gets the mutable reference to the underlying value.
Returns `None` if the cell is empty. This method never blocks.
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#127-134)#### pub fn set(&self, value: T) -> Result<(), T>
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Sets the contents of this cell to `value`.
May block if another thread is currently attempting to initialize the cell. The cell is guaranteed to contain a value when set returns, though not necessarily the one provided.
Returns `Ok(())` if the cell’s value was set by this call.
##### Examples
```
#![feature(once_cell)]
use std::sync::OnceLock;
static CELL: OnceLock<i32> = OnceLock::new();
fn main() {
assert!(CELL.get().is_none());
std::thread::spawn(|| {
assert_eq!(CELL.set(92), Ok(()));
}).join().unwrap();
assert_eq!(CELL.set(62), Err(62));
assert_eq!(CELL.get(), Some(&92));
}
```
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#166-173)#### pub fn get\_or\_init<F>(&self, f: F) -> &Twhere F: [FnOnce](../ops/trait.fnonce "trait std::ops::FnOnce")() -> T,
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Gets the contents of the cell, initializing it with `f` if the cell was empty.
Many threads may call `get_or_init` concurrently with different initializing functions, but it is guaranteed that only one function will be executed.
##### Panics
If `f` panics, the panic is propagated to the caller, and the cell remains uninitialized.
It is an error to reentrantly initialize the cell from `f`. The exact outcome is unspecified. Current implementation deadlocks, but this may be changed to a panic in the future.
##### Examples
```
#![feature(once_cell)]
use std::sync::OnceLock;
let cell = OnceLock::new();
let value = cell.get_or_init(|| 92);
assert_eq!(value, &92);
let value = cell.get_or_init(|| unreachable!());
assert_eq!(value, &92);
```
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#205-223)#### pub fn get\_or\_try\_init<F, E>(&self, f: F) -> Result<&T, E>where F: [FnOnce](../ops/trait.fnonce "trait std::ops::FnOnce")() -> [Result](../result/enum.result "enum std::result::Result")<T, E>,
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Gets the contents of the cell, initializing it with `f` if the cell was empty. If the cell was empty and `f` failed, an error is returned.
##### Panics
If `f` panics, the panic is propagated to the caller, and the cell remains uninitialized.
It is an error to reentrantly initialize the cell from `f`. The exact outcome is unspecified. Current implementation deadlocks, but this may be changed to a panic in the future.
##### Examples
```
#![feature(once_cell)]
use std::sync::OnceLock;
let cell = OnceLock::new();
assert_eq!(cell.get_or_try_init(|| Err(())), Err(()));
assert!(cell.get().is_none());
let value = cell.get_or_try_init(|| -> Result<i32, ()> {
Ok(92)
});
assert_eq!(value, Ok(&92));
assert_eq!(cell.get(), Some(&92))
```
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#243-245)#### pub fn into\_inner(self) -> Option<T>
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Consumes the `OnceLock`, returning the wrapped value. Returns `None` if the cell was empty.
##### Examples
```
#![feature(once_cell)]
use std::sync::OnceLock;
let cell: OnceLock<String> = OnceLock::new();
assert_eq!(cell.into_inner(), None);
let cell = OnceLock::new();
cell.set("hello".to_string()).unwrap();
assert_eq!(cell.into_inner(), Some("hello".to_string()));
```
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#269-279)#### pub fn take(&mut self) -> Option<T>
🔬This is a nightly-only experimental API. (`once_cell` [#74465](https://github.com/rust-lang/rust/issues/74465))
Takes the value out of this `OnceLock`, moving it back to an uninitialized state.
Has no effect and returns `None` if the `OnceLock` hasn’t been initialized.
Safety is guaranteed by requiring a mutable reference.
##### Examples
```
#![feature(once_cell)]
use std::sync::OnceLock;
let mut cell: OnceLock<String> = OnceLock::new();
assert_eq!(cell.take(), None);
let mut cell = OnceLock::new();
cell.set("hello".to_string()).unwrap();
assert_eq!(cell.take(), Some("hello".to_string()));
assert_eq!(cell.get(), None);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#377-388)### impl<T: Clone> Clone for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#378-387)#### fn clone(&self) -> OnceLock<T>
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#367-374)### impl<T: Debug> Debug for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#368-373)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#347-364)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl<T> Default for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#361-363)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> OnceLock<T>
Creates a new empty cell.
##### Example
```
#![feature(once_cell)]
use std::sync::OnceLock;
fn main() {
assert_eq!(OnceLock::<()>::new(), OnceLock::default());
}
```
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#429-438)### impl<T> Drop for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#430-437)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#391-416)### impl<T> From<T> for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#409-415)#### fn from(value: T) -> Self
Create a new cell with its contents set to `value`.
##### Example
```
#![feature(once_cell)]
use std::sync::OnceLock;
let a = OnceLock::from(3);
let b = OnceLock::new();
b.set(3)?;
assert_eq!(a, b);
Ok(())
```
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#419-423)### impl<T: PartialEq> PartialEq<OnceLock<T>> for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#420-422)#### fn eq(&self, other: &OnceLock<T>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#426)### impl<T: Eq> Eq for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#341)### impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#338)### impl<T: Send> Send for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#336)### impl<T: Sync + Send> Sync for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#343)### impl<T: UnwindSafe> UnwindSafe for OnceLock<T>
Auto Trait Implementations
--------------------------
### impl<T> Unpin for OnceLock<T>where T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#577)### impl<T> From<!> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#578)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: !) -> T
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::WaitTimeoutResult Struct std::sync::WaitTimeoutResult
===================================
```
pub struct WaitTimeoutResult(_);
```
A type indicating whether a timed wait on a condition variable returned due to a time out or not.
It is returned by the [`wait_timeout`](struct.condvar#method.wait_timeout) method.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#19-69)### impl WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#66-68)#### pub fn timed\_out(&self) -> bool
Returns `true` if the wait was known to have timed out.
##### Examples
This example spawns a thread which will update the boolean value and then wait 100 milliseconds before notifying the condvar.
The main thread will wait with a timeout on the condvar and then leave once the boolean has been updated and notified.
```
use std::sync::{Arc, Condvar, Mutex};
use std::thread;
use std::time::Duration;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
thread::spawn(move || {
let (lock, cvar) = &*pair2;
// Let's wait 20 milliseconds before notifying the condvar.
thread::sleep(Duration::from_millis(20));
let mut started = lock.lock().unwrap();
// We update the boolean value.
*started = true;
cvar.notify_one();
});
// Wait for the thread to start up.
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
loop {
// Let's put a timeout on the condvar's wait.
let result = cvar.wait_timeout(started, Duration::from_millis(10)).unwrap();
// 10 milliseconds have passed, or maybe the value changed!
started = result.0;
if *started == true {
// We received the notification and the value has been updated, we can leave.
break
}
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)### impl Clone for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)#### fn clone(&self) -> WaitTimeoutResult
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)### impl Debug for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)### impl PartialEq<WaitTimeoutResult> for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)#### fn eq(&self, other: &WaitTimeoutResult) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)### impl Copy for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)### impl Eq for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)### impl StructuralEq for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)### impl StructuralPartialEq for WaitTimeoutResult
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for WaitTimeoutResult
### impl Send for WaitTimeoutResult
### impl Sync for WaitTimeoutResult
### impl Unpin for WaitTimeoutResult
### impl UnwindSafe for WaitTimeoutResult
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::OnceState Struct std::sync::OnceState
===========================
```
pub struct OnceState { /* private fields */ }
```
State yielded to [`Once::call_once_force()`](struct.once#method.call_once_force "Once::call_once_force()")’s closure parameter. The state can be used to query the poison status of the [`Once`](struct.once "Once").
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#535-580)### impl OnceState
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#571-573)#### pub fn is\_poisoned(&self) -> bool
Returns `true` if the associated [`Once`](struct.once "Once") was poisoned prior to the invocation of the closure passed to [`Once::call_once_force()`](struct.once#method.call_once_force "Once::call_once_force()").
##### Examples
A poisoned [`Once`](struct.once "Once"):
```
use std::sync::Once;
use std::thread;
static INIT: Once = Once::new();
// poison the once
let handle = thread::spawn(|| {
INIT.call_once(|| panic!());
});
assert!(handle.join().is_err());
INIT.call_once_force(|state| {
assert!(state.is_poisoned());
});
```
An unpoisoned [`Once`](struct.once "Once"):
```
use std::sync::Once;
static INIT: Once = Once::new();
INIT.call_once_force(|state| {
assert!(!state.is_poisoned());
});
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#139)### impl Debug for OnceState
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#139)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl !RefUnwindSafe for OnceState
### impl !Send for OnceState
### impl !Sync for OnceState
### impl Unpin for OnceState
### impl UnwindSafe for OnceState
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::atomic::AtomicI16 Struct std::sync::atomic::AtomicI16
===================================
```
#[repr(C, align(2))]pub struct AtomicI16 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`i16`](../../primitive.i16 "i16"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`i16`](../../primitive.i16 "i16").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)### impl AtomicI16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)const: 1.34.0 · #### pub const fn new(v: i16) -> AtomicI16
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicI16;
let atomic_forty_two = AtomicI16::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn get\_mut(&mut self) -> &mut i16
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let mut some_var = AtomicI16::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn from\_mut(v: &mut i16) -> &mut AtomicI16
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut i16`.
**Note:** This function is only available on targets where `i16` has an alignment of 2 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI16, Ordering};
let mut some_int = 123;
let a = AtomicI16::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn get\_mut\_slice(this: &mut [AtomicI16]) -> &mut [i16]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicI16]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicI16, Ordering};
let mut some_ints = [const { AtomicI16::new(0) }; 10];
let view: &mut [i16] = AtomicI16::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn from\_mut\_slice(v: &mut [i16]) -> &mut [AtomicI16]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [i16]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI16, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicI16::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> i16
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicI16;
let some_var = AtomicI16::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn load(&self, order: Ordering) -> i16
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let some_var = AtomicI16::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn store(&self, val: i16, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let some_var = AtomicI16::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn swap(&self, val: i16, order: Ordering) -> i16
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let some_var = AtomicI16::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn compare\_and\_swap(&self, current: i16, new: i16, order: Ordering) -> i16
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let some_var = AtomicI16::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn compare\_exchange( &self, current: i16, new: i16, success: Ordering, failure: Ordering) -> Result<i16, i16>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let some_var = AtomicI16::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn compare\_exchange\_weak( &self, current: i16, new: i16, success: Ordering, failure: Ordering) -> Result<i16, i16>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicI16::compare_exchange`](struct.atomici16#method.compare_exchange "AtomicI16::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let val = AtomicI16::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn fetch\_add(&self, val: i16, order: Ordering) -> i16
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn fetch\_sub(&self, val: i16, order: Ordering) -> i16
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn fetch\_and(&self, val: i16, order: Ordering) -> i16
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn fetch\_nand(&self, val: i16, order: Ordering) -> i16
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn fetch\_or(&self, val: i16, order: Ordering) -> i16
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn fetch\_xor(&self, val: i16, order: Ordering) -> i16
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<i16, i16>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([i16](../../primitive.i16)) -> [Option](../../option/enum.option "enum std::option::Option")<[i16](../../primitive.i16)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicI16::compare_exchange`](struct.atomici16#method.compare_exchange "AtomicI16::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let x = AtomicI16::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)1.45.0 · #### pub fn fetch\_max(&self, val: i16, order: Ordering) -> i16
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)1.45.0 · #### pub fn fetch\_min(&self, val: i16, order: Ordering) -> i16
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i16`](../../primitive.i16 "i16").
##### Examples
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI16, Ordering};
let foo = AtomicI16::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### pub fn as\_mut\_ptr(&self) -> \*mut i16
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut i16` instead of `&AtomicI16`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicI16;
extern "C" {
fn my_atomic_op(arg: *mut i16);
}
let mut atomic = AtomicI16::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)### impl Debug for AtomicI16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicI16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicI16
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<i16> for AtomicI16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: i16) -> AtomicI16
Converts an `i16` into an `AtomicI16`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#212)### impl RefUnwindSafe for AtomicI16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)### impl Sync for AtomicI16
Auto Trait Implementations
--------------------------
### impl Send for AtomicI16
### impl Unpin for AtomicI16
### impl UnwindSafe for AtomicI16
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Constant std::sync::atomic::ATOMIC_BOOL_INIT Constant std::sync::atomic::ATOMIC\_BOOL\_INIT
==============================================
```
pub const ATOMIC_BOOL_INIT: AtomicBool;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
An [`AtomicBool`](struct.atomicbool "AtomicBool") initialized to `false`.
rust Function std::sync::atomic::compiler_fence Function std::sync::atomic::compiler\_fence
===========================================
```
pub fn compiler_fence(order: Ordering)
```
A compiler memory fence.
`compiler_fence` does not emit any machine code, but restricts the kinds of memory re-ordering the compiler is allowed to do. Specifically, depending on the given [`Ordering`](enum.ordering "Ordering") semantics, the compiler may be disallowed from moving reads or writes from before or after the call to the other side of the call to `compiler_fence`. Note that it does **not** prevent the *hardware* from doing such re-ordering. This is not a problem in a single-threaded, execution context, but when other threads may modify memory at the same time, stronger synchronization primitives such as [`fence`](fn.fence "fence") are required.
The re-ordering prevented by the different ordering semantics are:
* with [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), no re-ordering of reads and writes across this point is allowed.
* with [`Release`](enum.ordering#variant.Release "Release"), preceding reads and writes cannot be moved past subsequent writes.
* with [`Acquire`](enum.ordering#variant.Acquire "Acquire"), subsequent reads and writes cannot be moved ahead of preceding reads.
* with [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), both of the above rules are enforced.
`compiler_fence` is generally only useful for preventing a thread from racing *with itself*. That is, if a given thread is executing one piece of code, and is then interrupted, and starts executing code elsewhere (while still in the same thread, and conceptually still on the same core). In traditional programs, this can only occur when a signal handler is registered. In more low-level code, such situations can also arise when handling interrupts, when implementing green threads with pre-emption, etc. Curious readers are encouraged to read the Linux kernel’s discussion of [memory barriers](https://www.kernel.org/doc/Documentation/memory-barriers.txt).
Panics
------
Panics if `order` is [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
Examples
--------
Without `compiler_fence`, the `assert_eq!` in following code is *not* guaranteed to succeed, despite everything happening in a single thread. To see why, remember that the compiler is free to swap the stores to `IMPORTANT_VARIABLE` and `IS_READY` since they are both `Ordering::Relaxed`. If it does, and the signal handler is invoked right after `IS_READY` is updated, then the signal handler will see `IS_READY=1`, but `IMPORTANT_VARIABLE=0`. Using a `compiler_fence` remedies this situation.
```
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::sync::atomic::Ordering;
use std::sync::atomic::compiler_fence;
static IMPORTANT_VARIABLE: AtomicUsize = AtomicUsize::new(0);
static IS_READY: AtomicBool = AtomicBool::new(false);
fn main() {
IMPORTANT_VARIABLE.store(42, Ordering::Relaxed);
// prevent earlier writes from being moved beyond this point
compiler_fence(Ordering::Release);
IS_READY.store(true, Ordering::Relaxed);
}
fn signal_handler() {
if IS_READY.load(Ordering::Relaxed) {
assert_eq!(IMPORTANT_VARIABLE.load(Ordering::Relaxed), 42);
}
}
```
rust Constant std::sync::atomic::ATOMIC_U16_INIT Constant std::sync::atomic::ATOMIC\_U16\_INIT
=============================================
```
pub const ATOMIC_U16_INIT: AtomicU16;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Module std::sync::atomic Module std::sync::atomic
========================
Atomic types
Atomic types provide primitive shared-memory communication between threads, and are the building blocks of other concurrent types.
Rust atomics currently follow the same rules as [C++20 atomics](https://en.cppreference.com/w/cpp/atomic), specifically `atomic_ref`. Basically, creating a *shared reference* to one of the Rust atomic types corresponds to creating an `atomic_ref` in C++; the `atomic_ref` is destroyed when the lifetime of the shared reference ends. (A Rust atomic type that is exclusively owned or behind a mutable reference does *not* correspond to an “atomic object” in C++, since it can be accessed via non-atomic operations.)
This module defines atomic versions of a select number of primitive types, including [`AtomicBool`](struct.atomicbool "AtomicBool"), [`AtomicIsize`](struct.atomicisize "AtomicIsize"), [`AtomicUsize`](struct.atomicusize "AtomicUsize"), [`AtomicI8`](struct.atomici8 "AtomicI8"), [`AtomicU16`](struct.atomicu16 "AtomicU16"), etc. Atomic types present operations that, when used correctly, synchronize updates between threads.
Each method takes an [`Ordering`](enum.ordering "Ordering") which represents the strength of the memory barrier for that operation. These orderings are the same as the [C++20 atomic orderings](https://en.cppreference.com/w/cpp/atomic/memory_order). For more information see the [nomicon](https://doc.rust-lang.org/nomicon/atomics.html).
Atomic variables are safe to share between threads (they implement [`Sync`](../../marker/trait.sync "Sync")) but they do not themselves provide the mechanism for sharing and follow the [threading model](../../thread/index#the-threading-model) of Rust. The most common way to share an atomic variable is to put it into an [`Arc`](../struct.arc) (an atomically-reference-counted shared pointer).
Atomic types may be stored in static variables, initialized using the constant initializers like [`AtomicBool::new`](struct.atomicbool#method.new "AtomicBool::new"). Atomic statics are often used for lazy global initialization.
Portability
-----------
All atomic types in this module are guaranteed to be [lock-free](https://en.wikipedia.org/wiki/Non-blocking_algorithm) if they’re available. This means they don’t internally acquire a global mutex. Atomic types and operations are not guaranteed to be wait-free. This means that operations like `fetch_or` may be implemented with a compare-and-swap loop.
Atomic operations may be implemented at the instruction layer with larger-size atomics. For example some platforms use 4-byte atomic instructions to implement `AtomicI8`. Note that this emulation should not have an impact on correctness of code, it’s just something to be aware of.
The atomic types in this module might not be available on all platforms. The atomic types here are all widely available, however, and can generally be relied upon existing. Some notable exceptions are:
* PowerPC and MIPS platforms with 32-bit pointers do not have `AtomicU64` or `AtomicI64` types.
* ARM platforms like `armv5te` that aren’t for Linux only provide `load` and `store` operations, and do not support Compare and Swap (CAS) operations, such as `swap`, `fetch_add`, etc. Additionally on Linux, these CAS operations are implemented via [operating system support](https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt), which may come with a performance penalty.
* ARM targets with `thumbv6m` only provide `load` and `store` operations, and do not support Compare and Swap (CAS) operations, such as `swap`, `fetch_add`, etc.
Note that future platforms may be added that also do not have support for some atomic operations. Maximally portable code will want to be careful about which atomic types are used. `AtomicUsize` and `AtomicIsize` are generally the most portable, but even then they’re not available everywhere. For reference, the `std` library requires `AtomicBool`s and pointer-sized atomics, although `core` does not.
The `#[cfg(target_has_atomic)]` attribute can be used to conditionally compile based on the target’s supported bit widths. It is a key-value option set for each supported size, with values “8”, “16”, “32”, “64”, “128”, and “ptr” for pointer-sized atomics.
Examples
--------
A simple spinlock:
```
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{hint, thread};
fn main() {
let spinlock = Arc::new(AtomicUsize::new(1));
let spinlock_clone = Arc::clone(&spinlock);
let thread = thread::spawn(move|| {
spinlock_clone.store(0, Ordering::SeqCst);
});
// Wait for the other thread to release the lock
while spinlock.load(Ordering::SeqCst) != 0 {
hint::spin_loop();
}
if let Err(panic) = thread.join() {
println!("Thread had an error: {panic:?}");
}
}
```
Keep a global count of live threads:
```
use std::sync::atomic::{AtomicUsize, Ordering};
static GLOBAL_THREAD_COUNT: AtomicUsize = AtomicUsize::new(0);
let old_thread_count = GLOBAL_THREAD_COUNT.fetch_add(1, Ordering::SeqCst);
println!("live threads: {}", old_thread_count + 1);
```
Structs
-------
[AtomicBool](struct.atomicbool "std::sync::atomic::AtomicBool struct")
A boolean type which can be safely shared between threads.
[AtomicI8](struct.atomici8 "std::sync::atomic::AtomicI8 struct")
An integer type which can be safely shared between threads.
[AtomicI16](struct.atomici16 "std::sync::atomic::AtomicI16 struct")
An integer type which can be safely shared between threads.
[AtomicI32](struct.atomici32 "std::sync::atomic::AtomicI32 struct")
An integer type which can be safely shared between threads.
[AtomicI64](struct.atomici64 "std::sync::atomic::AtomicI64 struct")
An integer type which can be safely shared between threads.
[AtomicIsize](struct.atomicisize "std::sync::atomic::AtomicIsize struct")
An integer type which can be safely shared between threads.
[AtomicPtr](struct.atomicptr "std::sync::atomic::AtomicPtr struct")
A raw pointer type which can be safely shared between threads.
[AtomicU8](struct.atomicu8 "std::sync::atomic::AtomicU8 struct")
An integer type which can be safely shared between threads.
[AtomicU16](struct.atomicu16 "std::sync::atomic::AtomicU16 struct")
An integer type which can be safely shared between threads.
[AtomicU32](struct.atomicu32 "std::sync::atomic::AtomicU32 struct")
An integer type which can be safely shared between threads.
[AtomicU64](struct.atomicu64 "std::sync::atomic::AtomicU64 struct")
An integer type which can be safely shared between threads.
[AtomicUsize](struct.atomicusize "std::sync::atomic::AtomicUsize struct")
An integer type which can be safely shared between threads.
Enums
-----
[Ordering](enum.ordering "std::sync::atomic::Ordering enum")
Atomic memory orderings
Constants
---------
[ATOMIC\_I8\_INIT](constant.atomic_i8_init "std::sync::atomic::ATOMIC_I8_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_I16\_INIT](constant.atomic_i16_init "std::sync::atomic::ATOMIC_I16_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_I32\_INIT](constant.atomic_i32_init "std::sync::atomic::ATOMIC_I32_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_I64\_INIT](constant.atomic_i64_init "std::sync::atomic::ATOMIC_I64_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_U8\_INIT](constant.atomic_u8_init "std::sync::atomic::ATOMIC_U8_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_U16\_INIT](constant.atomic_u16_init "std::sync::atomic::ATOMIC_U16_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_U32\_INIT](constant.atomic_u32_init "std::sync::atomic::ATOMIC_U32_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_U64\_INIT](constant.atomic_u64_init "std::sync::atomic::ATOMIC_U64_INIT constant")DeprecatedExperimental
An atomic integer initialized to `0`.
[ATOMIC\_BOOL\_INIT](constant.atomic_bool_init "std::sync::atomic::ATOMIC_BOOL_INIT constant")Deprecated
An [`AtomicBool`](struct.atomicbool "AtomicBool") initialized to `false`.
[ATOMIC\_ISIZE\_INIT](constant.atomic_isize_init "std::sync::atomic::ATOMIC_ISIZE_INIT constant")Deprecated
An atomic integer initialized to `0`.
[ATOMIC\_USIZE\_INIT](constant.atomic_usize_init "std::sync::atomic::ATOMIC_USIZE_INIT constant")Deprecated
An atomic integer initialized to `0`.
Functions
---------
[compiler\_fence](fn.compiler_fence "std::sync::atomic::compiler_fence fn")
A compiler memory fence.
[fence](fn.fence "std::sync::atomic::fence fn")
An atomic fence.
[spin\_loop\_hint](fn.spin_loop_hint "std::sync::atomic::spin_loop_hint fn")Deprecated
Signals the processor that it is inside a busy-wait spin-loop (“spin lock”).
rust Constant std::sync::atomic::ATOMIC_U8_INIT Constant std::sync::atomic::ATOMIC\_U8\_INIT
============================================
```
pub const ATOMIC_U8_INIT: AtomicU8;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Function std::sync::atomic::fence Function std::sync::atomic::fence
=================================
```
pub fn fence(order: Ordering)
```
An atomic fence.
Depending on the specified order, a fence prevents the compiler and CPU from reordering certain types of memory operations around it. That creates synchronizes-with relationships between it and atomic operations or fences in other threads.
A fence ‘A’ which has (at least) [`Release`](enum.ordering#variant.Release "Release") ordering semantics, synchronizes with a fence ‘B’ with (at least) [`Acquire`](enum.ordering#variant.Acquire "Acquire") semantics, if and only if there exist operations X and Y, both operating on some atomic object ‘M’ such that A is sequenced before X, Y is sequenced before B and Y observes the change to M. This provides a happens-before dependence between A and B.
```
Thread 1 Thread 2
fence(Release); A --------------
x.store(3, Relaxed); X --------- |
| |
| |
-------------> Y if x.load(Relaxed) == 3 {
|-------> B fence(Acquire);
...
}
```
Atomic operations with [`Release`](enum.ordering#variant.Release "Release") or [`Acquire`](enum.ordering#variant.Acquire "Acquire") semantics can also synchronize with a fence.
A fence which has [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst") ordering, in addition to having both [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Release`](enum.ordering#variant.Release "Release") semantics, participates in the global program order of the other [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst") operations and/or fences.
Accepts [`Acquire`](enum.ordering#variant.Acquire "Acquire"), [`Release`](enum.ordering#variant.Release "Release"), [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel") and [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst") orderings.
Panics
------
Panics if `order` is [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
Examples
--------
```
use std::sync::atomic::AtomicBool;
use std::sync::atomic::fence;
use std::sync::atomic::Ordering;
// A mutual exclusion primitive based on spinlock.
pub struct Mutex {
flag: AtomicBool,
}
impl Mutex {
pub fn new() -> Mutex {
Mutex {
flag: AtomicBool::new(false),
}
}
pub fn lock(&self) {
// Wait until the old value is `false`.
while self
.flag
.compare_exchange_weak(false, true, Ordering::Relaxed, Ordering::Relaxed)
.is_err()
{}
// This fence synchronizes-with store in `unlock`.
fence(Ordering::Acquire);
}
pub fn unlock(&self) {
self.flag.store(false, Ordering::Release);
}
}
```
rust Struct std::sync::atomic::AtomicUsize Struct std::sync::atomic::AtomicUsize
=====================================
```
#[repr(C, align(8))]pub struct AtomicUsize { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`usize`](../../primitive.usize "usize"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`usize`](../../primitive.usize "usize").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)### impl AtomicUsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: 1.24.0 · #### pub const fn new(v: usize) -> AtomicUsize
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicUsize;
let atomic_forty_two = AtomicUsize::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.15.0 · #### pub fn get\_mut(&mut self) -> &mut usize
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let mut some_var = AtomicUsize::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn from\_mut(v: &mut usize) -> &mut AtomicUsize
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut usize`.
**Note:** This function is only available on targets where `usize` has an alignment of 8 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicUsize, Ordering};
let mut some_int = 123;
let a = AtomicUsize::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn get\_mut\_slice(this: &mut [AtomicUsize]) -> &mut [usize]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicUsize]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicUsize, Ordering};
let mut some_ints = [const { AtomicUsize::new(0) }; 10];
let view: &mut [usize] = AtomicUsize::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn from\_mut\_slice(v: &mut [usize]) -> &mut [AtomicUsize]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [usize]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicUsize, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicUsize::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.15.0 (const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner")) · #### pub fn into\_inner(self) -> usize
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicUsize;
let some_var = AtomicUsize::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn load(&self, order: Ordering) -> usize
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let some_var = AtomicUsize::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn store(&self, val: usize, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let some_var = AtomicUsize::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn swap(&self, val: usize, order: Ordering) -> usize
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let some_var = AtomicUsize::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn compare\_and\_swap( &self, current: usize, new: usize, order: Ordering) -> usize
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let some_var = AtomicUsize::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.10.0 · #### pub fn compare\_exchange( &self, current: usize, new: usize, success: Ordering, failure: Ordering) -> Result<usize, usize>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let some_var = AtomicUsize::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.10.0 · #### pub fn compare\_exchange\_weak( &self, current: usize, new: usize, success: Ordering, failure: Ordering) -> Result<usize, usize>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicUsize::compare_exchange`](struct.atomicusize#method.compare_exchange "AtomicUsize::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let val = AtomicUsize::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_add(&self, val: usize, order: Ordering) -> usize
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_sub(&self, val: usize, order: Ordering) -> usize
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_and(&self, val: usize, order: Ordering) -> usize
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.27.0 · #### pub fn fetch\_nand(&self, val: usize, order: Ordering) -> usize
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_or(&self, val: usize, order: Ordering) -> usize
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_xor(&self, val: usize, order: Ordering) -> usize
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<usize, usize>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([usize](../../primitive.usize)) -> [Option](../../option/enum.option "enum std::option::Option")<[usize](../../primitive.usize)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicUsize::compare_exchange`](struct.atomicusize#method.compare_exchange "AtomicUsize::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let x = AtomicUsize::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.45.0 · #### pub fn fetch\_max(&self, val: usize, order: Ordering) -> usize
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.45.0 · #### pub fn fetch\_min(&self, val: usize, order: Ordering) -> usize
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicUsize, Ordering};
let foo = AtomicUsize::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn as\_mut\_ptr(&self) -> \*mut usize
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut usize` instead of `&AtomicUsize`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicUsize;
extern "C" {
fn my_atomic_op(arg: *mut usize);
}
let mut atomic = AtomicUsize::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.3.0 · ### impl Debug for AtomicUsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicUsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicUsize
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.23.0 (const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num")) · ### impl From<usize> for AtomicUsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: usize) -> AtomicUsize
Converts an `usize` into an `AtomicUsize`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#225)1.14.0 · ### impl RefUnwindSafe for AtomicUsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)### impl Sync for AtomicUsize
Auto Trait Implementations
--------------------------
### impl Send for AtomicUsize
### impl Unpin for AtomicUsize
### impl UnwindSafe for AtomicUsize
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::atomic::AtomicU16 Struct std::sync::atomic::AtomicU16
===================================
```
#[repr(C, align(2))]pub struct AtomicU16 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`u16`](../../primitive.u16 "u16"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`u16`](../../primitive.u16 "u16").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)### impl AtomicU16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)const: 1.34.0 · #### pub const fn new(v: u16) -> AtomicU16
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicU16;
let atomic_forty_two = AtomicU16::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn get\_mut(&mut self) -> &mut u16
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let mut some_var = AtomicU16::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn from\_mut(v: &mut u16) -> &mut AtomicU16
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut u16`.
**Note:** This function is only available on targets where `u16` has an alignment of 2 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU16, Ordering};
let mut some_int = 123;
let a = AtomicU16::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn get\_mut\_slice(this: &mut [AtomicU16]) -> &mut [u16]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicU16]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicU16, Ordering};
let mut some_ints = [const { AtomicU16::new(0) }; 10];
let view: &mut [u16] = AtomicU16::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn from\_mut\_slice(v: &mut [u16]) -> &mut [AtomicU16]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [u16]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU16, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicU16::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> u16
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicU16;
let some_var = AtomicU16::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn load(&self, order: Ordering) -> u16
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let some_var = AtomicU16::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn store(&self, val: u16, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let some_var = AtomicU16::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn swap(&self, val: u16, order: Ordering) -> u16
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let some_var = AtomicU16::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn compare\_and\_swap(&self, current: u16, new: u16, order: Ordering) -> u16
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let some_var = AtomicU16::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn compare\_exchange( &self, current: u16, new: u16, success: Ordering, failure: Ordering) -> Result<u16, u16>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let some_var = AtomicU16::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn compare\_exchange\_weak( &self, current: u16, new: u16, success: Ordering, failure: Ordering) -> Result<u16, u16>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicU16::compare_exchange`](struct.atomicu16#method.compare_exchange "AtomicU16::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let val = AtomicU16::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn fetch\_add(&self, val: u16, order: Ordering) -> u16
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn fetch\_sub(&self, val: u16, order: Ordering) -> u16
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn fetch\_and(&self, val: u16, order: Ordering) -> u16
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn fetch\_nand(&self, val: u16, order: Ordering) -> u16
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn fetch\_or(&self, val: u16, order: Ordering) -> u16
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn fetch\_xor(&self, val: u16, order: Ordering) -> u16
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<u16, u16>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([u16](../../primitive.u16)) -> [Option](../../option/enum.option "enum std::option::Option")<[u16](../../primitive.u16)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicU16::compare_exchange`](struct.atomicu16#method.compare_exchange "AtomicU16::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let x = AtomicU16::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)1.45.0 · #### pub fn fetch\_max(&self, val: u16, order: Ordering) -> u16
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)1.45.0 · #### pub fn fetch\_min(&self, val: u16, order: Ordering) -> u16
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u16`](../../primitive.u16 "u16").
##### Examples
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU16, Ordering};
let foo = AtomicU16::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### pub fn as\_mut\_ptr(&self) -> \*mut u16
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut u16` instead of `&AtomicU16`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicU16;
extern "C" {
fn my_atomic_op(arg: *mut u16);
}
let mut atomic = AtomicU16::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)### impl Debug for AtomicU16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicU16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicU16
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<u16> for AtomicU16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: u16) -> AtomicU16
Converts an `u16` into an `AtomicU16`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#231)### impl RefUnwindSafe for AtomicU16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)### impl Sync for AtomicU16
Auto Trait Implementations
--------------------------
### impl Send for AtomicU16
### impl Unpin for AtomicU16
### impl UnwindSafe for AtomicU16
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Constant std::sync::atomic::ATOMIC_I16_INIT Constant std::sync::atomic::ATOMIC\_I16\_INIT
=============================================
```
pub const ATOMIC_I16_INIT: AtomicI16;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Constant std::sync::atomic::ATOMIC_I8_INIT Constant std::sync::atomic::ATOMIC\_I8\_INIT
============================================
```
pub const ATOMIC_I8_INIT: AtomicI8;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Struct std::sync::atomic::AtomicI32 Struct std::sync::atomic::AtomicI32
===================================
```
#[repr(C, align(4))]pub struct AtomicI32 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`i32`](../../primitive.i32 "i32"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`i32`](../../primitive.i32 "i32").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)### impl AtomicI32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)const: 1.34.0 · #### pub const fn new(v: i32) -> AtomicI32
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicI32;
let atomic_forty_two = AtomicI32::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn get\_mut(&mut self) -> &mut i32
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let mut some_var = AtomicI32::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn from\_mut(v: &mut i32) -> &mut AtomicI32
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut i32`.
**Note:** This function is only available on targets where `i32` has an alignment of 4 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI32, Ordering};
let mut some_int = 123;
let a = AtomicI32::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn get\_mut\_slice(this: &mut [AtomicI32]) -> &mut [i32]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicI32]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicI32, Ordering};
let mut some_ints = [const { AtomicI32::new(0) }; 10];
let view: &mut [i32] = AtomicI32::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn from\_mut\_slice(v: &mut [i32]) -> &mut [AtomicI32]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [i32]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI32, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicI32::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> i32
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicI32;
let some_var = AtomicI32::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn load(&self, order: Ordering) -> i32
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let some_var = AtomicI32::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn store(&self, val: i32, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let some_var = AtomicI32::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn swap(&self, val: i32, order: Ordering) -> i32
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let some_var = AtomicI32::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn compare\_and\_swap(&self, current: i32, new: i32, order: Ordering) -> i32
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let some_var = AtomicI32::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn compare\_exchange( &self, current: i32, new: i32, success: Ordering, failure: Ordering) -> Result<i32, i32>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let some_var = AtomicI32::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn compare\_exchange\_weak( &self, current: i32, new: i32, success: Ordering, failure: Ordering) -> Result<i32, i32>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicI32::compare_exchange`](struct.atomici32#method.compare_exchange "AtomicI32::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let val = AtomicI32::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn fetch\_add(&self, val: i32, order: Ordering) -> i32
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn fetch\_sub(&self, val: i32, order: Ordering) -> i32
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn fetch\_and(&self, val: i32, order: Ordering) -> i32
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn fetch\_nand(&self, val: i32, order: Ordering) -> i32
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn fetch\_or(&self, val: i32, order: Ordering) -> i32
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn fetch\_xor(&self, val: i32, order: Ordering) -> i32
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<i32, i32>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([i32](../../primitive.i32)) -> [Option](../../option/enum.option "enum std::option::Option")<[i32](../../primitive.i32)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicI32::compare_exchange`](struct.atomici32#method.compare_exchange "AtomicI32::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let x = AtomicI32::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)1.45.0 · #### pub fn fetch\_max(&self, val: i32, order: Ordering) -> i32
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)1.45.0 · #### pub fn fetch\_min(&self, val: i32, order: Ordering) -> i32
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i32`](../../primitive.i32 "i32").
##### Examples
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI32, Ordering};
let foo = AtomicI32::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### pub fn as\_mut\_ptr(&self) -> \*mut i32
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut i32` instead of `&AtomicI32`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicI32;
extern "C" {
fn my_atomic_op(arg: *mut i32);
}
let mut atomic = AtomicI32::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)### impl Debug for AtomicI32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicI32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicI32
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<i32> for AtomicI32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: i32) -> AtomicI32
Converts an `i32` into an `AtomicI32`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#215)### impl RefUnwindSafe for AtomicI32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)### impl Sync for AtomicI32
Auto Trait Implementations
--------------------------
### impl Send for AtomicI32
### impl Unpin for AtomicI32
### impl UnwindSafe for AtomicI32
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::atomic::AtomicPtr Struct std::sync::atomic::AtomicPtr
===================================
```
#[repr(C, align(8))]pub struct AtomicPtr<T> { /* private fields */ }
```
A raw pointer type which can be safely shared between threads.
This type has the same in-memory representation as a `*mut T`.
**Note**: This type is only available on platforms that support atomic loads and stores of pointers. Its size depends on the target pointer’s size.
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#994)### impl<T> AtomicPtr<T>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1008)const: 1.24.0 · #### pub const fn new(p: \*mut T) -> AtomicPtr<T>
Creates a new `AtomicPtr`.
##### Examples
```
use std::sync::atomic::AtomicPtr;
let ptr = &mut 5;
let atomic_ptr = AtomicPtr::new(ptr);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1030)1.15.0 · #### pub fn get\_mut(&mut self) -> &mut \*mut T
Returns a mutable reference to the underlying pointer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let mut data = 10;
let mut atomic_ptr = AtomicPtr::new(&mut data);
let mut other_data = 5;
*atomic_ptr.get_mut() = &mut other_data;
assert_eq!(unsafe { *atomic_ptr.load(Ordering::SeqCst) }, 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1052)#### pub fn from\_mut(v: &mut \*mut T) -> &mut AtomicPtr<T>
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a pointer.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicPtr, Ordering};
let mut data = 123;
let mut some_ptr = &mut data as *mut i32;
let a = AtomicPtr::from_mut(&mut some_ptr);
let mut other_data = 456;
a.store(&mut other_data, Ordering::Relaxed);
assert_eq!(unsafe { *some_ptr }, 456);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1097)#### pub fn get\_mut\_slice(this: &mut [AtomicPtr<T>]) -> &mut [\*mut T]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicPtr]` slice.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::ptr::null_mut;
use std::sync::atomic::{AtomicPtr, Ordering};
let mut some_ptrs = [const { AtomicPtr::new(null_mut::<String>()) }; 10];
let view: &mut [*mut String] = AtomicPtr::get_mut_slice(&mut some_ptrs);
assert_eq!(view, [null_mut::<String>(); 10]);
view
.iter_mut()
.enumerate()
.for_each(|(i, ptr)| *ptr = Box::into_raw(Box::new(format!("iteration#{i}"))));
std::thread::scope(|s| {
for ptr in &some_ptrs {
s.spawn(move || {
let ptr = ptr.load(Ordering::Relaxed);
assert!(!ptr.is_null());
let name = unsafe { Box::from_raw(ptr) };
println!("Hello, {name}!");
});
}
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1130)#### pub fn from\_mut\_slice(v: &mut [\*mut T]) -> &mut [AtomicPtr<T>]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a slice of pointers.
##### Examples
```
#![feature(atomic_from_mut)]
use std::ptr::null_mut;
use std::sync::atomic::{AtomicPtr, Ordering};
let mut some_ptrs = [null_mut::<String>(); 10];
let a = &*AtomicPtr::from_mut_slice(&mut some_ptrs);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || {
let name = Box::new(format!("thread{i}"));
a[i].store(Box::into_raw(name), Ordering::Relaxed);
});
}
});
for p in some_ptrs {
assert!(!p.is_null());
let name = unsafe { Box::from_raw(p) };
println!("Hello, {name}!");
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1155)1.15.0 (const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner")) · #### pub fn into\_inner(self) -> \*mut T
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicPtr;
let mut data = 5;
let atomic_ptr = AtomicPtr::new(&mut data);
assert_eq!(unsafe { *atomic_ptr.into_inner() }, 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1181)#### pub fn load(&self, order: Ordering) -> \*mut T
Loads a value from the pointer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let ptr = &mut 5;
let some_ptr = AtomicPtr::new(ptr);
let value = some_ptr.load(Ordering::Relaxed);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1210)#### pub fn store(&self, ptr: \*mut T, order: Ordering)
Stores a value into the pointer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let ptr = &mut 5;
let some_ptr = AtomicPtr::new(ptr);
let other_ptr = &mut 10;
some_ptr.store(other_ptr, Ordering::Relaxed);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1243)#### pub fn swap(&self, ptr: \*mut T, order: Ordering) -> \*mut T
Stores a value into the pointer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on pointers.
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let ptr = &mut 5;
let some_ptr = AtomicPtr::new(ptr);
let other_ptr = &mut 10;
let value = some_ptr.swap(other_ptr, Ordering::Relaxed);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1299)#### pub fn compare\_and\_swap( &self, current: \*mut T, new: \*mut T, order: Ordering) -> \*mut T
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the pointer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on pointers.
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let ptr = &mut 5;
let some_ptr = AtomicPtr::new(ptr);
let other_ptr = &mut 10;
let value = some_ptr.compare_and_swap(ptr, other_ptr, Ordering::Relaxed);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1339-1345)1.10.0 · #### pub fn compare\_exchange( &self, current: \*mut T, new: \*mut T, success: Ordering, failure: Ordering) -> Result<\*mut T, \*mut T>
Stores a value into the pointer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on pointers.
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let ptr = &mut 5;
let some_ptr = AtomicPtr::new(ptr);
let other_ptr = &mut 10;
let value = some_ptr.compare_exchange(ptr, other_ptr,
Ordering::SeqCst, Ordering::Relaxed);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1388-1394)1.10.0 · #### pub fn compare\_exchange\_weak( &self, current: \*mut T, new: \*mut T, success: Ordering, failure: Ordering) -> Result<\*mut T, \*mut T>
Stores a value into the pointer if the current value is the same as the `current` value.
Unlike [`AtomicPtr::compare_exchange`](struct.atomicptr#method.compare_exchange "AtomicPtr::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on pointers.
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let some_ptr = AtomicPtr::new(&mut 5);
let new = &mut 10;
let mut old = some_ptr.load(Ordering::Relaxed);
loop {
match some_ptr.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1449-1456)1.53.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<\*mut T, \*mut T>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([\*mut T](../../primitive.pointer)) -> [Option](../../option/enum.option "enum std::option::Option")<[\*mut T](../../primitive.pointer)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicPtr::compare_exchange`](struct.atomicptr#method.compare_exchange "AtomicPtr::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on pointers.
##### Examples
```
use std::sync::atomic::{AtomicPtr, Ordering};
let ptr: *mut _ = &mut 5;
let some_ptr = AtomicPtr::new(ptr);
let new: *mut _ = &mut 10;
assert_eq!(some_ptr.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(ptr));
let result = some_ptr.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| {
if x == ptr {
Some(new)
} else {
None
}
});
assert_eq!(result, Ok(ptr));
assert_eq!(some_ptr.load(Ordering::SeqCst), new);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1505)#### pub fn fetch\_ptr\_add(&self, val: usize, order: Ordering) -> \*mut T
🔬This is a nightly-only experimental API. (`strict_provenance_atomic_ptr` [#99108](https://github.com/rust-lang/rust/issues/99108))
Offsets the pointer’s address by adding `val` (in units of `T`), returning the previous pointer.
This is equivalent to using [`wrapping_add`](../../primitive.pointer#method.wrapping_add) to atomically perform the equivalent of `ptr = ptr.wrapping_add(val);`.
This method operates in units of `T`, which means that it cannot be used to offset the pointer by an amount which is not a multiple of `size_of::<T>()`. This can sometimes be inconvenient, as you may want to work with a deliberately misaligned pointer. In such cases, you may use the [`fetch_byte_add`](struct.atomicptr#method.fetch_byte_add) method instead.
`fetch_ptr_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`AtomicPtr`](struct.atomicptr "AtomicPtr").
##### Examples
```
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
use core::sync::atomic::{AtomicPtr, Ordering};
let atom = AtomicPtr::<i64>::new(core::ptr::null_mut());
assert_eq!(atom.fetch_ptr_add(1, Ordering::Relaxed).addr(), 0);
// Note: units of `size_of::<i64>()`.
assert_eq!(atom.load(Ordering::Relaxed).addr(), 8);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1550)#### pub fn fetch\_ptr\_sub(&self, val: usize, order: Ordering) -> \*mut T
🔬This is a nightly-only experimental API. (`strict_provenance_atomic_ptr` [#99108](https://github.com/rust-lang/rust/issues/99108))
Offsets the pointer’s address by subtracting `val` (in units of `T`), returning the previous pointer.
This is equivalent to using [`wrapping_sub`](../../primitive.pointer#method.wrapping_sub) to atomically perform the equivalent of `ptr = ptr.wrapping_sub(val);`.
This method operates in units of `T`, which means that it cannot be used to offset the pointer by an amount which is not a multiple of `size_of::<T>()`. This can sometimes be inconvenient, as you may want to work with a deliberately misaligned pointer. In such cases, you may use the [`fetch_byte_sub`](struct.atomicptr#method.fetch_byte_sub) method instead.
`fetch_ptr_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`AtomicPtr`](struct.atomicptr "AtomicPtr").
##### Examples
```
#![feature(strict_provenance_atomic_ptr)]
use core::sync::atomic::{AtomicPtr, Ordering};
let array = [1i32, 2i32];
let atom = AtomicPtr::new(array.as_ptr().wrapping_add(1) as *mut _);
assert!(core::ptr::eq(
atom.fetch_ptr_sub(1, Ordering::Relaxed),
&array[1],
));
assert!(core::ptr::eq(atom.load(Ordering::Relaxed), &array[0]));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1585)#### pub fn fetch\_byte\_add(&self, val: usize, order: Ordering) -> \*mut T
🔬This is a nightly-only experimental API. (`strict_provenance_atomic_ptr` [#99108](https://github.com/rust-lang/rust/issues/99108))
Offsets the pointer’s address by adding `val` *bytes*, returning the previous pointer.
This is equivalent to using [`wrapping_byte_add`](../../primitive.pointer#method.wrapping_byte_add) to atomically perform `ptr = ptr.wrapping_byte_add(val)`.
`fetch_byte_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`AtomicPtr`](struct.atomicptr "AtomicPtr").
##### Examples
```
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
use core::sync::atomic::{AtomicPtr, Ordering};
let atom = AtomicPtr::<i64>::new(core::ptr::null_mut());
assert_eq!(atom.fetch_byte_add(1, Ordering::Relaxed).addr(), 0);
// Note: in units of bytes, not `size_of::<i64>()`.
assert_eq!(atom.load(Ordering::Relaxed).addr(), 1);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1620)#### pub fn fetch\_byte\_sub(&self, val: usize, order: Ordering) -> \*mut T
🔬This is a nightly-only experimental API. (`strict_provenance_atomic_ptr` [#99108](https://github.com/rust-lang/rust/issues/99108))
Offsets the pointer’s address by subtracting `val` *bytes*, returning the previous pointer.
This is equivalent to using [`wrapping_byte_sub`](../../primitive.pointer#method.wrapping_byte_sub) to atomically perform `ptr = ptr.wrapping_byte_sub(val)`.
`fetch_byte_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`AtomicPtr`](struct.atomicptr "AtomicPtr").
##### Examples
```
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
use core::sync::atomic::{AtomicPtr, Ordering};
let atom = AtomicPtr::<i64>::new(core::ptr::invalid_mut(1));
assert_eq!(atom.fetch_byte_sub(1, Ordering::Relaxed).addr(), 1);
assert_eq!(atom.load(Ordering::Relaxed).addr(), 0);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1671)#### pub fn fetch\_or(&self, val: usize, order: Ordering) -> \*mut T
🔬This is a nightly-only experimental API. (`strict_provenance_atomic_ptr` [#99108](https://github.com/rust-lang/rust/issues/99108))
Performs a bitwise “or” operation on the address of the current pointer, and the argument `val`, and stores a pointer with provenance of the current pointer and the resulting address.
This is equivalent equivalent to using [`map_addr`](../../primitive.pointer#method.map_addr) to atomically perform `ptr = ptr.map_addr(|a| a | val)`. This can be used in tagged pointer schemes to atomically set tag bits.
**Caveat**: This operation returns the previous value. To compute the stored value without losing provenance, you may use [`map_addr`](../../primitive.pointer#method.map_addr). For example: `a.fetch_or(val).map_addr(|a| a | val)`.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`AtomicPtr`](struct.atomicptr "AtomicPtr").
This API and its claimed semantics are part of the Strict Provenance experiment, see the [module documentation for `ptr`](../../ptr/index "crate::ptr") for details.
##### Examples
```
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
use core::sync::atomic::{AtomicPtr, Ordering};
let pointer = &mut 3i64 as *mut i64;
let atom = AtomicPtr::<i64>::new(pointer);
// Tag the bottom bit of the pointer.
assert_eq!(atom.fetch_or(1, Ordering::Relaxed).addr() & 1, 0);
// Extract and untag.
let tagged = atom.load(Ordering::Relaxed);
assert_eq!(tagged.addr() & 1, 1);
assert_eq!(tagged.map_addr(|p| p & !1), pointer);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1721)#### pub fn fetch\_and(&self, val: usize, order: Ordering) -> \*mut T
🔬This is a nightly-only experimental API. (`strict_provenance_atomic_ptr` [#99108](https://github.com/rust-lang/rust/issues/99108))
Performs a bitwise “and” operation on the address of the current pointer, and the argument `val`, and stores a pointer with provenance of the current pointer and the resulting address.
This is equivalent equivalent to using [`map_addr`](../../primitive.pointer#method.map_addr) to atomically perform `ptr = ptr.map_addr(|a| a & val)`. This can be used in tagged pointer schemes to atomically unset tag bits.
**Caveat**: This operation returns the previous value. To compute the stored value without losing provenance, you may use [`map_addr`](../../primitive.pointer#method.map_addr). For example: `a.fetch_and(val).map_addr(|a| a & val)`.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`AtomicPtr`](struct.atomicptr "AtomicPtr").
This API and its claimed semantics are part of the Strict Provenance experiment, see the [module documentation for `ptr`](../../ptr/index "crate::ptr") for details.
##### Examples
```
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
use core::sync::atomic::{AtomicPtr, Ordering};
let pointer = &mut 3i64 as *mut i64;
// A tagged pointer
let atom = AtomicPtr::<i64>::new(pointer.map_addr(|a| a | 1));
assert_eq!(atom.fetch_or(1, Ordering::Relaxed).addr() & 1, 1);
// Untag, and extract the previously tagged pointer.
let untagged = atom.fetch_and(!1, Ordering::Relaxed)
.map_addr(|a| a & !1);
assert_eq!(untagged, pointer);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1769)#### pub fn fetch\_xor(&self, val: usize, order: Ordering) -> \*mut T
🔬This is a nightly-only experimental API. (`strict_provenance_atomic_ptr` [#99108](https://github.com/rust-lang/rust/issues/99108))
Performs a bitwise “xor” operation on the address of the current pointer, and the argument `val`, and stores a pointer with provenance of the current pointer and the resulting address.
This is equivalent equivalent to using [`map_addr`](../../primitive.pointer#method.map_addr) to atomically perform `ptr = ptr.map_addr(|a| a ^ val)`. This can be used in tagged pointer schemes to atomically toggle tag bits.
**Caveat**: This operation returns the previous value. To compute the stored value without losing provenance, you may use [`map_addr`](../../primitive.pointer#method.map_addr). For example: `a.fetch_xor(val).map_addr(|a| a ^ val)`.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`AtomicPtr`](struct.atomicptr "AtomicPtr").
This API and its claimed semantics are part of the Strict Provenance experiment, see the [module documentation for `ptr`](../../ptr/index "crate::ptr") for details.
##### Examples
```
#![feature(strict_provenance_atomic_ptr, strict_provenance)]
use core::sync::atomic::{AtomicPtr, Ordering};
let pointer = &mut 3i64 as *mut i64;
let atom = AtomicPtr::<i64>::new(pointer);
// Toggle a tag bit on the pointer.
atom.fetch_xor(1, Ordering::Relaxed);
assert_eq!(atom.load(Ordering::Relaxed).addr() & 1, 1);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#3406)1.3.0 · ### impl<T> Debug for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#3407)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#183)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl<T> Default for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#185)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicPtr<T>
Creates a null `AtomicPtr<T>`.
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1797)1.23.0 (const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert")) · ### impl<T> From<\*mut T> for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1800)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(p: \*mut T) -> AtomicPtr<T>
Converts a `*mut T` into an `AtomicPtr<T>`.
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#3414)1.24.0 · ### impl<T> Pointer for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#3415)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#248)1.14.0 · ### impl<T> RefUnwindSafe for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#192)### impl<T> Send for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#195)### impl<T> Sync for AtomicPtr<T>
Auto Trait Implementations
--------------------------
### impl<T> Unpin for AtomicPtr<T>
### impl<T> UnwindSafe for AtomicPtr<T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Constant std::sync::atomic::ATOMIC_I32_INIT Constant std::sync::atomic::ATOMIC\_I32\_INIT
=============================================
```
pub const ATOMIC_I32_INIT: AtomicI32;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Struct std::sync::atomic::AtomicU8 Struct std::sync::atomic::AtomicU8
==================================
```
#[repr(C, align(1))]pub struct AtomicU8 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`u8`](../../primitive.u8 "u8"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`u8`](../../primitive.u8 "u8").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)### impl AtomicU8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)const: 1.34.0 · #### pub const fn new(v: u8) -> AtomicU8
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicU8;
let atomic_forty_two = AtomicU8::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn get\_mut(&mut self) -> &mut u8
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let mut some_var = AtomicU8::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn from\_mut(v: &mut u8) -> &mut AtomicU8
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut u8`.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU8, Ordering};
let mut some_int = 123;
let a = AtomicU8::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn get\_mut\_slice(this: &mut [AtomicU8]) -> &mut [u8]
Notable traits for &[[u8](../../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicU8]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicU8, Ordering};
let mut some_ints = [const { AtomicU8::new(0) }; 10];
let view: &mut [u8] = AtomicU8::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn from\_mut\_slice(v: &mut [u8]) -> &mut [AtomicU8]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [u8]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU8, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicU8::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> u8
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicU8;
let some_var = AtomicU8::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn load(&self, order: Ordering) -> u8
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let some_var = AtomicU8::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn store(&self, val: u8, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let some_var = AtomicU8::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn swap(&self, val: u8, order: Ordering) -> u8
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let some_var = AtomicU8::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn compare\_and\_swap(&self, current: u8, new: u8, order: Ordering) -> u8
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let some_var = AtomicU8::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn compare\_exchange( &self, current: u8, new: u8, success: Ordering, failure: Ordering) -> Result<u8, u8>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let some_var = AtomicU8::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn compare\_exchange\_weak( &self, current: u8, new: u8, success: Ordering, failure: Ordering) -> Result<u8, u8>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicU8::compare_exchange`](struct.atomicu8#method.compare_exchange "AtomicU8::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let val = AtomicU8::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn fetch\_add(&self, val: u8, order: Ordering) -> u8
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn fetch\_sub(&self, val: u8, order: Ordering) -> u8
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn fetch\_and(&self, val: u8, order: Ordering) -> u8
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn fetch\_nand(&self, val: u8, order: Ordering) -> u8
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn fetch\_or(&self, val: u8, order: Ordering) -> u8
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn fetch\_xor(&self, val: u8, order: Ordering) -> u8
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<u8, u8>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([u8](../../primitive.u8)) -> [Option](../../option/enum.option "enum std::option::Option")<[u8](../../primitive.u8)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicU8::compare_exchange`](struct.atomicu8#method.compare_exchange "AtomicU8::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let x = AtomicU8::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)1.45.0 · #### pub fn fetch\_max(&self, val: u8, order: Ordering) -> u8
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)1.45.0 · #### pub fn fetch\_min(&self, val: u8, order: Ordering) -> u8
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u8`](../../primitive.u8 "u8").
##### Examples
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU8, Ordering};
let foo = AtomicU8::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### pub fn as\_mut\_ptr(&self) -> \*mut u8
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut u8` instead of `&AtomicU8`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicU8;
extern "C" {
fn my_atomic_op(arg: *mut u8);
}
let mut atomic = AtomicU8::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)### impl Debug for AtomicU8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicU8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicU8
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<u8> for AtomicU8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: u8) -> AtomicU8
Converts an `u8` into an `AtomicU8`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#228)### impl RefUnwindSafe for AtomicU8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)### impl Sync for AtomicU8
Auto Trait Implementations
--------------------------
### impl Send for AtomicU8
### impl Unpin for AtomicU8
### impl UnwindSafe for AtomicU8
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Constant std::sync::atomic::ATOMIC_I64_INIT Constant std::sync::atomic::ATOMIC\_I64\_INIT
=============================================
```
pub const ATOMIC_I64_INIT: AtomicI64;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Constant std::sync::atomic::ATOMIC_ISIZE_INIT Constant std::sync::atomic::ATOMIC\_ISIZE\_INIT
===============================================
```
pub const ATOMIC_ISIZE_INIT: AtomicIsize;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
An atomic integer initialized to `0`.
rust Function std::sync::atomic::spin_loop_hint Function std::sync::atomic::spin\_loop\_hint
============================================
```
pub fn spin_loop_hint()
```
👎Deprecated since 1.51.0: use hint::spin\_loop instead
Signals the processor that it is inside a busy-wait spin-loop (“spin lock”).
This function is deprecated in favor of [`hint::spin_loop`](../../hint/fn.spin_loop).
rust Enum std::sync::atomic::Ordering Enum std::sync::atomic::Ordering
================================
```
#[non_exhaustive]
pub enum Ordering {
Relaxed,
Release,
Acquire,
AcqRel,
SeqCst,
}
```
Atomic memory orderings
Memory orderings specify the way atomic operations synchronize memory. In its weakest [`Ordering::Relaxed`](enum.ordering#variant.Relaxed "Ordering::Relaxed"), only the memory directly touched by the operation is synchronized. On the other hand, a store-load pair of [`Ordering::SeqCst`](enum.ordering#variant.SeqCst "Ordering::SeqCst") operations synchronize other memory while additionally preserving a total order of such operations across all threads.
Rust’s memory orderings are [the same as those of C++20](https://en.cppreference.com/w/cpp/atomic/memory_order).
For more information see the [nomicon](https://doc.rust-lang.org/nomicon/atomics.html).
Variants (Non-exhaustive)
-------------------------
This enum is marked as non-exhaustiveNon-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.### `Relaxed`
No ordering constraints, only atomic operations.
Corresponds to [`memory_order_relaxed`](https://en.cppreference.com/w/cpp/atomic/memory_order#Relaxed_ordering) in C++20.
### `Release`
When coupled with a store, all previous operations become ordered before any load of this value with [`Acquire`](enum.ordering#variant.Acquire "Acquire") (or stronger) ordering. In particular, all previous writes become visible to all threads that perform an [`Acquire`](enum.ordering#variant.Acquire "Acquire") (or stronger) load of this value.
Notice that using this ordering for an operation that combines loads and stores leads to a [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") load operation!
This ordering is only applicable for operations that can perform a store.
Corresponds to [`memory_order_release`](https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering) in C++20.
### `Acquire`
When coupled with a load, if the loaded value was written by a store operation with [`Release`](enum.ordering#variant.Release "Release") (or stronger) ordering, then all subsequent operations become ordered after that store. In particular, all subsequent loads will see data written before the store.
Notice that using this ordering for an operation that combines loads and stores leads to a [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") store operation!
This ordering is only applicable for operations that can perform a load.
Corresponds to [`memory_order_acquire`](https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering) in C++20.
### `AcqRel`
Has the effects of both [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Release`](enum.ordering#variant.Release "Release") together: For loads it uses [`Acquire`](enum.ordering#variant.Acquire "Acquire") ordering. For stores it uses the [`Release`](enum.ordering#variant.Release "Release") ordering.
Notice that in the case of `compare_and_swap`, it is possible that the operation ends up not performing any store and hence it has just [`Acquire`](enum.ordering#variant.Acquire "Acquire") ordering. However, `AcqRel` will never perform [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") accesses.
This ordering is only applicable for operations that combine both loads and stores.
Corresponds to [`memory_order_acq_rel`](https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering) in C++20.
### `SeqCst`
Like [`Acquire`](enum.ordering#variant.Acquire "Acquire")/[`Release`](enum.ordering#variant.Release "Release")/[`AcqRel`](enum.ordering#variant.AcqRel "AcqRel") (for load, store, and load-with-store operations, respectively) with the additional guarantee that all threads see all sequentially consistent operations in the same order.
Corresponds to [`memory_order_seq_cst`](https://en.cppreference.com/w/cpp/atomic/memory_order#Sequentially-consistent_ordering) in C++20.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl Clone for Ordering
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)#### fn clone(&self) -> Ordering
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl Debug for Ordering
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl Hash for Ordering
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)#### fn hash<\_\_H>(&self, state: &mut \_\_H)where \_\_H: [Hasher](../../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../../hash/trait.hasher "Hasher"). [Read more](../../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../../hash/trait.hasher "Hasher"). [Read more](../../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl PartialEq<Ordering> for Ordering
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)#### fn eq(&self, other: &Ordering) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl Copy for Ordering
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl Eq for Ordering
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl StructuralEq for Ordering
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl StructuralPartialEq for Ordering
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for Ordering
### impl Send for Ordering
### impl Sync for Ordering
### impl Unpin for Ordering
### impl UnwindSafe for Ordering
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::atomic::AtomicBool Struct std::sync::atomic::AtomicBool
====================================
```
#[repr(C, align(1))]pub struct AtomicBool { /* private fields */ }
```
A boolean type which can be safely shared between threads.
This type has the same in-memory representation as a [`bool`](../../primitive.bool "bool").
**Note**: This type is only available on platforms that support atomic loads and stores of `u8`.
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#289)### impl AtomicBool
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#304)const: 1.24.0 · #### pub const fn new(v: bool) -> AtomicBool
Creates a new `AtomicBool`.
##### Examples
```
use std::sync::atomic::AtomicBool;
let atomic_true = AtomicBool::new(true);
let atomic_false = AtomicBool::new(false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#325)1.15.0 · #### pub fn get\_mut(&mut self) -> &mut bool
Returns a mutable reference to the underlying [`bool`](../../primitive.bool "bool").
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let mut some_bool = AtomicBool::new(true);
assert_eq!(*some_bool.get_mut(), true);
*some_bool.get_mut() = false;
assert_eq!(some_bool.load(Ordering::SeqCst), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#346)#### pub fn from\_mut(v: &mut bool) -> &mut AtomicBool
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut bool`.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicBool, Ordering};
let mut some_bool = true;
let a = AtomicBool::from_mut(&mut some_bool);
a.store(false, Ordering::Relaxed);
assert_eq!(some_bool, false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#381)#### pub fn get\_mut\_slice(this: &mut [AtomicBool]) -> &mut [bool]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicBool]` slice.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicBool, Ordering};
let mut some_bools = [const { AtomicBool::new(false) }; 10];
let view: &mut [bool] = AtomicBool::get_mut_slice(&mut some_bools);
assert_eq!(view, [false; 10]);
view[..5].copy_from_slice(&[true; 5]);
std::thread::scope(|s| {
for t in &some_bools[..5] {
s.spawn(move || assert_eq!(t.load(Ordering::Relaxed), true));
}
for f in &some_bools[5..] {
s.spawn(move || assert_eq!(f.load(Ordering::Relaxed), false));
}
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#406)#### pub fn from\_mut\_slice(v: &mut [bool]) -> &mut [AtomicBool]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [bool]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicBool, Ordering};
let mut some_bools = [false; 10];
let a = &*AtomicBool::from_mut_slice(&mut some_bools);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(true, Ordering::Relaxed));
}
});
assert_eq!(some_bools, [true; 10]);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#428)1.15.0 (const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner")) · #### pub fn into\_inner(self) -> bool
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicBool;
let some_bool = AtomicBool::new(true);
assert_eq!(some_bool.into_inner(), true);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#453)#### pub fn load(&self, order: Ordering) -> bool
Loads a value from the bool.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let some_bool = AtomicBool::new(true);
assert_eq!(some_bool.load(Ordering::Relaxed), true);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#481)#### pub fn store(&self, val: bool, order: Ordering)
Stores a value into the bool.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let some_bool = AtomicBool::new(true);
some_bool.store(false, Ordering::Relaxed);
assert_eq!(some_bool.load(Ordering::Relaxed), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#513)#### pub fn swap(&self, val: bool, order: Ordering) -> bool
Stores a value into the bool, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let some_bool = AtomicBool::new(true);
assert_eq!(some_bool.swap(false, Ordering::Relaxed), true);
assert_eq!(some_bool.load(Ordering::Relaxed), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#570)#### pub fn compare\_and\_swap(&self, current: bool, new: bool, order: Ordering) -> bool
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the [`bool`](../../primitive.bool "bool") if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let some_bool = AtomicBool::new(true);
assert_eq!(some_bool.compare_and_swap(true, false, Ordering::Relaxed), true);
assert_eq!(some_bool.load(Ordering::Relaxed), false);
assert_eq!(some_bool.compare_and_swap(true, true, Ordering::Relaxed), false);
assert_eq!(some_bool.load(Ordering::Relaxed), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#618-624)1.10.0 · #### pub fn compare\_exchange( &self, current: bool, new: bool, success: Ordering, failure: Ordering) -> Result<bool, bool>
Stores a value into the [`bool`](../../primitive.bool "bool") if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let some_bool = AtomicBool::new(true);
assert_eq!(some_bool.compare_exchange(true,
false,
Ordering::Acquire,
Ordering::Relaxed),
Ok(true));
assert_eq!(some_bool.load(Ordering::Relaxed), false);
assert_eq!(some_bool.compare_exchange(true, true,
Ordering::SeqCst,
Ordering::Acquire),
Err(false));
assert_eq!(some_bool.load(Ordering::Relaxed), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#673-679)1.10.0 · #### pub fn compare\_exchange\_weak( &self, current: bool, new: bool, success: Ordering, failure: Ordering) -> Result<bool, bool>
Stores a value into the [`bool`](../../primitive.bool "bool") if the current value is the same as the `current` value.
Unlike [`AtomicBool::compare_exchange`](struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let val = AtomicBool::new(false);
let new = true;
let mut old = val.load(Ordering::Relaxed);
loop {
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#725)#### pub fn fetch\_and(&self, val: bool, order: Ordering) -> bool
Logical “and” with a boolean value.
Performs a logical “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_and(false, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), false);
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_and(true, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), true);
let foo = AtomicBool::new(false);
assert_eq!(foo.fetch_and(false, Ordering::SeqCst), false);
assert_eq!(foo.load(Ordering::SeqCst), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#767)#### pub fn fetch\_nand(&self, val: bool, order: Ordering) -> bool
Logical “nand” with a boolean value.
Performs a logical “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_nand(false, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), true);
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_nand(true, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst) as usize, 0);
assert_eq!(foo.load(Ordering::SeqCst), false);
let foo = AtomicBool::new(false);
assert_eq!(foo.fetch_nand(false, Ordering::SeqCst), false);
assert_eq!(foo.load(Ordering::SeqCst), true);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#819)#### pub fn fetch\_or(&self, val: bool, order: Ordering) -> bool
Logical “or” with a boolean value.
Performs a logical “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_or(false, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), true);
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_or(true, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), true);
let foo = AtomicBool::new(false);
assert_eq!(foo.fetch_or(false, Ordering::SeqCst), false);
assert_eq!(foo.load(Ordering::SeqCst), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#860)#### pub fn fetch\_xor(&self, val: bool, order: Ordering) -> bool
Logical “xor” with a boolean value.
Performs a logical “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_xor(false, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), true);
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_xor(true, Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), false);
let foo = AtomicBool::new(false);
assert_eq!(foo.fetch_xor(false, Ordering::SeqCst), false);
assert_eq!(foo.load(Ordering::SeqCst), false);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#898)#### pub fn fetch\_not(&self, order: Ordering) -> bool
🔬This is a nightly-only experimental API. (`atomic_bool_fetch_not` [#98485](https://github.com/rust-lang/rust/issues/98485))
Logical “not” with a boolean value.
Performs a logical “not” operation on the current value, and sets the new value to the result.
Returns the previous value.
`fetch_not` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
#![feature(atomic_bool_fetch_not)]
use std::sync::atomic::{AtomicBool, Ordering};
let foo = AtomicBool::new(true);
assert_eq!(foo.fetch_not(Ordering::SeqCst), true);
assert_eq!(foo.load(Ordering::SeqCst), false);
let foo = AtomicBool::new(false);
assert_eq!(foo.fetch_not(Ordering::SeqCst), false);
assert_eq!(foo.load(Ordering::SeqCst), true);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#931)#### pub fn as\_mut\_ptr(&self) -> \*mut bool
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying [`bool`](../../primitive.bool "bool").
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut bool` instead of `&AtomicBool`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicBool;
extern "C" {
fn my_atomic_op(arg: *mut bool);
}
let mut atomic = AtomicBool::new(true);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#973-980)1.53.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<bool, bool>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([bool](../../primitive.bool)) -> [Option](../../option/enum.option "enum std::option::Option")<[bool](../../primitive.bool)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicBool::compare_exchange`](struct.atomicbool#method.compare_exchange "AtomicBool::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note:** This method is only available on platforms that support atomic operations on `u8`.
##### Examples
```
use std::sync::atomic::{AtomicBool, Ordering};
let x = AtomicBool::new(false);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(false));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(!x)), Ok(false));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(!x)), Ok(true));
assert_eq!(x.load(Ordering::SeqCst), false);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#3398)1.3.0 · ### impl Debug for AtomicBool
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#3399)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#151)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicBool
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#154)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicBool
Creates an `AtomicBool` initialized to `false`.
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1778)1.24.0 (const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert")) · ### impl From<bool> for AtomicBool
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#1789)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(b: bool) -> AtomicBool
Converts a `bool` into an `AtomicBool`.
##### Examples
```
use std::sync::atomic::AtomicBool;
let atomic_bool = AtomicBool::from(true);
assert_eq!(format!("{atomic_bool:?}"), "true")
```
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#244)1.14.0 · ### impl RefUnwindSafe for AtomicBool
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#162)### impl Sync for AtomicBool
Auto Trait Implementations
--------------------------
### impl Send for AtomicBool
### impl Unpin for AtomicBool
### impl UnwindSafe for AtomicBool
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::atomic::AtomicI64 Struct std::sync::atomic::AtomicI64
===================================
```
#[repr(C, align(8))]pub struct AtomicI64 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`i64`](../../primitive.i64 "i64"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`i64`](../../primitive.i64 "i64").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)### impl AtomicI64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)const: 1.34.0 · #### pub const fn new(v: i64) -> AtomicI64
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicI64;
let atomic_forty_two = AtomicI64::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn get\_mut(&mut self) -> &mut i64
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let mut some_var = AtomicI64::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn from\_mut(v: &mut i64) -> &mut AtomicI64
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut i64`.
**Note:** This function is only available on targets where `i64` has an alignment of 8 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI64, Ordering};
let mut some_int = 123;
let a = AtomicI64::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn get\_mut\_slice(this: &mut [AtomicI64]) -> &mut [i64]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicI64]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicI64, Ordering};
let mut some_ints = [const { AtomicI64::new(0) }; 10];
let view: &mut [i64] = AtomicI64::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn from\_mut\_slice(v: &mut [i64]) -> &mut [AtomicI64]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [i64]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI64, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicI64::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> i64
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicI64;
let some_var = AtomicI64::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn load(&self, order: Ordering) -> i64
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let some_var = AtomicI64::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn store(&self, val: i64, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let some_var = AtomicI64::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn swap(&self, val: i64, order: Ordering) -> i64
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let some_var = AtomicI64::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn compare\_and\_swap(&self, current: i64, new: i64, order: Ordering) -> i64
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let some_var = AtomicI64::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn compare\_exchange( &self, current: i64, new: i64, success: Ordering, failure: Ordering) -> Result<i64, i64>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let some_var = AtomicI64::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn compare\_exchange\_weak( &self, current: i64, new: i64, success: Ordering, failure: Ordering) -> Result<i64, i64>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicI64::compare_exchange`](struct.atomici64#method.compare_exchange "AtomicI64::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let val = AtomicI64::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn fetch\_add(&self, val: i64, order: Ordering) -> i64
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn fetch\_sub(&self, val: i64, order: Ordering) -> i64
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn fetch\_and(&self, val: i64, order: Ordering) -> i64
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn fetch\_nand(&self, val: i64, order: Ordering) -> i64
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn fetch\_or(&self, val: i64, order: Ordering) -> i64
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn fetch\_xor(&self, val: i64, order: Ordering) -> i64
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<i64, i64>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([i64](../../primitive.i64)) -> [Option](../../option/enum.option "enum std::option::Option")<[i64](../../primitive.i64)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicI64::compare_exchange`](struct.atomici64#method.compare_exchange "AtomicI64::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let x = AtomicI64::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)1.45.0 · #### pub fn fetch\_max(&self, val: i64, order: Ordering) -> i64
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)1.45.0 · #### pub fn fetch\_min(&self, val: i64, order: Ordering) -> i64
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i64`](../../primitive.i64 "i64").
##### Examples
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI64, Ordering};
let foo = AtomicI64::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### pub fn as\_mut\_ptr(&self) -> \*mut i64
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut i64` instead of `&AtomicI64`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicI64;
extern "C" {
fn my_atomic_op(arg: *mut i64);
}
let mut atomic = AtomicI64::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)### impl Debug for AtomicI64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicI64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicI64
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<i64> for AtomicI64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: i64) -> AtomicI64
Converts an `i64` into an `AtomicI64`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#218)### impl RefUnwindSafe for AtomicI64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)### impl Sync for AtomicI64
Auto Trait Implementations
--------------------------
### impl Send for AtomicI64
### impl Unpin for AtomicI64
### impl UnwindSafe for AtomicI64
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Constant std::sync::atomic::ATOMIC_USIZE_INIT Constant std::sync::atomic::ATOMIC\_USIZE\_INIT
===============================================
```
pub const ATOMIC_USIZE_INIT: AtomicUsize;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
An atomic integer initialized to `0`.
rust Struct std::sync::atomic::AtomicIsize Struct std::sync::atomic::AtomicIsize
=====================================
```
#[repr(C, align(8))]pub struct AtomicIsize { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`isize`](../../primitive.isize "isize"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`isize`](../../primitive.isize "isize").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)### impl AtomicIsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: 1.24.0 · #### pub const fn new(v: isize) -> AtomicIsize
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicIsize;
let atomic_forty_two = AtomicIsize::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.15.0 · #### pub fn get\_mut(&mut self) -> &mut isize
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let mut some_var = AtomicIsize::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn from\_mut(v: &mut isize) -> &mut AtomicIsize
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut isize`.
**Note:** This function is only available on targets where `isize` has an alignment of 8 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicIsize, Ordering};
let mut some_int = 123;
let a = AtomicIsize::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn get\_mut\_slice(this: &mut [AtomicIsize]) -> &mut [isize]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicIsize]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicIsize, Ordering};
let mut some_ints = [const { AtomicIsize::new(0) }; 10];
let view: &mut [isize] = AtomicIsize::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn from\_mut\_slice(v: &mut [isize]) -> &mut [AtomicIsize]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [isize]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicIsize, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicIsize::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.15.0 (const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner")) · #### pub fn into\_inner(self) -> isize
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicIsize;
let some_var = AtomicIsize::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn load(&self, order: Ordering) -> isize
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let some_var = AtomicIsize::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn store(&self, val: isize, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let some_var = AtomicIsize::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn swap(&self, val: isize, order: Ordering) -> isize
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let some_var = AtomicIsize::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn compare\_and\_swap( &self, current: isize, new: isize, order: Ordering) -> isize
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let some_var = AtomicIsize::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.10.0 · #### pub fn compare\_exchange( &self, current: isize, new: isize, success: Ordering, failure: Ordering) -> Result<isize, isize>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let some_var = AtomicIsize::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.10.0 · #### pub fn compare\_exchange\_weak( &self, current: isize, new: isize, success: Ordering, failure: Ordering) -> Result<isize, isize>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicIsize::compare_exchange`](struct.atomicisize#method.compare_exchange "AtomicIsize::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let val = AtomicIsize::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_add(&self, val: isize, order: Ordering) -> isize
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_sub(&self, val: isize, order: Ordering) -> isize
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_and(&self, val: isize, order: Ordering) -> isize
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.27.0 · #### pub fn fetch\_nand(&self, val: isize, order: Ordering) -> isize
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_or(&self, val: isize, order: Ordering) -> isize
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn fetch\_xor(&self, val: isize, order: Ordering) -> isize
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<isize, isize>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([isize](../../primitive.isize)) -> [Option](../../option/enum.option "enum std::option::Option")<[isize](../../primitive.isize)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicIsize::compare_exchange`](struct.atomicisize#method.compare_exchange "AtomicIsize::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let x = AtomicIsize::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.45.0 · #### pub fn fetch\_max(&self, val: isize, order: Ordering) -> isize
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.45.0 · #### pub fn fetch\_min(&self, val: isize, order: Ordering) -> isize
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`isize`](../../primitive.isize "isize").
##### Examples
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicIsize, Ordering};
let foo = AtomicIsize::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### pub fn as\_mut\_ptr(&self) -> \*mut isize
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut isize` instead of `&AtomicIsize`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicIsize;
extern "C" {
fn my_atomic_op(arg: *mut isize);
}
let mut atomic = AtomicIsize::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.3.0 · ### impl Debug for AtomicIsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicIsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicIsize
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)1.23.0 (const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num")) · ### impl From<isize> for AtomicIsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: isize) -> AtomicIsize
Converts an `isize` into an `AtomicIsize`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#206)1.14.0 · ### impl RefUnwindSafe for AtomicIsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)### impl Sync for AtomicIsize
Auto Trait Implementations
--------------------------
### impl Send for AtomicIsize
### impl Unpin for AtomicIsize
### impl UnwindSafe for AtomicIsize
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::atomic::AtomicU64 Struct std::sync::atomic::AtomicU64
===================================
```
#[repr(C, align(8))]pub struct AtomicU64 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`u64`](../../primitive.u64 "u64"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`u64`](../../primitive.u64 "u64").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)### impl AtomicU64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)const: 1.34.0 · #### pub const fn new(v: u64) -> AtomicU64
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicU64;
let atomic_forty_two = AtomicU64::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn get\_mut(&mut self) -> &mut u64
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let mut some_var = AtomicU64::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn from\_mut(v: &mut u64) -> &mut AtomicU64
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut u64`.
**Note:** This function is only available on targets where `u64` has an alignment of 8 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU64, Ordering};
let mut some_int = 123;
let a = AtomicU64::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn get\_mut\_slice(this: &mut [AtomicU64]) -> &mut [u64]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicU64]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicU64, Ordering};
let mut some_ints = [const { AtomicU64::new(0) }; 10];
let view: &mut [u64] = AtomicU64::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn from\_mut\_slice(v: &mut [u64]) -> &mut [AtomicU64]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [u64]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU64, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicU64::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> u64
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicU64;
let some_var = AtomicU64::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn load(&self, order: Ordering) -> u64
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let some_var = AtomicU64::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn store(&self, val: u64, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let some_var = AtomicU64::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn swap(&self, val: u64, order: Ordering) -> u64
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let some_var = AtomicU64::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn compare\_and\_swap(&self, current: u64, new: u64, order: Ordering) -> u64
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let some_var = AtomicU64::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn compare\_exchange( &self, current: u64, new: u64, success: Ordering, failure: Ordering) -> Result<u64, u64>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let some_var = AtomicU64::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn compare\_exchange\_weak( &self, current: u64, new: u64, success: Ordering, failure: Ordering) -> Result<u64, u64>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicU64::compare_exchange`](struct.atomicu64#method.compare_exchange "AtomicU64::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let val = AtomicU64::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn fetch\_add(&self, val: u64, order: Ordering) -> u64
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn fetch\_sub(&self, val: u64, order: Ordering) -> u64
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn fetch\_and(&self, val: u64, order: Ordering) -> u64
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn fetch\_nand(&self, val: u64, order: Ordering) -> u64
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn fetch\_or(&self, val: u64, order: Ordering) -> u64
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn fetch\_xor(&self, val: u64, order: Ordering) -> u64
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<u64, u64>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([u64](../../primitive.u64)) -> [Option](../../option/enum.option "enum std::option::Option")<[u64](../../primitive.u64)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicU64::compare_exchange`](struct.atomicu64#method.compare_exchange "AtomicU64::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let x = AtomicU64::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)1.45.0 · #### pub fn fetch\_max(&self, val: u64, order: Ordering) -> u64
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)1.45.0 · #### pub fn fetch\_min(&self, val: u64, order: Ordering) -> u64
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u64`](../../primitive.u64 "u64").
##### Examples
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU64, Ordering};
let foo = AtomicU64::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### pub fn as\_mut\_ptr(&self) -> \*mut u64
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut u64` instead of `&AtomicU64`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicU64;
extern "C" {
fn my_atomic_op(arg: *mut u64);
}
let mut atomic = AtomicU64::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)### impl Debug for AtomicU64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicU64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicU64
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<u64> for AtomicU64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: u64) -> AtomicU64
Converts an `u64` into an `AtomicU64`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#237)### impl RefUnwindSafe for AtomicU64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)### impl Sync for AtomicU64
Auto Trait Implementations
--------------------------
### impl Send for AtomicU64
### impl Unpin for AtomicU64
### impl UnwindSafe for AtomicU64
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::atomic::AtomicI8 Struct std::sync::atomic::AtomicI8
==================================
```
#[repr(C, align(1))]pub struct AtomicI8 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`i8`](../../primitive.i8 "i8"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`i8`](../../primitive.i8 "i8").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)### impl AtomicI8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)const: 1.34.0 · #### pub const fn new(v: i8) -> AtomicI8
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicI8;
let atomic_forty_two = AtomicI8::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn get\_mut(&mut self) -> &mut i8
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let mut some_var = AtomicI8::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn from\_mut(v: &mut i8) -> &mut AtomicI8
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut i8`.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI8, Ordering};
let mut some_int = 123;
let a = AtomicI8::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn get\_mut\_slice(this: &mut [AtomicI8]) -> &mut [i8]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicI8]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicI8, Ordering};
let mut some_ints = [const { AtomicI8::new(0) }; 10];
let view: &mut [i8] = AtomicI8::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn from\_mut\_slice(v: &mut [i8]) -> &mut [AtomicI8]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [i8]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicI8, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicI8::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> i8
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicI8;
let some_var = AtomicI8::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn load(&self, order: Ordering) -> i8
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let some_var = AtomicI8::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn store(&self, val: i8, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let some_var = AtomicI8::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn swap(&self, val: i8, order: Ordering) -> i8
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let some_var = AtomicI8::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn compare\_and\_swap(&self, current: i8, new: i8, order: Ordering) -> i8
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let some_var = AtomicI8::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn compare\_exchange( &self, current: i8, new: i8, success: Ordering, failure: Ordering) -> Result<i8, i8>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let some_var = AtomicI8::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn compare\_exchange\_weak( &self, current: i8, new: i8, success: Ordering, failure: Ordering) -> Result<i8, i8>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicI8::compare_exchange`](struct.atomici8#method.compare_exchange "AtomicI8::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let val = AtomicI8::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn fetch\_add(&self, val: i8, order: Ordering) -> i8
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn fetch\_sub(&self, val: i8, order: Ordering) -> i8
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn fetch\_and(&self, val: i8, order: Ordering) -> i8
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn fetch\_nand(&self, val: i8, order: Ordering) -> i8
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn fetch\_or(&self, val: i8, order: Ordering) -> i8
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn fetch\_xor(&self, val: i8, order: Ordering) -> i8
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<i8, i8>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([i8](../../primitive.i8)) -> [Option](../../option/enum.option "enum std::option::Option")<[i8](../../primitive.i8)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicI8::compare_exchange`](struct.atomici8#method.compare_exchange "AtomicI8::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let x = AtomicI8::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)1.45.0 · #### pub fn fetch\_max(&self, val: i8, order: Ordering) -> i8
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)1.45.0 · #### pub fn fetch\_min(&self, val: i8, order: Ordering) -> i8
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`i8`](../../primitive.i8 "i8").
##### Examples
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicI8, Ordering};
let foo = AtomicI8::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### pub fn as\_mut\_ptr(&self) -> \*mut i8
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut i8` instead of `&AtomicI8`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicI8;
extern "C" {
fn my_atomic_op(arg: *mut i8);
}
let mut atomic = AtomicI8::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)### impl Debug for AtomicI8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicI8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicI8
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<i8> for AtomicI8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: i8) -> AtomicI8
Converts an `i8` into an `AtomicI8`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#209)### impl RefUnwindSafe for AtomicI8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)### impl Sync for AtomicI8
Auto Trait Implementations
--------------------------
### impl Send for AtomicI8
### impl Unpin for AtomicI8
### impl UnwindSafe for AtomicI8
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::atomic::AtomicU32 Struct std::sync::atomic::AtomicU32
===================================
```
#[repr(C, align(4))]pub struct AtomicU32 { /* private fields */ }
```
An integer type which can be safely shared between threads.
This type has the same in-memory representation as the underlying integer type, [`u32`](../../primitive.u32 "u32"). For more about the differences between atomic types and non-atomic types as well as information about the portability of this type, please see the [module-level documentation](index).
**Note:** This type is only available on platforms that support atomic loads and stores of [`u32`](../../primitive.u32 "u32").
Implementations
---------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)### impl AtomicU32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)const: 1.34.0 · #### pub const fn new(v: u32) -> AtomicU32
Creates a new atomic integer.
##### Examples
```
use std::sync::atomic::AtomicU32;
let atomic_forty_two = AtomicU32::new(42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn get\_mut(&mut self) -> &mut u32
Returns a mutable reference to the underlying integer.
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let mut some_var = AtomicU32::new(10);
assert_eq!(*some_var.get_mut(), 10);
*some_var.get_mut() = 5;
assert_eq!(some_var.load(Ordering::SeqCst), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn from\_mut(v: &mut u32) -> &mut AtomicU32
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut u32`.
**Note:** This function is only available on targets where `u32` has an alignment of 4 bytes.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU32, Ordering};
let mut some_int = 123;
let a = AtomicU32::from_mut(&mut some_int);
a.store(100, Ordering::Relaxed);
assert_eq!(some_int, 100);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn get\_mut\_slice(this: &mut [AtomicU32]) -> &mut [u32]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get non-atomic access to a `&mut [AtomicU32]` slice
This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
#![feature(atomic_from_mut, inline_const)]
use std::sync::atomic::{AtomicU32, Ordering};
let mut some_ints = [const { AtomicU32::new(0) }; 10];
let view: &mut [u32] = AtomicU32::get_mut_slice(&mut some_ints);
assert_eq!(view, [0; 10]);
view
.iter_mut()
.enumerate()
.for_each(|(idx, int)| *int = idx as _);
std::thread::scope(|s| {
some_ints
.iter()
.enumerate()
.for_each(|(idx, int)| {
s.spawn(move || assert_eq!(int.load(Ordering::Relaxed), idx as _));
})
});
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn from\_mut\_slice(v: &mut [u32]) -> &mut [AtomicU32]
🔬This is a nightly-only experimental API. (`atomic_from_mut` [#76314](https://github.com/rust-lang/rust/issues/76314))
Get atomic access to a `&mut [u32]` slice.
##### Examples
```
#![feature(atomic_from_mut)]
use std::sync::atomic::{AtomicU32, Ordering};
let mut some_ints = [0; 10];
let a = &*AtomicU32::from_mut_slice(&mut some_ints);
std::thread::scope(|s| {
for i in 0..a.len() {
s.spawn(move || a[i].store(i as _, Ordering::Relaxed));
}
});
for (i, n) in some_ints.into_iter().enumerate() {
assert_eq!(i, n as usize);
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)const: [unstable](https://github.com/rust-lang/rust/issues/78729 "Tracking issue for const_cell_into_inner") · #### pub fn into\_inner(self) -> u32
Consumes the atomic and returns the contained value.
This is safe because passing `self` by value guarantees that no other threads are concurrently accessing the atomic data.
##### Examples
```
use std::sync::atomic::AtomicU32;
let some_var = AtomicU32::new(5);
assert_eq!(some_var.into_inner(), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn load(&self, order: Ordering) -> u32
Loads a value from the atomic integer.
`load` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Release`](enum.ordering#variant.Release "Release") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let some_var = AtomicU32::new(5);
assert_eq!(some_var.load(Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn store(&self, val: u32, order: Ordering)
Stores a value into the atomic integer.
`store` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Possible values are [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Release`](enum.ordering#variant.Release "Release") and [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
##### Panics
Panics if `order` is [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let some_var = AtomicU32::new(5);
some_var.store(10, Ordering::Relaxed);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn swap(&self, val: u32, order: Ordering) -> u32
Stores a value into the atomic integer, returning the previous value.
`swap` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let some_var = AtomicU32::new(5);
assert_eq!(some_var.swap(10, Ordering::Relaxed), 5);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn compare\_and\_swap(&self, current: u32, new: u32, order: Ordering) -> u32
👎Deprecated since 1.50.0: Use `compare_exchange` or `compare_exchange_weak` instead
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is always the previous value. If it is equal to `current`, then the value was updated.
`compare_and_swap` also takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. Notice that even when using [`AcqRel`](enum.ordering#variant.AcqRel "AcqRel"), the operation might fail and hence just perform an `Acquire` load, but not have `Release` semantics. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed") if it happens, and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Migrating to `compare_exchange` and `compare_exchange_weak`
`compare_and_swap` is equivalent to `compare_exchange` with the following mapping for memory orderings:
| Original | Success | Failure |
| --- | --- | --- |
| Relaxed | Relaxed | Relaxed |
| Acquire | Acquire | Acquire |
| Release | Release | Relaxed |
| AcqRel | AcqRel | Acquire |
| SeqCst | SeqCst | SeqCst |
`compare_exchange_weak` is allowed to fail spuriously even when the comparison succeeds, which allows the compiler to generate better assembly code when the compare and swap is used in a loop.
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let some_var = AtomicU32::new(5);
assert_eq!(some_var.compare_and_swap(5, 10, Ordering::Relaxed), 5);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_and_swap(6, 12, Ordering::Relaxed), 10);
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn compare\_exchange( &self, current: u32, new: u32, success: Ordering, failure: Ordering) -> Result<u32, u32>
Stores a value into the atomic integer if the current value is the same as the `current` value.
The return value is a result indicating whether the new value was written and containing the previous value. On success this value is guaranteed to be equal to `current`.
`compare_exchange` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let some_var = AtomicU32::new(5);
assert_eq!(some_var.compare_exchange(5, 10,
Ordering::Acquire,
Ordering::Relaxed),
Ok(5));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
assert_eq!(some_var.compare_exchange(6, 12,
Ordering::SeqCst,
Ordering::Acquire),
Err(10));
assert_eq!(some_var.load(Ordering::Relaxed), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn compare\_exchange\_weak( &self, current: u32, new: u32, success: Ordering, failure: Ordering) -> Result<u32, u32>
Stores a value into the atomic integer if the current value is the same as the `current` value.
Unlike [`AtomicU32::compare_exchange`](struct.atomicu32#method.compare_exchange "AtomicU32::compare_exchange"), this function is allowed to spuriously fail even when the comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new value was written and containing the previous value.
`compare_exchange_weak` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. `success` describes the required ordering for the read-modify-write operation that takes place if the comparison with `current` succeeds. `failure` describes the required ordering for the load operation that takes place when the comparison fails. Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The failure ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let val = AtomicU32::new(4);
let mut old = val.load(Ordering::Relaxed);
loop {
let new = old * 2;
match val.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn fetch\_add(&self, val: u32, order: Ordering) -> u32
Adds to the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_add` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(0);
assert_eq!(foo.fetch_add(10, Ordering::SeqCst), 0);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn fetch\_sub(&self, val: u32, order: Ordering) -> u32
Subtracts from the current value, returning the previous value.
This operation wraps around on overflow.
`fetch_sub` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(20);
assert_eq!(foo.fetch_sub(10, Ordering::SeqCst), 20);
assert_eq!(foo.load(Ordering::SeqCst), 10);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn fetch\_and(&self, val: u32, order: Ordering) -> u32
Bitwise “and” with the current value.
Performs a bitwise “and” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_and` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(0b101101);
assert_eq!(foo.fetch_and(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b100001);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn fetch\_nand(&self, val: u32, order: Ordering) -> u32
Bitwise “nand” with the current value.
Performs a bitwise “nand” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_nand` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(0x13);
assert_eq!(foo.fetch_nand(0x31, Ordering::SeqCst), 0x13);
assert_eq!(foo.load(Ordering::SeqCst), !(0x13 & 0x31));
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn fetch\_or(&self, val: u32, order: Ordering) -> u32
Bitwise “or” with the current value.
Performs a bitwise “or” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_or` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(0b101101);
assert_eq!(foo.fetch_or(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b111111);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn fetch\_xor(&self, val: u32, order: Ordering) -> u32
Bitwise “xor” with the current value.
Performs a bitwise “xor” operation on the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_xor` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(0b101101);
assert_eq!(foo.fetch_xor(0b110011, Ordering::SeqCst), 0b101101);
assert_eq!(foo.load(Ordering::SeqCst), 0b011110);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)1.45.0 · #### pub fn fetch\_update<F>( &self, set\_order: Ordering, fetch\_order: Ordering, f: F) -> Result<u32, u32>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([u32](../../primitive.u32)) -> [Option](../../option/enum.option "enum std::option::Option")<[u32](../../primitive.u32)>,
Fetches the value, and applies a function to it that returns an optional new value. Returns a `Result` of `Ok(previous_value)` if the function returned `Some(_)`, else `Err(previous_value)`.
Note: This may call the function multiple times if the value has been changed from other threads in the meantime, as long as the function returns `Some(_)`, but the function will have been applied only once to the stored value.
`fetch_update` takes two [`Ordering`](enum.ordering "Ordering") arguments to describe the memory ordering of this operation. The first describes the required ordering for when the operation finally succeeds while the second describes the required ordering for loads. These correspond to the success and failure orderings of [`AtomicU32::compare_exchange`](struct.atomicu32#method.compare_exchange "AtomicU32::compare_exchange") respectively.
Using [`Acquire`](enum.ordering#variant.Acquire "Acquire") as success ordering makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the final successful load [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"). The (failed) load ordering can only be [`SeqCst`](enum.ordering#variant.SeqCst "SeqCst"), [`Acquire`](enum.ordering#variant.Acquire "Acquire") or [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let x = AtomicU32::new(7);
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |_| None), Err(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(7));
assert_eq!(x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| Some(x + 1)), Ok(8));
assert_eq!(x.load(Ordering::SeqCst), 9);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)1.45.0 · #### pub fn fetch\_max(&self, val: u32, order: Ordering) -> u32
Maximum with the current value.
Finds the maximum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_max` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(23);
assert_eq!(foo.fetch_max(42, Ordering::SeqCst), 23);
assert_eq!(foo.load(Ordering::SeqCst), 42);
```
If you want to obtain the maximum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(23);
let bar = 42;
let max_foo = foo.fetch_max(bar, Ordering::SeqCst).max(bar);
assert!(max_foo == 42);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)1.45.0 · #### pub fn fetch\_min(&self, val: u32, order: Ordering) -> u32
Minimum with the current value.
Finds the minimum of the current value and the argument `val`, and sets the new value to the result.
Returns the previous value.
`fetch_min` takes an [`Ordering`](enum.ordering "Ordering") argument which describes the memory ordering of this operation. All ordering modes are possible. Note that using [`Acquire`](enum.ordering#variant.Acquire "Acquire") makes the store part of this operation [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed"), and using [`Release`](enum.ordering#variant.Release "Release") makes the load part [`Relaxed`](enum.ordering#variant.Relaxed "Relaxed").
**Note**: This method is only available on platforms that support atomic operations on [`u32`](../../primitive.u32 "u32").
##### Examples
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(23);
assert_eq!(foo.fetch_min(42, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 23);
assert_eq!(foo.fetch_min(22, Ordering::Relaxed), 23);
assert_eq!(foo.load(Ordering::Relaxed), 22);
```
If you want to obtain the minimum value in one step, you can use the following:
```
use std::sync::atomic::{AtomicU32, Ordering};
let foo = AtomicU32::new(23);
let bar = 12;
let min_foo = foo.fetch_min(bar, Ordering::SeqCst).min(bar);
assert_eq!(min_foo, 12);
```
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### pub fn as\_mut\_ptr(&self) -> \*mut u32
🔬This is a nightly-only experimental API. (`atomic_mut_ptr` [#66893](https://github.com/rust-lang/rust/issues/66893))
Returns a mutable pointer to the underlying integer.
Doing non-atomic reads and writes on the resulting integer can be a data race. This method is mostly useful for FFI, where the function signature may use `*mut u32` instead of `&AtomicU32`.
Returning an `*mut` pointer from a shared reference to this atomic is safe because the atomic types work with interior mutability. All modifications of an atomic change the value through a shared reference, and can do so safely as long as they use atomic operations. Any use of the returned raw pointer requires an `unsafe` block and still has to uphold the same restriction: operations on it must be atomic.
##### Examples
ⓘ
```
use std::sync::atomic::AtomicU32;
extern "C" {
fn my_atomic_op(arg: *mut u32);
}
let mut atomic = AtomicU32::new(1);
unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)### impl Debug for AtomicU32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl Default for AtomicU32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> AtomicU32
Returns the “default value” for a type. [Read more](../../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · ### impl From<u32> for AtomicU32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)const: [unstable](https://github.com/rust-lang/rust/issues/87852 "Tracking issue for const_num_from_num") · #### fn from(v: u32) -> AtomicU32
Converts an `u32` into an `AtomicU32`.
[source](https://doc.rust-lang.org/src/core/panic/unwind_safe.rs.html#234)### impl RefUnwindSafe for AtomicU32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)### impl Sync for AtomicU32
Auto Trait Implementations
--------------------------
### impl Send for AtomicU32
### impl Unpin for AtomicU32
### impl UnwindSafe for AtomicU32
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Constant std::sync::atomic::ATOMIC_U64_INIT Constant std::sync::atomic::ATOMIC\_U64\_INIT
=============================================
```
pub const ATOMIC_U64_INIT: AtomicU64;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Constant std::sync::atomic::ATOMIC_U32_INIT Constant std::sync::atomic::ATOMIC\_U32\_INIT
=============================================
```
pub const ATOMIC_U32_INIT: AtomicU32;
```
👎Deprecated since 1.34.0: the `new` function is now preferred
🔬This is a nightly-only experimental API. (`integer_atomics` [#99069](https://github.com/rust-lang/rust/issues/99069))
An atomic integer initialized to `0`.
rust Module std::sync::mpsc Module std::sync::mpsc
======================
Multi-producer, single-consumer FIFO queue communication primitives.
This module provides message-based communication over channels, concretely defined among three types:
* [`Sender`](struct.sender "Sender")
* [`SyncSender`](struct.syncsender "SyncSender")
* [`Receiver`](struct.receiver "Receiver")
A [`Sender`](struct.sender "Sender") or [`SyncSender`](struct.syncsender "SyncSender") is used to send data to a [`Receiver`](struct.receiver "Receiver"). Both senders are clone-able (multi-producer) such that many threads can send simultaneously to one receiver (single-consumer).
These channels come in two flavors:
1. An asynchronous, infinitely buffered channel. The [`channel`](fn.channel "channel") function will return a `(Sender, Receiver)` tuple where all sends will be **asynchronous** (they never block). The channel conceptually has an infinite buffer.
2. A synchronous, bounded channel. The [`sync_channel`](fn.sync_channel "sync_channel") function will return a `(SyncSender, Receiver)` tuple where the storage for pending messages is a pre-allocated buffer of a fixed size. All sends will be **synchronous** by blocking until there is buffer space available. Note that a bound of 0 is allowed, causing the channel to become a “rendezvous” channel where each sender atomically hands off a message to a receiver.
### Disconnection
The send and receive operations on channels will all return a [`Result`](../../result/enum.result "Result") indicating whether the operation succeeded or not. An unsuccessful operation is normally indicative of the other half of a channel having “hung up” by being dropped in its corresponding thread.
Once half of a channel has been deallocated, most operations can no longer continue to make progress, so [`Err`](../../result/enum.result#variant.Err "Err") will be returned. Many applications will continue to [`unwrap`](../../result/enum.result#method.unwrap) the results returned from this module, instigating a propagation of failure among threads if one unexpectedly dies.
Examples
--------
Simple usage:
```
use std::thread;
use std::sync::mpsc::channel;
// Create a simple streaming channel
let (tx, rx) = channel();
thread::spawn(move|| {
tx.send(10).unwrap();
});
assert_eq!(rx.recv().unwrap(), 10);
```
Shared usage:
```
use std::thread;
use std::sync::mpsc::channel;
// Create a shared channel that can be sent along from many threads
// where tx is the sending half (tx for transmission), and rx is the receiving
// half (rx for receiving).
let (tx, rx) = channel();
for i in 0..10 {
let tx = tx.clone();
thread::spawn(move|| {
tx.send(i).unwrap();
});
}
for _ in 0..10 {
let j = rx.recv().unwrap();
assert!(0 <= j && j < 10);
}
```
Propagating panics:
```
use std::sync::mpsc::channel;
// The call to recv() will return an error because the channel has already
// hung up (or been deallocated)
let (tx, rx) = channel::<i32>();
drop(tx);
assert!(rx.recv().is_err());
```
Synchronous channels:
```
use std::thread;
use std::sync::mpsc::sync_channel;
let (tx, rx) = sync_channel::<i32>(0);
thread::spawn(move|| {
// This will wait for the parent thread to start receiving
tx.send(53).unwrap();
});
rx.recv().unwrap();
```
Unbounded receive loop:
```
use std::sync::mpsc::sync_channel;
use std::thread;
let (tx, rx) = sync_channel(3);
for _ in 0..3 {
// It would be the same without thread and clone here
// since there will still be one `tx` left.
let tx = tx.clone();
// cloned tx dropped within thread
thread::spawn(move || tx.send("ok").unwrap());
}
// Drop the last sender to stop `rx` waiting for message.
// The program will not complete if we comment this out.
// **All** `tx` needs to be dropped for `rx` to have `Err`.
drop(tx);
// Unbounded receiver waiting for all senders to complete.
while let Ok(msg) = rx.recv() {
println!("{msg}");
}
println!("completed");
```
Structs
-------
[IntoIter](struct.intoiter "std::sync::mpsc::IntoIter struct")
An owning iterator over messages on a [`Receiver`](struct.receiver "Receiver"), created by [`into_iter`](struct.receiver#method.into_iter).
[Iter](struct.iter "std::sync::mpsc::Iter struct")
An iterator over messages on a [`Receiver`](struct.receiver "Receiver"), created by [`iter`](struct.receiver#method.iter).
[Receiver](struct.receiver "std::sync::mpsc::Receiver struct")
The receiving half of Rust’s [`channel`](fn.channel "channel") (or [`sync_channel`](fn.sync_channel "sync_channel")) type. This half can only be owned by one thread.
[RecvError](struct.recverror "std::sync::mpsc::RecvError struct")
An error returned from the [`recv`](struct.receiver#method.recv) function on a [`Receiver`](struct.receiver "Receiver").
[SendError](struct.senderror "std::sync::mpsc::SendError struct")
An error returned from the [`Sender::send`](struct.sender#method.send "Sender::send") or [`SyncSender::send`](struct.syncsender#method.send "SyncSender::send") function on **channel**s.
[Sender](struct.sender "std::sync::mpsc::Sender struct")
The sending-half of Rust’s asynchronous [`channel`](fn.channel "channel") type. This half can only be owned by one thread, but it can be cloned to send to other threads.
[SyncSender](struct.syncsender "std::sync::mpsc::SyncSender struct")
The sending-half of Rust’s synchronous [`sync_channel`](fn.sync_channel "sync_channel") type.
[TryIter](struct.tryiter "std::sync::mpsc::TryIter struct")
An iterator that attempts to yield all pending values for a [`Receiver`](struct.receiver "Receiver"), created by [`try_iter`](struct.receiver#method.try_iter).
Enums
-----
[RecvTimeoutError](enum.recvtimeouterror "std::sync::mpsc::RecvTimeoutError enum")
This enumeration is the list of possible errors that made [`recv_timeout`](struct.receiver#method.recv_timeout) unable to return data when called. This can occur with both a [`channel`](fn.channel "channel") and a [`sync_channel`](fn.sync_channel "sync_channel").
[TryRecvError](enum.tryrecverror "std::sync::mpsc::TryRecvError enum")
This enumeration is the list of the possible reasons that [`try_recv`](struct.receiver#method.try_recv) could not return data when called. This can occur with both a [`channel`](fn.channel "channel") and a [`sync_channel`](fn.sync_channel "sync_channel").
[TrySendError](enum.trysenderror "std::sync::mpsc::TrySendError enum")
This enumeration is the list of the possible error outcomes for the [`try_send`](struct.syncsender#method.try_send) method.
Functions
---------
[channel](fn.channel "std::sync::mpsc::channel fn")
Creates a new asynchronous channel, returning the sender/receiver halves. All data sent on the [`Sender`](struct.sender "Sender") will become available on the [`Receiver`](struct.receiver "Receiver") in the same order as it was sent, and no [`send`](struct.sender#method.send) will block the calling thread (this channel has an “infinite buffer”, unlike [`sync_channel`](fn.sync_channel "sync_channel"), which will block after its buffer limit is reached). [`recv`](struct.receiver#method.recv) will block until a message is available while there is at least one [`Sender`](struct.sender "Sender") alive (including clones).
[sync\_channel](fn.sync_channel "std::sync::mpsc::sync_channel fn")
Creates a new synchronous, bounded channel. All data sent on the [`SyncSender`](struct.syncsender "SyncSender") will become available on the [`Receiver`](struct.receiver "Receiver") in the same order as it was sent. Like asynchronous [`channel`](fn.channel "channel")s, the [`Receiver`](struct.receiver "Receiver") will block until a message becomes available. `sync_channel` differs greatly in the semantics of the sender, however.
rust Function std::sync::mpsc::sync_channel Function std::sync::mpsc::sync\_channel
=======================================
```
pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>)
```
Creates a new synchronous, bounded channel. All data sent on the [`SyncSender`](struct.syncsender "SyncSender") will become available on the [`Receiver`](struct.receiver "Receiver") in the same order as it was sent. Like asynchronous [`channel`](fn.channel "channel")s, the [`Receiver`](struct.receiver "Receiver") will block until a message becomes available. `sync_channel` differs greatly in the semantics of the sender, however.
This channel has an internal buffer on which messages will be queued. `bound` specifies the buffer size. When the internal buffer becomes full, future sends will *block* waiting for the buffer to open up. Note that a buffer size of 0 is valid, in which case this becomes “rendezvous channel” where each [`send`](struct.syncsender#method.send) will not return until a [`recv`](struct.receiver#method.recv) is paired with it.
The [`SyncSender`](struct.syncsender "SyncSender") can be cloned to [`send`](struct.syncsender#method.send) to the same channel multiple times, but only one [`Receiver`](struct.receiver "Receiver") is supported.
Like asynchronous channels, if the [`Receiver`](struct.receiver "Receiver") is disconnected while trying to [`send`](struct.syncsender#method.send) with the [`SyncSender`](struct.syncsender "SyncSender"), the [`send`](struct.syncsender#method.send) method will return a [`SendError`](struct.senderror "SendError"). Similarly, If the [`SyncSender`](struct.syncsender "SyncSender") is disconnected while trying to [`recv`](struct.receiver#method.recv), the [`recv`](struct.receiver#method.recv) method will return a [`RecvError`](struct.recverror "RecvError").
Examples
--------
```
use std::sync::mpsc::sync_channel;
use std::thread;
let (sender, receiver) = sync_channel(1);
// this returns immediately
sender.send(1).unwrap();
thread::spawn(move|| {
// this will block until the previous message has been received
sender.send(2).unwrap();
});
assert_eq!(receiver.recv().unwrap(), 1);
assert_eq!(receiver.recv().unwrap(), 2);
```
rust Function std::sync::mpsc::channel Function std::sync::mpsc::channel
=================================
```
pub fn channel<T>() -> (Sender<T>, Receiver<T>)
```
Creates a new asynchronous channel, returning the sender/receiver halves. All data sent on the [`Sender`](struct.sender "Sender") will become available on the [`Receiver`](struct.receiver "Receiver") in the same order as it was sent, and no [`send`](struct.sender#method.send) will block the calling thread (this channel has an “infinite buffer”, unlike [`sync_channel`](fn.sync_channel "sync_channel"), which will block after its buffer limit is reached). [`recv`](struct.receiver#method.recv) will block until a message is available while there is at least one [`Sender`](struct.sender "Sender") alive (including clones).
The [`Sender`](struct.sender "Sender") can be cloned to [`send`](struct.sender#method.send) to the same channel multiple times, but only one [`Receiver`](struct.receiver "Receiver") is supported.
If the [`Receiver`](struct.receiver "Receiver") is disconnected while trying to [`send`](struct.sender#method.send) with the [`Sender`](struct.sender "Sender"), the [`send`](struct.sender#method.send) method will return a [`SendError`](struct.senderror "SendError"). Similarly, if the [`Sender`](struct.sender "Sender") is disconnected while trying to [`recv`](struct.receiver#method.recv), the [`recv`](struct.receiver#method.recv) method will return a [`RecvError`](struct.recverror "RecvError").
Examples
--------
```
use std::sync::mpsc::channel;
use std::thread;
let (sender, receiver) = channel();
// Spawn off an expensive computation
thread::spawn(move|| {
sender.send(expensive_computation()).unwrap();
});
// Do some useful work for awhile
// Let's see what that answer was
println!("{:?}", receiver.recv().unwrap());
```
rust Struct std::sync::mpsc::IntoIter Struct std::sync::mpsc::IntoIter
================================
```
pub struct IntoIter<T> { /* private fields */ }
```
An owning iterator over messages on a [`Receiver`](struct.receiver "Receiver"), created by [`into_iter`](struct.receiver#method.into_iter).
This iterator will block whenever [`next`](../../iter/trait.iterator#tymethod.next) is called, waiting for a new message, and [`None`](../../option/enum.option#variant.None "None") will be returned if the corresponding channel has hung up.
Examples
--------
```
use std::sync::mpsc::channel;
use std::thread;
let (send, recv) = channel();
thread::spawn(move || {
send.send(1u8).unwrap();
send.send(2u8).unwrap();
send.send(3u8).unwrap();
});
for x in recv.into_iter() {
println!("Got: {x}");
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#460)### impl<T: Debug> Debug for IntoIter<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#460)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1483-1488)### impl<T> Iterator for IntoIter<T>
#### type Item = T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1485-1487)#### fn next(&mut self) -> Option<T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#215)1.0.0 · #### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
Auto Trait Implementations
--------------------------
### impl<T> !RefUnwindSafe for IntoIter<T>
### impl<T> Send for IntoIter<T>where T: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<T> !Sync for IntoIter<T>
### impl<T> Unpin for IntoIter<T>
### impl<T> !UnwindSafe for IntoIter<T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::mpsc::Receiver Struct std::sync::mpsc::Receiver
================================
```
pub struct Receiver<T> { /* private fields */ }
```
The receiving half of Rust’s [`channel`](fn.channel "channel") (or [`sync_channel`](fn.sync_channel "sync_channel")) type. This half can only be owned by one thread.
Messages sent to the channel can be retrieved using [`recv`](struct.receiver#method.recv).
Examples
--------
```
use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;
let (send, recv) = channel();
thread::spawn(move || {
send.send("Hello world!").unwrap();
thread::sleep(Duration::from_secs(2)); // block for two seconds
send.send("Delayed for 2 seconds").unwrap();
});
println!("{}", recv.recv().unwrap()); // Received immediately
println!("Waiting...");
println!("{}", recv.recv().unwrap()); // Received after 2 seconds
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1042-1452)### impl<T> Receiver<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1071-1101)#### pub fn try\_recv(&self) -> Result<T, TryRecvError>
Attempts to return a pending value on this receiver without blocking.
This method will never block the caller in order to wait for data to become available. Instead, this will always return immediately with a possible option of pending data on the channel.
This is useful for a flavor of “optimistic check” before deciding to block on a receiver.
Compared with [`recv`](struct.receiver#method.recv), this function has two failure cases instead of one (one for disconnection, one for an empty buffer).
##### Examples
```
use std::sync::mpsc::{Receiver, channel};
let (_, receiver): (_, Receiver<i32>) = channel();
assert!(receiver.try_recv().is_err());
```
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1158-1184)#### pub fn recv(&self) -> Result<T, RecvError>
Attempts to wait for a value on this receiver, returning an error if the corresponding channel has hung up.
This function will always block the current thread if there is no data available and it’s possible for more data to be sent (at least one sender still exists). Once a message is sent to the corresponding [`Sender`](struct.sender "Sender") (or [`SyncSender`](struct.syncsender "SyncSender")), this receiver will wake up and return that message.
If the corresponding [`Sender`](struct.sender "Sender") has disconnected, or it disconnects while this call is blocking, this call will wake up and return [`Err`](../../result/enum.result#variant.Err "Err") to indicate that no more messages can ever be received on this channel. However, since channels are buffered, messages sent before the disconnect will still be properly received.
##### Examples
```
use std::sync::mpsc;
use std::thread;
let (send, recv) = mpsc::channel();
let handle = thread::spawn(move || {
send.send(1u8).unwrap();
});
handle.join().unwrap();
assert_eq!(Ok(1), recv.recv());
```
Buffering behavior:
```
use std::sync::mpsc;
use std::thread;
use std::sync::mpsc::RecvError;
let (send, recv) = mpsc::channel();
let handle = thread::spawn(move || {
send.send(1u8).unwrap();
send.send(2).unwrap();
send.send(3).unwrap();
drop(send);
});
// wait for the thread to join so we ensure the sender is dropped
handle.join().unwrap();
assert_eq!(Ok(1), recv.recv());
assert_eq!(Ok(2), recv.recv());
assert_eq!(Ok(3), recv.recv());
assert_eq!(Err(RecvError), recv.recv());
```
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1270-1282)1.12.0 · #### pub fn recv\_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError>
Attempts to wait for a value on this receiver, returning an error if the corresponding channel has hung up, or if it waits more than `timeout`.
This function will always block the current thread if there is no data available and it’s possible for more data to be sent (at least one sender still exists). Once a message is sent to the corresponding [`Sender`](struct.sender "Sender") (or [`SyncSender`](struct.syncsender "SyncSender")), this receiver will wake up and return that message.
If the corresponding [`Sender`](struct.sender "Sender") has disconnected, or it disconnects while this call is blocking, this call will wake up and return [`Err`](../../result/enum.result#variant.Err "Err") to indicate that no more messages can ever be received on this channel. However, since channels are buffered, messages sent before the disconnect will still be properly received.
##### Known Issues
There is currently a known issue (see [`#39364`](https://github.com/rust-lang/rust/issues/39364)) that causes `recv_timeout` to panic unexpectedly with the following example:
```
use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;
let (tx, rx) = channel::<String>();
thread::spawn(move || {
let d = Duration::from_millis(10);
loop {
println!("recv");
let _r = rx.recv_timeout(d);
}
});
thread::sleep(Duration::from_millis(100));
let _c1 = tx.clone();
thread::sleep(Duration::from_secs(1));
```
##### Examples
Successfully receiving value before encountering timeout:
```
use std::thread;
use std::time::Duration;
use std::sync::mpsc;
let (send, recv) = mpsc::channel();
thread::spawn(move || {
send.send('a').unwrap();
});
assert_eq!(
recv.recv_timeout(Duration::from_millis(400)),
Ok('a')
);
```
Receiving an error upon reaching timeout:
```
use std::thread;
use std::time::Duration;
use std::sync::mpsc;
let (send, recv) = mpsc::channel();
thread::spawn(move || {
thread::sleep(Duration::from_millis(800));
send.send('a').unwrap();
});
assert_eq!(
recv.recv_timeout(Duration::from_millis(400)),
Err(mpsc::RecvTimeoutError::Timeout)
);
```
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1341-1382)#### pub fn recv\_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError>
🔬This is a nightly-only experimental API. (`deadline_api` [#46316](https://github.com/rust-lang/rust/issues/46316))
Attempts to wait for a value on this receiver, returning an error if the corresponding channel has hung up, or if `deadline` is reached.
This function will always block the current thread if there is no data available and it’s possible for more data to be sent. Once a message is sent to the corresponding [`Sender`](struct.sender "Sender") (or [`SyncSender`](struct.syncsender "SyncSender")), then this receiver will wake up and return that message.
If the corresponding [`Sender`](struct.sender "Sender") has disconnected, or it disconnects while this call is blocking, this call will wake up and return [`Err`](../../result/enum.result#variant.Err "Err") to indicate that no more messages can ever be received on this channel. However, since channels are buffered, messages sent before the disconnect will still be properly received.
##### Examples
Successfully receiving value before reaching deadline:
```
#![feature(deadline_api)]
use std::thread;
use std::time::{Duration, Instant};
use std::sync::mpsc;
let (send, recv) = mpsc::channel();
thread::spawn(move || {
send.send('a').unwrap();
});
assert_eq!(
recv.recv_deadline(Instant::now() + Duration::from_millis(400)),
Ok('a')
);
```
Receiving an error upon reaching deadline:
```
#![feature(deadline_api)]
use std::thread;
use std::time::{Duration, Instant};
use std::sync::mpsc;
let (send, recv) = mpsc::channel();
thread::spawn(move || {
thread::sleep(Duration::from_millis(800));
send.send('a').unwrap();
});
assert_eq!(
recv.recv_deadline(Instant::now() + Duration::from_millis(400)),
Err(mpsc::RecvTimeoutError::Timeout)
);
```
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1408-1410)#### pub fn iter(&self) -> Iter<'\_, T>
Notable traits for [Iter](struct.iter "struct std::sync::mpsc::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = T;
```
Returns an iterator that will block waiting for messages, but never [`panic!`](../../macro.panic "panic!"). It will return [`None`](../../option/enum.option#variant.None "None") when the channel has hung up.
##### Examples
```
use std::sync::mpsc::channel;
use std::thread;
let (send, recv) = channel();
thread::spawn(move || {
send.send(1).unwrap();
send.send(2).unwrap();
send.send(3).unwrap();
});
let mut iter = recv.iter();
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), None);
```
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1449-1451)1.15.0 · #### pub fn try\_iter(&self) -> TryIter<'\_, T>
Notable traits for [TryIter](struct.tryiter "struct std::sync::mpsc::TryIter")<'a, T>
```
impl<'a, T> Iterator for TryIter<'a, T>
type Item = T;
```
Returns an iterator that will attempt to yield all pending values. It will return `None` if there are no more pending values or if the channel has hung up. The iterator will never [`panic!`](../../macro.panic "panic!") or block the user by waiting for values.
##### Examples
```
use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;
let (sender, receiver) = channel();
// nothing is in the buffer yet
assert!(receiver.try_iter().next().is_none());
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
sender.send(1).unwrap();
sender.send(2).unwrap();
sender.send(3).unwrap();
});
// nothing is in the buffer yet
assert!(receiver.try_iter().next().is_none());
// block for two seconds
thread::sleep(Duration::from_secs(2));
let mut iter = receiver.try_iter();
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), None);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1513-1517)1.8.0 · ### impl<T> Debug for Receiver<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1514-1516)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1501-1510)### impl<T> Drop for Receiver<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1502-1509)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1473-1480)1.1.0 · ### impl<'a, T> IntoIterator for &'a Receiver<T>
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1477-1479)#### fn into\_iter(self) -> Iter<'a, T>
Notable traits for [Iter](struct.iter "struct std::sync::mpsc::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = T;
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1491-1498)1.1.0 · ### impl<T> IntoIterator for Receiver<T>
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1495-1497)#### fn into\_iter(self) -> IntoIter<T>
Notable traits for [IntoIter](struct.intoiter "struct std::sync::mpsc::IntoIter")<T>
```
impl<T> Iterator for IntoIter<T>
type Item = T;
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#350)### impl<T: Send> Send for Receiver<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#353)### impl<T> !Sync for Receiver<T>
Auto Trait Implementations
--------------------------
### impl<T> !RefUnwindSafe for Receiver<T>
### impl<T> Unpin for Receiver<T>
### impl<T> !UnwindSafe for Receiver<T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::mpsc::Sender Struct std::sync::mpsc::Sender
==============================
```
pub struct Sender<T> { /* private fields */ }
```
The sending-half of Rust’s asynchronous [`channel`](fn.channel "channel") type. This half can only be owned by one thread, but it can be cloned to send to other threads.
Messages can be sent through this channel with [`send`](struct.sender#method.send).
Note: all senders (the original and the clones) need to be dropped for the receiver to stop blocking to receive messages with [`Receiver::recv`](struct.receiver#method.recv "Receiver::recv").
Examples
--------
```
use std::sync::mpsc::channel;
use std::thread;
let (sender, receiver) = channel();
let sender2 = sender.clone();
// First thread owns sender
thread::spawn(move || {
sender.send(1).unwrap();
});
// Second thread owns sender2
thread::spawn(move || {
sender2.send(2).unwrap();
});
let msg = receiver.recv().unwrap();
let msg2 = receiver.recv().unwrap();
assert_eq!(3, msg + msg2);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#771-840)### impl<T> Sender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#804-839)#### pub fn send(&self, t: T) -> Result<(), SendError<T>>
Attempts to send a value on this channel, returning it back if it could not be sent.
A successful send occurs when it is determined that the other end of the channel has not hung up already. An unsuccessful send would be one where the corresponding receiver has already been deallocated. Note that a return value of [`Err`](../../result/enum.result#variant.Err "Err") means that the data will never be received, but a return value of [`Ok`](../../result/enum.result#variant.Ok "Ok") does *not* mean that the data will be received. It is possible for the corresponding receiver to hang up immediately after this function returns [`Ok`](../../result/enum.result#variant.Ok "Ok").
This method will never block the current thread.
##### Examples
```
use std::sync::mpsc::channel;
let (tx, rx) = channel();
// This send is always successful
tx.send(1).unwrap();
// This send will fail because the receiver is gone
drop(rx);
assert_eq!(tx.send(1).unwrap_err().0, 1);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#843-890)### impl<T> Clone for Sender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#849-889)#### fn clone(&self) -> Sender<T>
Clone a sender to send to other threads.
Note, be aware of the lifetime of the sender because all senders (including the original) need to be dropped in order for [`Receiver::recv`](struct.receiver#method.recv "Receiver::recv") to stop blocking.
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#905-909)1.8.0 · ### impl<T> Debug for Sender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#906-908)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#893-902)### impl<T> Drop for Sender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#894-901)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#507)### impl<T: Send> Send for Sender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#510)### impl<T> !Sync for Sender<T>
Auto Trait Implementations
--------------------------
### impl<T> !RefUnwindSafe for Sender<T>
### impl<T> Unpin for Sender<T>
### impl<T> !UnwindSafe for Sender<T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::mpsc::SendError Struct std::sync::mpsc::SendError
=================================
```
pub struct SendError<T>(pub T);
```
An error returned from the [`Sender::send`](struct.sender#method.send "Sender::send") or [`SyncSender::send`](struct.syncsender#method.send "SyncSender::send") function on **channel**s.
A **send** operation can only fail if the receiving end of a channel is disconnected, implying that the data could never be received. The error contains the data being sent as a payload so it can be recovered.
Tuple Fields
------------
`0: T`Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)### impl<T: Clone> Clone for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)#### fn clone(&self) -> SendError<T>
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1520-1524)### impl<T> Debug for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1521-1523)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1527-1531)### impl<T> Display for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1528-1530)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1534-1539)### impl<T: Send> Error for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1536-1538)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1573-1584)1.24.0 · ### impl<T> From<SendError<T>> for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1579-1583)#### fn from(err: SendError<T>) -> TrySendError<T>
Converts a `SendError<T>` into a `TrySendError<T>`.
This conversion always returns a `TrySendError::Disconnected` containing the data in the `SendError<T>`.
No data is allocated on the heap.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)### impl<T: PartialEq> PartialEq<SendError<T>> for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)#### fn eq(&self, other: &SendError<T>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)### impl<T: Copy> Copy for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)### impl<T: Eq> Eq for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)### impl<T> StructuralEq for SendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)### impl<T> StructuralPartialEq for SendError<T>
Auto Trait Implementations
--------------------------
### impl<T> RefUnwindSafe for SendError<T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T> Send for SendError<T>where T: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<T> Sync for SendError<T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<T> Unpin for SendError<T>where T: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T> UnwindSafe for SendError<T>where T: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../error/trait.error "trait std::error::Error") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Enum std::sync::mpsc::TrySendError Enum std::sync::mpsc::TrySendError
==================================
```
pub enum TrySendError<T> {
Full(T),
Disconnected(T),
}
```
This enumeration is the list of the possible error outcomes for the [`try_send`](struct.syncsender#method.try_send) method.
Variants
--------
### `Full(T)`
The data could not be sent on the [`sync_channel`](fn.sync_channel "sync_channel") because it would require that the callee block to send the data.
If this is a buffered channel, then the buffer is full at this time. If this is not a buffered channel, then there is no [`Receiver`](struct.receiver "Receiver") available to acquire the data.
### `Disconnected(T)`
This [`sync_channel`](fn.sync_channel "sync_channel")’s receiving half has disconnected, so the data could not be sent. The data is returned back to the callee in this case.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)### impl<T: Clone> Clone for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)#### fn clone(&self) -> TrySendError<T>
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1542-1549)### impl<T> Debug for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1543-1548)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1552-1559)### impl<T> Display for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1553-1558)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1562-1570)### impl<T: Send> Error for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1564-1569)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1573-1584)1.24.0 · ### impl<T> From<SendError<T>> for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1579-1583)#### fn from(err: SendError<T>) -> TrySendError<T>
Converts a `SendError<T>` into a `TrySendError<T>`.
This conversion always returns a `TrySendError::Disconnected` containing the data in the `SendError<T>`.
No data is allocated on the heap.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)### impl<T: PartialEq> PartialEq<TrySendError<T>> for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)#### fn eq(&self, other: &TrySendError<T>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)### impl<T: Copy> Copy for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)### impl<T: Eq> Eq for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)### impl<T> StructuralEq for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)### impl<T> StructuralPartialEq for TrySendError<T>
Auto Trait Implementations
--------------------------
### impl<T> RefUnwindSafe for TrySendError<T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T> Send for TrySendError<T>where T: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<T> Sync for TrySendError<T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<T> Unpin for TrySendError<T>where T: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T> UnwindSafe for TrySendError<T>where T: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../error/trait.error "trait std::error::Error") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Enum std::sync::mpsc::RecvTimeoutError Enum std::sync::mpsc::RecvTimeoutError
======================================
```
pub enum RecvTimeoutError {
Timeout,
Disconnected,
}
```
This enumeration is the list of possible errors that made [`recv_timeout`](struct.receiver#method.recv_timeout) unable to return data when called. This can occur with both a [`channel`](fn.channel "channel") and a [`sync_channel`](fn.sync_channel "sync_channel").
Variants
--------
### `Timeout`
This **channel** is currently empty, but the **Sender**(s) have not yet disconnected, so data may yet become available.
### `Disconnected`
The **channel**’s sending half has become disconnected, and there will never be any more data received on it.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)### impl Clone for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)#### fn clone(&self) -> RecvTimeoutError
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)### impl Debug for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1637-1644)1.15.0 · ### impl Display for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1638-1643)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1647-1655)1.15.0 · ### impl Error for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1649-1654)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)1.0.0 · #### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1658-1669)1.24.0 · ### impl From<RecvError> for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1664-1668)#### fn from(err: RecvError) -> RecvTimeoutError
Converts a `RecvError` into a `RecvTimeoutError`.
This conversion always returns `RecvTimeoutError::Disconnected`.
No data is allocated on the heap.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)### impl PartialEq<RecvTimeoutError> for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)#### fn eq(&self, other: &RecvTimeoutError) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)### impl Copy for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)### impl Eq for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)### impl StructuralEq for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)### impl StructuralPartialEq for RecvTimeoutError
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for RecvTimeoutError
### impl Send for RecvTimeoutError
### impl Sync for RecvTimeoutError
### impl Unpin for RecvTimeoutError
### impl UnwindSafe for RecvTimeoutError
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../error/trait.error "trait std::error::Error") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Enum std::sync::mpsc::TryRecvError Enum std::sync::mpsc::TryRecvError
==================================
```
pub enum TryRecvError {
Empty,
Disconnected,
}
```
This enumeration is the list of the possible reasons that [`try_recv`](struct.receiver#method.try_recv) could not return data when called. This can occur with both a [`channel`](fn.channel "channel") and a [`sync_channel`](fn.sync_channel "sync_channel").
Variants
--------
### `Empty`
This **channel** is currently empty, but the **Sender**(s) have not yet disconnected, so data may yet become available.
### `Disconnected`
The **channel**’s sending half has become disconnected, and there will never be any more data received on it.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl Clone for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)#### fn clone(&self) -> TryRecvError
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl Debug for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1602-1609)### impl Display for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1603-1608)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1612-1620)### impl Error for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1614-1619)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1623-1634)1.24.0 · ### impl From<RecvError> for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1629-1633)#### fn from(err: RecvError) -> TryRecvError
Converts a `RecvError` into a `TryRecvError`.
This conversion always returns `TryRecvError::Disconnected`.
No data is allocated on the heap.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl PartialEq<TryRecvError> for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)#### fn eq(&self, other: &TryRecvError) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl Copy for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl Eq for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl StructuralEq for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl StructuralPartialEq for TryRecvError
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for TryRecvError
### impl Send for TryRecvError
### impl Sync for TryRecvError
### impl Unpin for TryRecvError
### impl UnwindSafe for TryRecvError
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../error/trait.error "trait std::error::Error") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::mpsc::RecvError Struct std::sync::mpsc::RecvError
=================================
```
pub struct RecvError;
```
An error returned from the [`recv`](struct.receiver#method.recv) function on a [`Receiver`](struct.receiver "Receiver").
The [`recv`](struct.receiver#method.recv) operation can only fail if the sending half of a [`channel`](fn.channel "channel") (or [`sync_channel`](fn.sync_channel "sync_channel")) is disconnected, implying that no further messages will ever be received.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl Clone for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)#### fn clone(&self) -> RecvError
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl Debug for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1587-1591)### impl Display for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1588-1590)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1594-1599)### impl Error for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1596-1598)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)#### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1658-1669)1.24.0 · ### impl From<RecvError> for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1664-1668)#### fn from(err: RecvError) -> RecvTimeoutError
Converts a `RecvError` into a `RecvTimeoutError`.
This conversion always returns `RecvTimeoutError::Disconnected`.
No data is allocated on the heap.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1623-1634)1.24.0 · ### impl From<RecvError> for TryRecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1629-1633)#### fn from(err: RecvError) -> TryRecvError
Converts a `RecvError` into a `TryRecvError`.
This conversion always returns `TryRecvError::Disconnected`.
No data is allocated on the heap.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl PartialEq<RecvError> for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)#### fn eq(&self, other: &RecvError) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl Copy for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl Eq for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl StructuralEq for RecvError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl StructuralPartialEq for RecvError
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for RecvError
### impl Send for RecvError
### impl Sync for RecvError
### impl Unpin for RecvError
### impl UnwindSafe for RecvError
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../error/trait.error "trait std::error::Error") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::mpsc::SyncSender Struct std::sync::mpsc::SyncSender
==================================
```
pub struct SyncSender<T> { /* private fields */ }
```
The sending-half of Rust’s synchronous [`sync_channel`](fn.sync_channel "sync_channel") type.
Messages can be sent through this channel with [`send`](struct.syncsender#method.send) or [`try_send`](struct.syncsender#method.try_send).
[`send`](struct.syncsender#method.send) will block if there is no space in the internal buffer.
Examples
--------
```
use std::sync::mpsc::sync_channel;
use std::thread;
// Create a sync_channel with buffer size 2
let (sync_sender, receiver) = sync_channel(2);
let sync_sender2 = sync_sender.clone();
// First thread owns sync_sender
thread::spawn(move || {
sync_sender.send(1).unwrap();
sync_sender.send(2).unwrap();
});
// Second thread owns sync_sender2
thread::spawn(move || {
sync_sender2.send(3).unwrap();
// thread will now block since the buffer is full
println!("Thread unblocked!");
});
let mut msg;
msg = receiver.recv().unwrap();
println!("message {msg} received");
// "Thread unblocked!" will be printed now
msg = receiver.recv().unwrap();
println!("message {msg} received");
msg = receiver.recv().unwrap();
println!("message {msg} received");
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#915-1014)### impl<T> SyncSender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#957-959)#### pub fn send(&self, t: T) -> Result<(), SendError<T>>
Sends a value on this synchronous channel.
This function will *block* until space in the internal buffer becomes available or a receiver is available to hand off the message to.
Note that a successful send does *not* guarantee that the receiver will ever see the data if there is a buffer on this channel. Items may be enqueued in the internal buffer for the receiver to receive at a later time. If the buffer size is 0, however, the channel becomes a rendezvous channel and it guarantees that the receiver has indeed received the data if this function returns success.
This function will never panic, but it may return [`Err`](../../result/enum.result#variant.Err "Err") if the [`Receiver`](struct.receiver "Receiver") has disconnected and is no longer able to receive information.
##### Examples
```
use std::sync::mpsc::sync_channel;
use std::thread;
// Create a rendezvous sync_channel with buffer size 0
let (sync_sender, receiver) = sync_channel(0);
thread::spawn(move || {
println!("sending message...");
sync_sender.send(1).unwrap();
// Thread is now blocked until the message is received
println!("...message received!");
});
let msg = receiver.recv().unwrap();
assert_eq!(1, msg);
```
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1011-1013)#### pub fn try\_send(&self, t: T) -> Result<(), TrySendError<T>>
Attempts to send a value on this channel without blocking.
This method differs from [`send`](struct.syncsender#method.send) by returning immediately if the channel’s buffer is full or no receiver is waiting to acquire some data. Compared with [`send`](struct.syncsender#method.send), this function has two failure cases instead of one (one for disconnection, one for a full buffer).
See [`send`](struct.syncsender#method.send) for notes about guarantees of whether the receiver has received the data or not if this function is successful.
##### Examples
```
use std::sync::mpsc::sync_channel;
use std::thread;
// Create a sync_channel with buffer size 1
let (sync_sender, receiver) = sync_channel(1);
let sync_sender2 = sync_sender.clone();
// First thread owns sync_sender
thread::spawn(move || {
sync_sender.send(1).unwrap();
sync_sender.send(2).unwrap();
// Thread blocked
});
// Second thread owns sync_sender2
thread::spawn(move || {
// This will return an error and send
// no message if the buffer is full
let _ = sync_sender2.try_send(3);
});
let mut msg;
msg = receiver.recv().unwrap();
println!("message {msg} received");
msg = receiver.recv().unwrap();
println!("message {msg} received");
// Third message may have never been sent
match receiver.try_recv() {
Ok(msg) => println!("message {msg} received"),
Err(_) => println!("the third message was never sent"),
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1017-1022)### impl<T> Clone for SyncSender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1018-1021)#### fn clone(&self) -> SyncSender<T>
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1032-1036)1.8.0 · ### impl<T> Debug for SyncSender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1033-1035)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1025-1029)### impl<T> Drop for SyncSender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1026-1028)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#564)### impl<T: Send> Send for SyncSender<T>
Auto Trait Implementations
--------------------------
### impl<T> RefUnwindSafe for SyncSender<T>
### impl<T> Sync for SyncSender<T>where T: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<T> Unpin for SyncSender<T>
### impl<T> UnwindSafe for SyncSender<T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::sync::mpsc::Iter Struct std::sync::mpsc::Iter
============================
```
pub struct Iter<'a, T: 'a> { /* private fields */ }
```
An iterator over messages on a [`Receiver`](struct.receiver "Receiver"), created by [`iter`](struct.receiver#method.iter).
This iterator will block whenever [`next`](../../iter/trait.iterator#tymethod.next) is called, waiting for a new message, and [`None`](../../option/enum.option#variant.None "None") will be returned when the corresponding channel has hung up.
Examples
--------
```
use std::sync::mpsc::channel;
use std::thread;
let (send, recv) = channel();
thread::spawn(move || {
send.send(1u8).unwrap();
send.send(2u8).unwrap();
send.send(3u8).unwrap();
});
for x in recv.iter() {
println!("Got: {x}");
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#383)### impl<'a, T: Debug + 'a> Debug for Iter<'a, T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#383)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1455-1461)### impl<'a, T> Iterator for Iter<'a, T>
#### type Item = T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1458-1460)#### fn next(&mut self) -> Option<T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#215)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
Auto Trait Implementations
--------------------------
### impl<'a, T> !RefUnwindSafe for Iter<'a, T>
### impl<'a, T> !Send for Iter<'a, T>
### impl<'a, T> !Sync for Iter<'a, T>
### impl<'a, T> Unpin for Iter<'a, T>
### impl<'a, T> !UnwindSafe for Iter<'a, T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::sync::mpsc::TryIter Struct std::sync::mpsc::TryIter
===============================
```
pub struct TryIter<'a, T: 'a> { /* private fields */ }
```
An iterator that attempts to yield all pending values for a [`Receiver`](struct.receiver "Receiver"), created by [`try_iter`](struct.receiver#method.try_iter).
[`None`](../../option/enum.option#variant.None "None") will be returned when there are no pending values remaining or if the corresponding channel has hung up.
This iterator will never block the caller in order to wait for data to become available. Instead, it will return [`None`](../../option/enum.option#variant.None "None").
Examples
--------
```
use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;
let (sender, receiver) = channel();
// Nothing is in the buffer yet
assert!(receiver.try_iter().next().is_none());
println!("Nothing in the buffer...");
thread::spawn(move || {
sender.send(1).unwrap();
sender.send(2).unwrap();
sender.send(3).unwrap();
});
println!("Going to sleep...");
thread::sleep(Duration::from_secs(2)); // block for two seconds
for x in receiver.try_iter() {
println!("Got: {x}");
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#426)### impl<'a, T: Debug + 'a> Debug for TryIter<'a, T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#426)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1464-1470)### impl<'a, T> Iterator for TryIter<'a, T>
#### type Item = T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#1467-1469)#### fn next(&mut self) -> Option<T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#215)1.0.0 · #### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)#### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)#### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
Auto Trait Implementations
--------------------------
### impl<'a, T> !RefUnwindSafe for TryIter<'a, T>
### impl<'a, T> !Send for TryIter<'a, T>
### impl<'a, T> !Sync for TryIter<'a, T>
### impl<'a, T> Unpin for TryIter<'a, T>
### impl<'a, T> !UnwindSafe for TryIter<'a, T>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Module std::prelude Module std::prelude
===================
The Rust Prelude
----------------
Rust comes with a variety of things in its standard library. However, if you had to manually import every single thing that you used, it would be very verbose. But importing a lot of things that a program never uses isn’t good either. A balance needs to be struck.
The *prelude* is the list of things that Rust automatically imports into every Rust program. It’s kept as small as possible, and is focused on things, particularly traits, which are used in almost every single Rust program.
Other preludes
--------------
Preludes can be seen as a pattern to make using multiple types more convenient. As such, you’ll find other preludes in the standard library, such as [`std::io::prelude`](../io/prelude/index). Various libraries in the Rust ecosystem may also define their own preludes.
The difference between ‘the prelude’ and these other preludes is that they are not automatically `use`’d, and must be imported manually. This is still easier than importing all of their constituent components.
Prelude contents
----------------
The first version of the prelude is used in Rust 2015 and Rust 2018, and lives in [`std::prelude::v1`](v1/index). [`std::prelude::rust_2015`](rust_2015/index) and [`std::prelude::rust_2018`](rust_2018/index) re-export this prelude. It re-exports the following:
* `[std::marker](../marker/index)::{[Copy](../marker/trait.copy "Copy"), [Send](../marker/trait.send "Send"), [Sized](../marker/trait.sized "Sized"), [Sync](../marker/trait.sync "Sync"), [Unpin](../marker/trait.unpin "Unpin")}`, marker traits that indicate fundamental properties of types.
* `[std::ops](../ops/index)::{[Drop](../ops/trait.drop "Drop"), [Fn](../ops/trait.fn "Fn"), [FnMut](../ops/trait.fnmut "FnMut"), [FnOnce](../ops/trait.fnonce "FnOnce")}`, various operations for both destructors and overloading `()`.
* `[std::mem](../mem/index)::[drop](../mem/fn.drop)`, a convenience function for explicitly dropping a value.
* `[std::boxed](../boxed/index)::[Box](../boxed/struct.box "Box")`, a way to allocate values on the heap.
* `[std::borrow](../borrow/index)::[ToOwned](../borrow/trait.toowned "ToOwned")`, the conversion trait that defines [`to_owned`](../borrow/trait.toowned#tymethod.to_owned), the generic method for creating an owned type from a borrowed type.
* `[std::clone](../clone/index)::[Clone](../clone/trait.clone "Clone")`, the ubiquitous trait that defines [`clone`](../clone/trait.clone#tymethod.clone "Clone::clone"), the method for producing a copy of a value.
* `[std::cmp](../cmp/index)::{[PartialEq](../cmp/trait.partialeq "PartialEq"), [PartialOrd](../cmp/trait.partialord "PartialOrd"), [Eq](../cmp/trait.eq "Eq"), [Ord](../cmp/trait.ord "Ord")}`, the comparison traits, which implement the comparison operators and are often seen in trait bounds.
* `[std::convert](../convert/index)::{[AsRef](../convert/trait.asref "AsRef"), [AsMut](../convert/trait.asmut "AsMut"), [Into](../convert/trait.into "Into"), [From](../convert/trait.from "From")}`, generic conversions, used by savvy API authors to create overloaded methods.
* `[std::default](../default/index)::[Default](../default/trait.default "Default")`, types that have default values.
* `[std::iter](../iter/index)::{[Iterator](../iter/trait.iterator "Iterator"), [Extend](../iter/trait.extend "Extend"), [IntoIterator](../iter/trait.intoiterator "IntoIterator"), [DoubleEndedIterator](../iter/trait.doubleendediterator "DoubleEndedIterator"), [ExactSizeIterator](../iter/trait.exactsizeiterator "ExactSizeIterator")}`, iterators of various kinds.
* `[std::option](../option/index)::[Option](../option/enum.option "Option")::{[self](../option/enum.option "Option"), [Some](../option/enum.option#variant.Some "Some"), [None](../option/enum.option#variant.None "None")}`, a type which expresses the presence or absence of a value. This type is so commonly used, its variants are also exported.
* `[std::result](../result/index)::[Result](../result/enum.result "Result")::{[self](../result/enum.result "Result"), [Ok](../result/enum.result#variant.Ok "Ok"), [Err](../result/enum.result#variant.Err "Err")}`, a type for functions that may succeed or fail. Like [`Option`](../option/enum.option "Option"), its variants are exported as well.
* `[std::string](../string/index)::{[String](../string/struct.string "String"), [ToString](../string/trait.tostring "ToString")}`, heap-allocated strings.
* `[std::vec](../vec/index)::[Vec](../vec/struct.vec "Vec")`, a growable, heap-allocated vector.
The prelude used in Rust 2021, [`std::prelude::rust_2021`](rust_2021/index), includes all of the above, and in addition re-exports:
* `[std::convert](../convert/index)::{[TryFrom](../convert/trait.tryfrom), [TryInto](../convert/trait.tryinto)}`,
* `[std::iter](../iter/index)::[FromIterator](../iter/trait.fromiterator)`.
Modules
-------
[rust\_2024](rust_2024/index "std::prelude::rust_2024 mod")Experimental
The 2024 version of the prelude of The Rust Standard Library.
[rust\_2015](rust_2015/index "std::prelude::rust_2015 mod")
The 2015 version of the prelude of The Rust Standard Library.
[rust\_2018](rust_2018/index "std::prelude::rust_2018 mod")
The 2018 version of the prelude of The Rust Standard Library.
[rust\_2021](rust_2021/index "std::prelude::rust_2021 mod")
The 2021 version of the prelude of The Rust Standard Library.
[v1](v1/index "std::prelude::v1 mod")
The first version of the prelude of The Rust Standard Library.
rust Macro std::prelude::v1::cfg_accessible Macro std::prelude::v1::cfg\_accessible
=======================================
```
pub macro cfg_accessible($item:item) {
...
}
```
🔬This is a nightly-only experimental API. (`cfg_accessible` [#64797](https://github.com/rust-lang/rust/issues/64797))
Keeps the item it’s applied to if the passed path is accessible, and removes it otherwise.
rust Macro std::prelude::v1::test Macro std::prelude::v1::test
============================
```
pub macro test($item:item) {
...
}
```
Attribute macro applied to a function to turn it into a unit test.
See [the reference](../../../reference/attributes/testing#the-test-attribute) for more info.
rust Module std::prelude::v1 Module std::prelude::v1
=======================
The first version of the prelude of The Rust Standard Library.
See the [module-level documentation](../index) for more.
Re-exports
----------
`pub use core::prelude::v1::[concat\_bytes](../../macro.concat_bytes "macro std::concat_bytes");`
Experimental
`pub use crate::marker::[Send](../../marker/trait.send "trait std::marker::Send");`
`pub use crate::marker::[Sized](../../marker/trait.sized "trait std::marker::Sized");`
`pub use crate::marker::[Sync](../../marker/trait.sync "trait std::marker::Sync");`
`pub use crate::marker::[Unpin](../../marker/trait.unpin "trait std::marker::Unpin");`
`pub use crate::ops::[Drop](../../ops/trait.drop "trait std::ops::Drop");`
`pub use crate::ops::[Fn](../../ops/trait.fn "trait std::ops::Fn");`
`pub use crate::ops::[FnMut](../../ops/trait.fnmut "trait std::ops::FnMut");`
`pub use crate::ops::[FnOnce](../../ops/trait.fnonce "trait std::ops::FnOnce");`
`pub use crate::mem::[drop](../../mem/fn.drop "fn std::mem::drop");`
`pub use crate::convert::[AsMut](../../convert/trait.asmut "trait std::convert::AsMut");`
`pub use crate::convert::[AsRef](../../convert/trait.asref "trait std::convert::AsRef");`
`pub use crate::convert::[From](../../convert/trait.from "trait std::convert::From");`
`pub use crate::convert::[Into](../../convert/trait.into "trait std::convert::Into");`
`pub use crate::iter::[DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator");`
`pub use crate::iter::[ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator");`
`pub use crate::iter::[Extend](../../iter/trait.extend "trait std::iter::Extend");`
`pub use crate::iter::[IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator");`
`pub use crate::iter::[Iterator](../../iter/trait.iterator "trait std::iter::Iterator");`
`pub use crate::option::[Option](../../option/enum.option "enum std::option::Option");`
`pub use crate::option::Option::[None](../../option/enum.option "enum std::option::Option");`
`pub use crate::option::Option::[Some](../../option/enum.option "enum std::option::Option");`
`pub use crate::result::[Result](../../result/enum.result "enum std::result::Result");`
`pub use crate::result::Result::[Err](../../result/enum.result "enum std::result::Result");`
`pub use crate::result::Result::[Ok](../../result/enum.result "enum std::result::Result");`
`pub use core::prelude::v1::[assert](../../macro.assert "macro std::assert");`
`pub use core::prelude::v1::[cfg](../../macro.cfg "macro std::cfg");`
`pub use core::prelude::v1::[column](../../macro.column "macro std::column");`
`pub use core::prelude::v1::[compile\_error](../../macro.compile_error "macro std::compile_error");`
`pub use core::prelude::v1::[concat](../../macro.concat "macro std::concat");`
`pub use core::prelude::v1::[concat\_idents](../../macro.concat_idents "macro std::concat_idents");`
Experimental
`pub use core::prelude::v1::[env](../../macro.env "macro std::env");`
`pub use core::prelude::v1::[file](../../macro.file "macro std::file");`
`pub use core::prelude::v1::[format\_args](../../macro.format_args "macro std::format_args");`
`pub use core::prelude::v1::[format\_args\_nl](../../macro.format_args_nl "macro std::format_args_nl");`
Experimental
`pub use core::prelude::v1::[include](../../macro.include "macro std::include");`
`pub use core::prelude::v1::[include\_bytes](../../macro.include_bytes "macro std::include_bytes");`
`pub use core::prelude::v1::[include\_str](../../macro.include_str "macro std::include_str");`
`pub use core::prelude::v1::[line](../../macro.line "macro std::line");`
`pub use core::prelude::v1::[log\_syntax](../../macro.log_syntax "macro std::log_syntax");`
Experimental
`pub use core::prelude::v1::[module\_path](../../macro.module_path "macro std::module_path");`
`pub use core::prelude::v1::[option\_env](../../macro.option_env "macro std::option_env");`
`pub use core::prelude::v1::[stringify](../../macro.stringify "macro std::stringify");`
`pub use core::prelude::v1::[trace\_macros](../../macro.trace_macros "macro std::trace_macros");`
Experimental
`pub use core::prelude::v1::[Clone](../../clone/trait.clone "trait std::clone::Clone");`
`pub use core::prelude::v1::[Clone](../../clone/macro.clone "macro std::clone::Clone");`
`pub use core::prelude::v1::[Copy](../../marker/trait.copy "trait std::marker::Copy");`
`pub use core::prelude::v1::[Copy](../../marker/macro.copy "macro std::marker::Copy");`
`pub use core::prelude::v1::[Debug](../../fmt/macro.debug "macro std::fmt::Debug");`
`pub use core::prelude::v1::[Default](../../default/trait.default "trait std::default::Default");`
`pub use core::prelude::v1::[Default](../../default/macro.default "macro std::default::Default");`
`pub use core::prelude::v1::[Eq](../../cmp/trait.eq "trait std::cmp::Eq");`
`pub use core::prelude::v1::[Eq](../../cmp/macro.eq "macro std::cmp::Eq");`
`pub use core::prelude::v1::[Hash](../../hash/macro.hash "macro std::hash::Hash");`
`pub use core::prelude::v1::[Ord](../../cmp/trait.ord "trait std::cmp::Ord");`
`pub use core::prelude::v1::[Ord](../../cmp/macro.ord "macro std::cmp::Ord");`
`pub use core::prelude::v1::[PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq");`
`pub use core::prelude::v1::[PartialEq](../../cmp/macro.partialeq "macro std::cmp::PartialEq");`
`pub use core::prelude::v1::[PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd");`
`pub use core::prelude::v1::[PartialOrd](../../cmp/macro.partialord "macro std::cmp::PartialOrd");`
`pub use crate::borrow::[ToOwned](../../borrow/trait.toowned "trait std::borrow::ToOwned");`
`pub use crate::boxed::[Box](../../boxed/struct.box "struct std::boxed::Box");`
`pub use crate::string::[String](../../string/struct.string "struct std::string::String");`
`pub use crate::string::[ToString](../../string/trait.tostring "trait std::string::ToString");`
`pub use crate::vec::[Vec](../../vec/struct.vec "struct std::vec::Vec");`
Macros
------
[bench](macro.bench "std::prelude::v1::bench macro")Experimental
Attribute macro applied to a function to turn it into a benchmark test.
[cfg\_accessible](macro.cfg_accessible "std::prelude::v1::cfg_accessible macro")Experimental
Keeps the item it’s applied to if the passed path is accessible, and removes it otherwise.
[cfg\_eval](macro.cfg_eval "std::prelude::v1::cfg_eval macro")Experimental
Expands all `#[cfg]` and `#[cfg_attr]` attributes in the code fragment it’s applied to.
[test\_case](macro.test_case "std::prelude::v1::test_case macro")Experimental
An implementation detail of the `#[test]` and `#[bench]` macros.
[derive](macro.derive "std::prelude::v1::derive macro")
Attribute macro used to apply derive macros.
[global\_allocator](macro.global_allocator "std::prelude::v1::global_allocator macro")
Attribute macro applied to a static to register it as a global allocator.
[test](macro.test "std::prelude::v1::test macro")
Attribute macro applied to a function to turn it into a unit test.
rust Macro std::prelude::v1::test_case Macro std::prelude::v1::test\_case
==================================
```
pub macro test_case($item:item) {
...
}
```
🔬This is a nightly-only experimental API. (`custom_test_frameworks` [#50297](https://github.com/rust-lang/rust/issues/50297))
An implementation detail of the `#[test]` and `#[bench]` macros.
rust Macro std::prelude::v1::global_allocator Macro std::prelude::v1::global\_allocator
=========================================
```
pub macro global_allocator($item:item) {
...
}
```
Attribute macro applied to a static to register it as a global allocator.
See also [`std::alloc::GlobalAlloc`](../../alloc/trait.globalalloc).
rust Macro std::prelude::v1::derive Macro std::prelude::v1::derive
==============================
```
pub macro derive($item:item) {
...
}
```
Attribute macro used to apply derive macros.
See [the reference](../../../reference/attributes/derive) for more info.
rust Macro std::prelude::v1::bench Macro std::prelude::v1::bench
=============================
```
pub macro bench($item:item) {
...
}
```
🔬This is a nightly-only experimental API. (`test` [#50297](https://github.com/rust-lang/rust/issues/50297))
Attribute macro applied to a function to turn it into a benchmark test.
rust Macro std::prelude::v1::cfg_eval Macro std::prelude::v1::cfg\_eval
=================================
```
pub macro cfg_eval($($tt:tt)*) {
...
}
```
🔬This is a nightly-only experimental API. (`cfg_eval` [#82679](https://github.com/rust-lang/rust/issues/82679))
Expands all `#[cfg]` and `#[cfg_attr]` attributes in the code fragment it’s applied to.
rust Module std::prelude::rust_2024 Module std::prelude::rust\_2024
===============================
🔬This is a nightly-only experimental API. (`prelude_2024`)
The 2024 version of the prelude of The Rust Standard Library.
See the [module-level documentation](../index) for more.
Re-exports
----------
`pub use super::[v1](../v1/index "mod std::prelude::v1")::*;`
`pub use core::prelude::[rust\_2024](https://doc.rust-lang.org/core/prelude/rust_2024/index.html "mod core::prelude::rust_2024")::*;`
Experimental
rust Module std::prelude::rust_2015 Module std::prelude::rust\_2015
===============================
The 2015 version of the prelude of The Rust Standard Library.
See the [module-level documentation](../index) for more.
Re-exports
----------
`pub use super::[v1](../v1/index "mod std::prelude::v1")::*;`
rust Module std::prelude::rust_2021 Module std::prelude::rust\_2021
===============================
The 2021 version of the prelude of The Rust Standard Library.
See the [module-level documentation](../index) for more.
Re-exports
----------
`pub use super::[v1](../v1/index "mod std::prelude::v1")::*;`
`pub use core::prelude::[rust\_2021](https://doc.rust-lang.org/core/prelude/rust_2021/index.html "mod core::prelude::rust_2021")::*;`
rust Module std::prelude::rust_2018 Module std::prelude::rust\_2018
===============================
The 2018 version of the prelude of The Rust Standard Library.
See the [module-level documentation](../index) for more.
Re-exports
----------
`pub use super::[v1](../v1/index "mod std::prelude::v1")::*;`
rust Trait std::marker::StructuralEq Trait std::marker::StructuralEq
===============================
```
pub trait StructuralEq { }
```
🔬This is a nightly-only experimental API. (`structural_match` [#31434](https://github.com/rust-lang/rust/issues/31434))
Required trait for constants used in pattern matches.
Any type that derives `Eq` automatically implements this trait, *regardless* of whether its type parameters implement `Eq`.
This is a hack to work around a limitation in our type system.
Background
----------
We want to require that types of consts used in pattern matches have the attribute `#[derive(PartialEq, Eq)]`.
In a more ideal world, we could check that requirement by just checking that the given type implements both the `StructuralPartialEq` trait *and* the `Eq` trait. However, you can have ADTs that *do* `derive(PartialEq, Eq)`, and be a case that we want the compiler to accept, and yet the constant’s type fails to implement `Eq`.
Namely, a case like this:
```
#[derive(PartialEq, Eq)]
struct Wrap<X>(X);
fn higher_order(_: &()) { }
const CFN: Wrap<fn(&())> = Wrap(higher_order);
fn main() {
match CFN {
CFN => {}
_ => {}
}
}
```
(The problem in the above code is that `Wrap<fn(&())>` does not implement `PartialEq`, nor `Eq`, because `for<'a> fn(&'a _)` does not implement those traits.)
Therefore, we cannot rely on naive check for `StructuralPartialEq` and mere `Eq`.
As a hack to work around this, we use two separate traits injected by each of the two derives (`#[derive(PartialEq)]` and `#[derive(Eq)]`) and check that both of them are present as part of structural-match checking.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/backtrace.rs.html#117)1.65.0 · ### impl StructuralEq for BacktraceStatus
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#342)1.0.0 · ### impl StructuralEq for std::cmp::Ordering
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl StructuralEq for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/std/env.rs.html#280)1.0.0 · ### impl StructuralEq for VarError
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#25)1.28.0 · ### impl StructuralEq for Alignment
[source](https://doc.rust-lang.org/src/std/io/error.rs.html#166)1.0.0 · ### impl StructuralEq for ErrorKind
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1881)1.0.0 · ### impl StructuralEq for SeekFrom
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#34)1.7.0 · ### impl StructuralEq for IpAddr
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#200)### impl StructuralEq for Ipv6MulticastScope
[source](https://doc.rust-lang.org/src/std/net/mod.rs.html#49)1.0.0 · ### impl StructuralEq for Shutdown
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#42)1.0.0 · ### impl StructuralEq for SocketAddr
[source](https://doc.rust-lang.org/src/core/num/mod.rs.html#954)1.0.0 · ### impl StructuralEq for FpCategory
[source](https://doc.rust-lang.org/src/core/num/error.rs.html#87)1.55.0 · ### impl StructuralEq for IntErrorKind
[source](https://doc.rust-lang.org/src/std/panic.rs.html#208)### impl StructuralEq for BacktraceStyle
[source](https://doc.rust-lang.org/src/core/up/up/portable-simd/crates/core_simd/src/swizzle.rs.html#76)### impl StructuralEq for Which
[source](https://doc.rust-lang.org/src/core/str/pattern.rs.html#167)### impl StructuralEq for SearchStep
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)1.0.0 · ### impl StructuralEq for std::sync::atomic::Ordering
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)1.12.0 · ### impl StructuralEq for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)1.0.0 · ### impl StructuralEq for TryRecvError
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/cpuid.rs.html#11)1.27.0 · ### impl StructuralEq for CpuidResult
[source](https://doc.rust-lang.org/src/core/ffi/c_str.rs.html#149)### impl StructuralEq for FromBytesUntilNulError
[source](https://doc.rust-lang.org/src/core/alloc/mod.rs.html#34)### impl StructuralEq for AllocError
[source](https://doc.rust-lang.org/src/core/alloc/layout.rs.html#37)1.28.0 · ### impl StructuralEq for Layout
[source](https://doc.rust-lang.org/src/core/alloc/layout.rs.html#463)1.50.0 · ### impl StructuralEq for LayoutError
[source](https://doc.rust-lang.org/src/core/any.rs.html#665)1.0.0 · ### impl StructuralEq for TypeId
[source](https://doc.rust-lang.org/src/core/char/convert.rs.html#235)1.34.0 · ### impl StructuralEq for CharTryFromError
[source](https://doc.rust-lang.org/src/core/char/decode.rs.html#29)1.9.0 · ### impl StructuralEq for DecodeUtf16Error
[source](https://doc.rust-lang.org/src/core/char/convert.rs.html#149)1.20.0 · ### impl StructuralEq for ParseCharError
[source](https://doc.rust-lang.org/src/core/char/mod.rs.html#580)1.59.0 · ### impl StructuralEq for TryFromCharError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)1.57.0 · ### impl StructuralEq for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#109)1.64.0 · ### impl StructuralEq for CString
[source](https://doc.rust-lang.org/src/core/ffi/c_str.rs.html#110)1.64.0 · ### impl StructuralEq for FromBytesWithNulError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#159)1.64.0 · ### impl StructuralEq for FromVecWithNulError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#225)1.64.0 · ### impl StructuralEq for IntoStringError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#134)1.64.0 · ### impl StructuralEq for NulError
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#98)1.0.0 · ### impl StructuralEq for Error
[source](https://doc.rust-lang.org/src/std/fs.rs.html#207)1.1.0 · ### impl StructuralEq for FileType
[source](https://doc.rust-lang.org/src/std/fs.rs.html#200)1.0.0 · ### impl StructuralEq for Permissions
[source](https://doc.rust-lang.org/src/core/mem/transmutability.rs.html#21)### impl StructuralEq for Assume
[source](https://doc.rust-lang.org/src/std/net/parser.rs.html#476)1.0.0 · ### impl StructuralEq for AddrParseError
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#75)1.0.0 · ### impl StructuralEq for Ipv4Addr
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#158)1.0.0 · ### impl StructuralEq for Ipv6Addr
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#78)1.0.0 · ### impl StructuralEq for SocketAddrV4
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#111)1.0.0 · ### impl StructuralEq for SocketAddrV6
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralEq for NonZeroI8
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralEq for NonZeroI16
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralEq for NonZeroI32
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralEq for NonZeroI64
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralEq for NonZeroI128
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralEq for NonZeroIsize
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralEq for NonZeroU8
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralEq for NonZeroU16
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralEq for NonZeroU32
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralEq for NonZeroU64
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralEq for NonZeroU128
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralEq for NonZeroUsize
[source](https://doc.rust-lang.org/src/core/num/dec2flt/mod.rs.html#173)1.0.0 · ### impl StructuralEq for ParseFloatError
[source](https://doc.rust-lang.org/src/core/num/error.rs.html#69)1.0.0 · ### impl StructuralEq for ParseIntError
[source](https://doc.rust-lang.org/src/core/num/error.rs.html#10)1.34.0 · ### impl StructuralEq for TryFromIntError
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#41)1.0.0 · ### impl StructuralEq for RangeFull
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl StructuralEq for UCred
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)1.63.0 · ### impl StructuralEq for InvalidHandleError
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)1.63.0 · ### impl StructuralEq for NullHandleError
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/path.rs.html#1937)1.7.0 · ### impl StructuralEq for StripPrefixError
[source](https://doc.rust-lang.org/src/std/process.rs.html#1452)1.0.0 · ### impl StructuralEq for ExitStatus
[source](https://doc.rust-lang.org/src/std/process.rs.html#1585)### impl StructuralEq for ExitStatusError
[source](https://doc.rust-lang.org/src/std/process.rs.html#1096)1.0.0 · ### impl StructuralEq for Output
[source](https://doc.rust-lang.org/src/core/str/error.rs.html#139)1.0.0 · ### impl StructuralEq for ParseBoolError
[source](https://doc.rust-lang.org/src/core/str/error.rs.html#46)1.0.0 · ### impl StructuralEq for Utf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)1.0.0 · ### impl StructuralEq for FromUtf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#365)1.0.0 · ### impl StructuralEq for String
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)1.0.0 · ### impl StructuralEq for RecvError
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)1.5.0 · ### impl StructuralEq for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/std/thread/local.rs.html#372)1.26.0 · ### impl StructuralEq for AccessError
[source](https://doc.rust-lang.org/src/std/thread/mod.rs.html#1039)1.19.0 · ### impl StructuralEq for ThreadId
[source](https://doc.rust-lang.org/src/core/time.rs.html#70)1.3.0 · ### impl StructuralEq for Duration
[source](https://doc.rust-lang.org/src/core/time.rs.html#1210)### impl StructuralEq for FromFloatSecsError
[source](https://doc.rust-lang.org/src/std/time.rs.html#152)1.8.0 · ### impl StructuralEq for Instant
[source](https://doc.rust-lang.org/src/std/time.rs.html#237)1.8.0 · ### impl StructuralEq for SystemTime
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)1.33.0 · ### impl StructuralEq for PhantomPinned
[source](https://doc.rust-lang.org/src/std/path.rs.html#505)1.0.0 · ### impl<'a> StructuralEq for Component<'a>
[source](https://doc.rust-lang.org/src/std/path.rs.html#141)1.0.0 · ### impl<'a> StructuralEq for Prefix<'a>
[source](https://doc.rust-lang.org/src/core/panic/location.rs.html#31)1.10.0 · ### impl<'a> StructuralEq for Location<'a>
[source](https://doc.rust-lang.org/src/std/path.rs.html#422)1.0.0 · ### impl<'a> StructuralEq for PrefixComponent<'a>
[source](https://doc.rust-lang.org/src/core/str/lossy.rs.html#34)### impl<'a> StructuralEq for Utf8Chunk<'a>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#78)1.0.0 · ### impl<Idx> StructuralEq for Range<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#185)1.0.0 · ### impl<Idx> StructuralEq for RangeFrom<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#339)1.26.0 · ### impl<Idx> StructuralEq for RangeInclusive<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#266)1.0.0 · ### impl<Idx> StructuralEq for RangeTo<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#584)1.26.0 · ### impl<Idx> StructuralEq for RangeToInclusive<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#664)1.17.0 · ### impl<T> StructuralEq for Bound<T>
[source](https://doc.rust-lang.org/src/core/option.rs.html#515)1.0.0 · ### impl<T> StructuralEq for Option<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)1.0.0 · ### impl<T> StructuralEq for TrySendError<T>
[source](https://doc.rust-lang.org/src/core/task/poll.rs.html#11)1.36.0 · ### impl<T> StructuralEq for Poll<T>
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#606)1.19.0 · ### impl<T> StructuralEq for Reverse<T>
[source](https://doc.rust-lang.org/src/std/io/cursor.rs.html#73)1.0.0 · ### impl<T> StructuralEq for Cursor<T>
[source](https://doc.rust-lang.org/src/core/mem/manually_drop.rs.html#48)1.20.0 · ### impl<T> StructuralEq for ManuallyDrop<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/num/saturating.rs.html#36)### impl<T> StructuralEq for Saturating<T>
[source](https://doc.rust-lang.org/src/core/num/wrapping.rs.html#40)1.0.0 · ### impl<T> StructuralEq for Wrapping<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)1.0.0 · ### impl<T> StructuralEq for SendError<T>
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> StructuralEq for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/result.rs.html#500)1.0.0 · ### impl<T, E> StructuralEq for Result<T, E>
[source](https://doc.rust-lang.org/src/core/ops/generator.rs.html#9)### impl<Y, R> StructuralEq for GeneratorState<Y, R>
| programming_docs |
rust Module std::marker Module std::marker
==================
Primitive traits and types representing basic properties of types.
Rust types can be classified in various useful ways according to their intrinsic properties. These classifications are represented as traits.
Macros
------
[Copy](macro.copy "std::marker::Copy macro")
Derive macro generating an impl of the trait `Copy`.
Structs
-------
[PhantomData](struct.phantomdata "std::marker::PhantomData struct")
Zero-sized type used to mark things that “act like” they own a `T`.
[PhantomPinned](struct.phantompinned "std::marker::PhantomPinned struct")
A marker type which does not implement `Unpin`.
Traits
------
[Destruct](trait.destruct "std::marker::Destruct trait")Experimental
A marker for types that can be dropped.
[DiscriminantKind](trait.discriminantkind "std::marker::DiscriminantKind trait")Experimental
Compiler-internal trait used to indicate the type of enum discriminants.
[StructuralEq](trait.structuraleq "std::marker::StructuralEq trait")Experimental
Required trait for constants used in pattern matches.
[StructuralPartialEq](trait.structuralpartialeq "std::marker::StructuralPartialEq trait")Experimental
Required trait for constants used in pattern matches.
[Tuple](trait.tuple "std::marker::Tuple trait")Experimental
A marker for tuple types.
[Unsize](trait.unsize "std::marker::Unsize trait")Experimental
Types that can be “unsized” to a dynamically-sized type.
[Copy](trait.copy "std::marker::Copy trait")
Types whose values can be duplicated simply by copying bits.
[Send](trait.send "std::marker::Send trait")
Types that can be transferred across thread boundaries.
[Sized](trait.sized "std::marker::Sized trait")
Types with a constant size known at compile time.
[Sync](trait.sync "std::marker::Sync trait")
Types for which it is safe to share references between threads.
[Unpin](trait.unpin "std::marker::Unpin trait")
Types that can be safely moved after being pinned.
rust Macro std::marker::Copy Macro std::marker::Copy
=======================
```
pub macro Copy($item:item) {
...
}
```
Derive macro generating an impl of the trait `Copy`.
rust Trait std::marker::Tuple Trait std::marker::Tuple
========================
```
pub trait Tuple { }
```
🔬This is a nightly-only experimental API. (`tuple_trait`)
A marker for tuple types.
The implementation of this trait is built-in and cannot be implemented for any user type.
Implementors
------------
rust Trait std::marker::DiscriminantKind Trait std::marker::DiscriminantKind
===================================
```
pub trait DiscriminantKind {
type Discriminant: Clone + Copy + Debug + Eq + PartialEq<Self::Discriminant> + Hash + Send + Sync + Unpin;
}
```
🔬This is a nightly-only experimental API. (`discriminant_kind`)
Compiler-internal trait used to indicate the type of enum discriminants.
This trait is automatically implemented for every type and does not add any guarantees to [`mem::Discriminant`](../mem/struct.discriminant). It is **undefined behavior** to transmute between `DiscriminantKind::Discriminant` and `mem::Discriminant`.
Required Associated Types
-------------------------
[source](https://doc.rust-lang.org/src/core/marker.rs.html#706)#### type Discriminant: Clone + Copy + Debug + Eq + PartialEq<Self::Discriminant> + Hash + Send + Sync + Unpin
🔬This is a nightly-only experimental API. (`discriminant_kind`)
The type of the discriminant, which must satisfy the trait bounds required by `mem::Discriminant`.
Implementors
------------
rust Trait std::marker::Unsize Trait std::marker::Unsize
=========================
```
pub trait Unsize<T>where T: ?Sized,{ }
```
🔬This is a nightly-only experimental API. (`unsize` [#27732](https://github.com/rust-lang/rust/issues/27732))
Types that can be “unsized” to a dynamically-sized type.
For example, the sized array type `[i8; 2]` implements `Unsize<[i8]>` and `Unsize<dyn fmt::Debug>`.
All implementations of `Unsize` are provided automatically by the compiler. Those implementations are:
* Arrays `[T; N]` implement `Unsize<[T]>`.
* Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`.
* Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions are met:
+ `T: Unsize<U>`.
+ Only the last field of `Foo` has a type involving `T`.
+ `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field.
`Unsize` is used along with [`ops::CoerceUnsized`](../ops/trait.coerceunsized) to allow “user-defined” containers such as [`Rc`](../rc/struct.rc) to contain dynamically-sized types. See the [DST coercion RFC](https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md) and [the nomicon entry on coercion](https://doc.rust-lang.org/nomicon/coercions.html) for more details.
Implementors
------------
rust Trait std::marker::StructuralPartialEq Trait std::marker::StructuralPartialEq
======================================
```
pub trait StructuralPartialEq { }
```
🔬This is a nightly-only experimental API. (`structural_match` [#31434](https://github.com/rust-lang/rust/issues/31434))
Required trait for constants used in pattern matches.
Any type that derives `PartialEq` automatically implements this trait, *regardless* of whether its type-parameters implement `Eq`.
If a `const` item contains some type that does not implement this trait, then that type either (1.) does not implement `PartialEq` (which means the constant will not provide that comparison method, which code generation assumes is available), or (2.) it implements *its own* version of `PartialEq` (which we assume does not conform to a structural-equality comparison).
In either of the two scenarios above, we reject usage of such a constant in a pattern match.
See also the [structural match RFC](https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md), and [issue 63438](https://github.com/rust-lang/rust/issues/63438) which motivated migrating from attribute-based design to this trait.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/backtrace.rs.html#117)1.65.0 · ### impl StructuralPartialEq for BacktraceStatus
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#889)1.0.0 · ### impl StructuralPartialEq for std::cmp::Ordering
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl StructuralPartialEq for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/std/env.rs.html#280)1.0.0 · ### impl StructuralPartialEq for VarError
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#25)1.28.0 · ### impl StructuralPartialEq for Alignment
[source](https://doc.rust-lang.org/src/std/io/error.rs.html#166)1.0.0 · ### impl StructuralPartialEq for ErrorKind
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1881)1.0.0 · ### impl StructuralPartialEq for SeekFrom
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#34)1.7.0 · ### impl StructuralPartialEq for IpAddr
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#200)### impl StructuralPartialEq for Ipv6MulticastScope
[source](https://doc.rust-lang.org/src/std/net/mod.rs.html#49)1.0.0 · ### impl StructuralPartialEq for Shutdown
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#42)1.0.0 · ### impl StructuralPartialEq for SocketAddr
[source](https://doc.rust-lang.org/src/core/num/mod.rs.html#954)1.0.0 · ### impl StructuralPartialEq for FpCategory
[source](https://doc.rust-lang.org/src/core/num/error.rs.html#87)1.55.0 · ### impl StructuralPartialEq for IntErrorKind
[source](https://doc.rust-lang.org/src/std/panic.rs.html#208)### impl StructuralPartialEq for BacktraceStyle
[source](https://doc.rust-lang.org/src/core/up/up/portable-simd/crates/core_simd/src/swizzle.rs.html#76)### impl StructuralPartialEq for Which
[source](https://doc.rust-lang.org/src/core/str/pattern.rs.html#167)### impl StructuralPartialEq for SearchStep
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)1.0.0 · ### impl StructuralPartialEq for std::sync::atomic::Ordering
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)1.12.0 · ### impl StructuralPartialEq for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)1.0.0 · ### impl StructuralPartialEq for TryRecvError
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/cpuid.rs.html#11)1.27.0 · ### impl StructuralPartialEq for CpuidResult
[source](https://doc.rust-lang.org/src/core/ffi/c_str.rs.html#149)### impl StructuralPartialEq for FromBytesUntilNulError
[source](https://doc.rust-lang.org/src/core/alloc/mod.rs.html#34)### impl StructuralPartialEq for AllocError
[source](https://doc.rust-lang.org/src/core/alloc/layout.rs.html#37)1.28.0 · ### impl StructuralPartialEq for Layout
[source](https://doc.rust-lang.org/src/core/alloc/layout.rs.html#463)1.50.0 · ### impl StructuralPartialEq for LayoutError
[source](https://doc.rust-lang.org/src/core/any.rs.html#665)1.0.0 · ### impl StructuralPartialEq for TypeId
[source](https://doc.rust-lang.org/src/core/char/convert.rs.html#235)1.34.0 · ### impl StructuralPartialEq for CharTryFromError
[source](https://doc.rust-lang.org/src/core/char/decode.rs.html#29)1.9.0 · ### impl StructuralPartialEq for DecodeUtf16Error
[source](https://doc.rust-lang.org/src/core/char/convert.rs.html#149)1.20.0 · ### impl StructuralPartialEq for ParseCharError
[source](https://doc.rust-lang.org/src/core/char/mod.rs.html#580)1.59.0 · ### impl StructuralPartialEq for TryFromCharError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)1.57.0 · ### impl StructuralPartialEq for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#109)1.64.0 · ### impl StructuralPartialEq for CString
[source](https://doc.rust-lang.org/src/core/ffi/c_str.rs.html#110)1.64.0 · ### impl StructuralPartialEq for FromBytesWithNulError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#159)1.64.0 · ### impl StructuralPartialEq for FromVecWithNulError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#225)1.64.0 · ### impl StructuralPartialEq for IntoStringError
[source](https://doc.rust-lang.org/src/alloc/ffi/c_str.rs.html#134)1.64.0 · ### impl StructuralPartialEq for NulError
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#98)1.0.0 · ### impl StructuralPartialEq for Error
[source](https://doc.rust-lang.org/src/std/fs.rs.html#207)1.1.0 · ### impl StructuralPartialEq for FileType
[source](https://doc.rust-lang.org/src/std/fs.rs.html#200)1.0.0 · ### impl StructuralPartialEq for Permissions
[source](https://doc.rust-lang.org/src/core/mem/transmutability.rs.html#21)### impl StructuralPartialEq for Assume
[source](https://doc.rust-lang.org/src/std/net/parser.rs.html#476)1.0.0 · ### impl StructuralPartialEq for AddrParseError
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#75)1.0.0 · ### impl StructuralPartialEq for Ipv4Addr
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#158)1.0.0 · ### impl StructuralPartialEq for Ipv6Addr
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#78)1.0.0 · ### impl StructuralPartialEq for SocketAddrV4
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#111)1.0.0 · ### impl StructuralPartialEq for SocketAddrV6
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralPartialEq for NonZeroI8
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralPartialEq for NonZeroI16
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralPartialEq for NonZeroI32
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralPartialEq for NonZeroI64
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralPartialEq for NonZeroI128
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl StructuralPartialEq for NonZeroIsize
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralPartialEq for NonZeroU8
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralPartialEq for NonZeroU16
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralPartialEq for NonZeroU32
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralPartialEq for NonZeroU64
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralPartialEq for NonZeroU128
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl StructuralPartialEq for NonZeroUsize
[source](https://doc.rust-lang.org/src/core/num/dec2flt/mod.rs.html#173)1.0.0 · ### impl StructuralPartialEq for ParseFloatError
[source](https://doc.rust-lang.org/src/core/num/error.rs.html#69)1.0.0 · ### impl StructuralPartialEq for ParseIntError
[source](https://doc.rust-lang.org/src/core/num/error.rs.html#10)1.34.0 · ### impl StructuralPartialEq for TryFromIntError
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#41)1.0.0 · ### impl StructuralPartialEq for RangeFull
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl StructuralPartialEq for UCred
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#270)1.63.0 · ### impl StructuralPartialEq for InvalidHandleError
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#252)1.63.0 · ### impl StructuralPartialEq for NullHandleError
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/path.rs.html#1937)1.7.0 · ### impl StructuralPartialEq for StripPrefixError
[source](https://doc.rust-lang.org/src/std/process.rs.html#1452)1.0.0 · ### impl StructuralPartialEq for ExitStatus
[source](https://doc.rust-lang.org/src/std/process.rs.html#1585)### impl StructuralPartialEq for ExitStatusError
[source](https://doc.rust-lang.org/src/std/process.rs.html#1096)1.0.0 · ### impl StructuralPartialEq for Output
[source](https://doc.rust-lang.org/src/core/str/error.rs.html#139)1.0.0 · ### impl StructuralPartialEq for ParseBoolError
[source](https://doc.rust-lang.org/src/core/str/error.rs.html#46)1.0.0 · ### impl StructuralPartialEq for Utf8Error
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#407)1.0.0 · ### impl StructuralPartialEq for FromUtf8Error
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)1.0.0 · ### impl StructuralPartialEq for RecvError
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)1.5.0 · ### impl StructuralPartialEq for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/core/task/wake.rs.html#13)1.36.0 · ### impl StructuralPartialEq for RawWaker
[source](https://doc.rust-lang.org/src/core/task/wake.rs.html#81)1.36.0 · ### impl StructuralPartialEq for RawWakerVTable
[source](https://doc.rust-lang.org/src/std/thread/local.rs.html#372)1.26.0 · ### impl StructuralPartialEq for AccessError
[source](https://doc.rust-lang.org/src/std/thread/mod.rs.html#1039)1.19.0 · ### impl StructuralPartialEq for ThreadId
[source](https://doc.rust-lang.org/src/core/time.rs.html#70)1.3.0 · ### impl StructuralPartialEq for Duration
[source](https://doc.rust-lang.org/src/core/time.rs.html#1210)### impl StructuralPartialEq for FromFloatSecsError
[source](https://doc.rust-lang.org/src/std/time.rs.html#152)1.8.0 · ### impl StructuralPartialEq for Instant
[source](https://doc.rust-lang.org/src/std/time.rs.html#237)1.8.0 · ### impl StructuralPartialEq for SystemTime
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)1.33.0 · ### impl StructuralPartialEq for PhantomPinned
[source](https://doc.rust-lang.org/src/std/path.rs.html#505)1.0.0 · ### impl<'a> StructuralPartialEq for Component<'a>
[source](https://doc.rust-lang.org/src/std/path.rs.html#141)1.0.0 · ### impl<'a> StructuralPartialEq for Prefix<'a>
[source](https://doc.rust-lang.org/src/core/panic/location.rs.html#31)1.10.0 · ### impl<'a> StructuralPartialEq for Location<'a>
[source](https://doc.rust-lang.org/src/core/str/lossy.rs.html#34)### impl<'a> StructuralPartialEq for Utf8Chunk<'a>
[source](https://doc.rust-lang.org/src/core/ops/control_flow.rs.html#82)1.55.0 · ### impl<B, C> StructuralPartialEq for ControlFlow<B, C>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#78)1.0.0 · ### impl<Idx> StructuralPartialEq for Range<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#185)1.0.0 · ### impl<Idx> StructuralPartialEq for RangeFrom<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#339)1.26.0 · ### impl<Idx> StructuralPartialEq for RangeInclusive<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#266)1.0.0 · ### impl<Idx> StructuralPartialEq for RangeTo<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#584)1.26.0 · ### impl<Idx> StructuralPartialEq for RangeToInclusive<Idx>
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#664)1.17.0 · ### impl<T> StructuralPartialEq for Bound<T>
[source](https://doc.rust-lang.org/src/core/option.rs.html#515)1.0.0 · ### impl<T> StructuralPartialEq for Option<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)1.0.0 · ### impl<T> StructuralPartialEq for TrySendError<T>
[source](https://doc.rust-lang.org/src/core/task/poll.rs.html#11)1.36.0 · ### impl<T> StructuralPartialEq for Poll<T>
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#606)1.19.0 · ### impl<T> StructuralPartialEq for Reverse<T>
[source](https://doc.rust-lang.org/src/std/io/cursor.rs.html#73)1.0.0 · ### impl<T> StructuralPartialEq for Cursor<T>
[source](https://doc.rust-lang.org/src/core/mem/manually_drop.rs.html#48)1.20.0 · ### impl<T> StructuralPartialEq for ManuallyDrop<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/num/saturating.rs.html#36)### impl<T> StructuralPartialEq for Saturating<T>
[source](https://doc.rust-lang.org/src/core/num/wrapping.rs.html#40)1.0.0 · ### impl<T> StructuralPartialEq for Wrapping<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)1.0.0 · ### impl<T> StructuralPartialEq for SendError<T>
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> StructuralPartialEq for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/result.rs.html#500)1.0.0 · ### impl<T, E> StructuralPartialEq for Result<T, E>
[source](https://doc.rust-lang.org/src/core/ops/generator.rs.html#9)### impl<Y, R> StructuralPartialEq for GeneratorState<Y, R>
rust Trait std::marker::Copy Trait std::marker::Copy
=======================
```
pub trait Copy: Clone { }
```
Types whose values can be duplicated simply by copying bits.
By default, variable bindings have ‘move semantics.’ In other words:
```
#[derive(Debug)]
struct Foo;
let x = Foo;
let y = x;
// `x` has moved into `y`, and so cannot be used
// println!("{x:?}"); // error: use of moved value
```
However, if a type implements `Copy`, it instead has ‘copy semantics’:
```
// We can derive a `Copy` implementation. `Clone` is also required, as it's
// a supertrait of `Copy`.
#[derive(Debug, Copy, Clone)]
struct Foo;
let x = Foo;
let y = x;
// `y` is a copy of `x`
println!("{x:?}"); // A-OK!
```
It’s important to note that in these two examples, the only difference is whether you are allowed to access `x` after the assignment. Under the hood, both a copy and a move can result in bits being copied in memory, although this is sometimes optimized away.
### How can I implement `Copy`?
There are two ways to implement `Copy` on your type. The simplest is to use `derive`:
```
#[derive(Copy, Clone)]
struct MyStruct;
```
You can also implement `Copy` and `Clone` manually:
```
struct MyStruct;
impl Copy for MyStruct { }
impl Clone for MyStruct {
fn clone(&self) -> MyStruct {
*self
}
}
```
There is a small difference between the two: the `derive` strategy will also place a `Copy` bound on type parameters, which isn’t always desired.
### What’s the difference between `Copy` and `Clone`?
Copies happen implicitly, for example as part of an assignment `y = x`. The behavior of `Copy` is not overloadable; it is always a simple bit-wise copy.
Cloning is an explicit action, `x.clone()`. The implementation of [`Clone`](../clone/trait.clone "Clone") can provide any type-specific behavior necessary to duplicate values safely. For example, the implementation of [`Clone`](../clone/trait.clone "Clone") for [`String`](../string/struct.string) needs to copy the pointed-to string buffer in the heap. A simple bitwise copy of [`String`](../string/struct.string) values would merely copy the pointer, leading to a double free down the line. For this reason, [`String`](../string/struct.string) is [`Clone`](../clone/trait.clone "Clone") but not `Copy`.
[`Clone`](../clone/trait.clone "Clone") is a supertrait of `Copy`, so everything which is `Copy` must also implement [`Clone`](../clone/trait.clone "Clone"). If a type is `Copy` then its [`Clone`](../clone/trait.clone "Clone") implementation only needs to return `*self` (see the example above).
### When can my type be `Copy`?
A type can implement `Copy` if all of its components implement `Copy`. For example, this struct can be `Copy`:
```
#[derive(Copy, Clone)]
struct Point {
x: i32,
y: i32,
}
```
A struct can be `Copy`, and [`i32`](../primitive.i32 "i32") is `Copy`, therefore `Point` is eligible to be `Copy`. By contrast, consider
```
struct PointList {
points: Vec<Point>,
}
```
The struct `PointList` cannot implement `Copy`, because [`Vec<T>`](../vec/struct.vec) is not `Copy`. If we attempt to derive a `Copy` implementation, we’ll get an error:
```
the trait `Copy` may not be implemented for this type; field `points` does not implement `Copy`
```
Shared references (`&T`) are also `Copy`, so a type can be `Copy`, even when it holds shared references of types `T` that are *not* `Copy`. Consider the following struct, which can implement `Copy`, because it only holds a *shared reference* to our non-`Copy` type `PointList` from above:
```
#[derive(Copy, Clone)]
struct PointListWrapper<'a> {
point_list_ref: &'a PointList,
}
```
### When *can’t* my type be `Copy`?
Some types can’t be copied safely. For example, copying `&mut T` would create an aliased mutable reference. Copying [`String`](../string/struct.string) would duplicate responsibility for managing the [`String`](../string/struct.string)’s buffer, leading to a double free.
Generalizing the latter case, any type implementing [`Drop`](../ops/trait.drop "Drop") can’t be `Copy`, because it’s managing some resource besides its own [`size_of::<T>`](../mem/fn.size_of) bytes.
If you try to implement `Copy` on a struct or enum containing non-`Copy` data, you will get the error [E0204](https://doc.rust-lang.org/error_codes/E0204.html).
### When *should* my type be `Copy`?
Generally speaking, if your type *can* implement `Copy`, it should. Keep in mind, though, that implementing `Copy` is part of the public API of your type. If the type might become non-`Copy` in the future, it could be prudent to omit the `Copy` implementation now, to avoid a breaking API change.
### Additional implementors
In addition to the [implementors listed below](#implementors), the following types also implement `Copy`:
* Function item types (i.e., the distinct types defined for each function)
* Function pointer types (e.g., `fn() -> i32`)
* Closure types, if they capture no value from the environment or if all such captured values implement `Copy` themselves. Note that variables captured by shared reference always implement `Copy` (even if the referent doesn’t), while variables captured by mutable reference never implement `Copy`.
Implementors
------------
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#342)### impl Copy for std::cmp::Ordering
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#696)1.34.0 · ### impl Copy for Infallible
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#25)1.28.0 · ### impl Copy for Alignment
[source](https://doc.rust-lang.org/src/std/io/error.rs.html#166)### impl Copy for ErrorKind
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1881)### impl Copy for SeekFrom
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#34)1.7.0 · ### impl Copy for IpAddr
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#200)### impl Copy for Ipv6MulticastScope
[source](https://doc.rust-lang.org/src/std/net/mod.rs.html#49)### impl Copy for Shutdown
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#42)### impl Copy for SocketAddr
[source](https://doc.rust-lang.org/src/core/num/mod.rs.html#954)### impl Copy for FpCategory
[source](https://doc.rust-lang.org/src/std/panic.rs.html#208)### impl Copy for BacktraceStyle
[source](https://doc.rust-lang.org/src/core/up/up/portable-simd/crates/core_simd/src/swizzle.rs.html#76)### impl Copy for Which
[source](https://doc.rust-lang.org/src/core/str/pattern.rs.html#167)### impl Copy for SearchStep
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#212)### impl Copy for std::sync::atomic::Ordering
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#611)1.12.0 · ### impl Copy for RecvTimeoutError
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#592)### impl Copy for TryRecvError
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for bool
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for char
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for f32
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for f64
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for i8
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for i16
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for i32
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for i64
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for i128
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for isize
[source](https://doc.rust-lang.org/src/core/marker.rs.html#838)### impl Copy for !
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for u8
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for u16
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for u32
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for u64
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for u128
[source](https://doc.rust-lang.org/src/std/primitive_docs.rs.html#459-461)### impl Copy for ()
[source](https://doc.rust-lang.org/src/core/marker.rs.html#830-835)### impl Copy for usize
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/cpuid.rs.html#11)1.27.0 · ### impl Copy for CpuidResult
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)1.27.0 · ### impl Copy for \_\_m128
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)### impl Copy for \_\_m128bh
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)1.27.0 · ### impl Copy for \_\_m128d
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)1.27.0 · ### impl Copy for \_\_m128i
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)1.27.0 · ### impl Copy for \_\_m256
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)### impl Copy for \_\_m256bh
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)1.27.0 · ### impl Copy for \_\_m256d
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)1.27.0 · ### impl Copy for \_\_m256i
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)### impl Copy for \_\_m512
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)### impl Copy for \_\_m512bh
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)### impl Copy for \_\_m512d
[source](https://doc.rust-lang.org/src/core/up/up/stdarch/crates/core_arch/src/x86/mod.rs.html#8-330)### impl Copy for \_\_m512i
[source](https://doc.rust-lang.org/src/core/alloc/mod.rs.html#34)### impl Copy for AllocError
[source](https://doc.rust-lang.org/src/alloc/alloc.rs.html#53)### impl Copy for Global
[source](https://doc.rust-lang.org/src/core/alloc/layout.rs.html#37)1.28.0 · ### impl Copy for Layout
[source](https://doc.rust-lang.org/src/std/alloc.rs.html#130)1.28.0 · ### impl Copy for System
[source](https://doc.rust-lang.org/src/core/any.rs.html#665)### impl Copy for TypeId
[source](https://doc.rust-lang.org/src/core/array/mod.rs.html#113)1.34.0 · ### impl Copy for TryFromSliceError
[source](https://doc.rust-lang.org/src/core/char/convert.rs.html#235)1.34.0 · ### impl Copy for CharTryFromError
[source](https://doc.rust-lang.org/src/core/char/mod.rs.html#580)1.59.0 · ### impl Copy for TryFromCharError
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#98)### impl Copy for Error
[source](https://doc.rust-lang.org/src/std/fs.rs.html#188)### impl Copy for FileTimes
[source](https://doc.rust-lang.org/src/std/fs.rs.html#207)1.1.0 · ### impl Copy for FileType
[source](https://doc.rust-lang.org/src/std/io/util.rs.html#17)### impl Copy for Empty
[source](https://doc.rust-lang.org/src/std/io/util.rs.html#189)### impl Copy for Sink
[source](https://doc.rust-lang.org/src/core/mem/transmutability.rs.html#21)### impl Copy for Assume
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#75)### impl Copy for Ipv4Addr
[source](https://doc.rust-lang.org/src/std/net/ip_addr.rs.html#158)### impl Copy for Ipv6Addr
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#78)### impl Copy for SocketAddrV4
[source](https://doc.rust-lang.org/src/std/net/socket_addr.rs.html#111)### impl Copy for SocketAddrV6
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl Copy for NonZeroI8
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl Copy for NonZeroI16
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl Copy for NonZeroI32
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl Copy for NonZeroI64
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl Copy for NonZeroI128
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.34.0 · ### impl Copy for NonZeroIsize
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl Copy for NonZeroU8
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl Copy for NonZeroU16
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl Copy for NonZeroU32
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl Copy for NonZeroU64
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl Copy for NonZeroU128
[source](https://doc.rust-lang.org/src/core/num/nonzero.rs.html#161-174)1.28.0 · ### impl Copy for NonZeroUsize
[source](https://doc.rust-lang.org/src/core/num/error.rs.html#10)1.34.0 · ### impl Copy for TryFromIntError
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#41)### impl Copy for RangeFull
[source](https://doc.rust-lang.org/src/std/os/unix/ucred.rs.html#13)### impl Copy for UCred
Available on **Unix** only.[source](https://doc.rust-lang.org/src/std/process.rs.html#1723)1.61.0 · ### impl Copy for ExitCode
[source](https://doc.rust-lang.org/src/std/process.rs.html#1452)### impl Copy for ExitStatus
[source](https://doc.rust-lang.org/src/std/process.rs.html#1585)### impl Copy for ExitStatusError
[source](https://doc.rust-lang.org/src/core/str/error.rs.html#46)### impl Copy for Utf8Error
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#583)### impl Copy for RecvError
[source](https://doc.rust-lang.org/src/std/sync/condvar.rs.html#15)1.5.0 · ### impl Copy for WaitTimeoutResult
[source](https://doc.rust-lang.org/src/core/task/wake.rs.html#81)1.36.0 · ### impl Copy for RawWakerVTable
[source](https://doc.rust-lang.org/src/std/thread/local.rs.html#372)1.26.0 · ### impl Copy for AccessError
[source](https://doc.rust-lang.org/src/std/thread/mod.rs.html#1039)1.19.0 · ### impl Copy for ThreadId
[source](https://doc.rust-lang.org/src/core/time.rs.html#70)1.3.0 · ### impl Copy for Duration
[source](https://doc.rust-lang.org/src/std/time.rs.html#152)1.8.0 · ### impl Copy for Instant
[source](https://doc.rust-lang.org/src/std/time.rs.html#237)1.8.0 · ### impl Copy for SystemTime
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)1.33.0 · ### impl Copy for PhantomPinned
[source](https://doc.rust-lang.org/src/std/path.rs.html#505)### impl<'a> Copy for Component<'a>
[source](https://doc.rust-lang.org/src/std/path.rs.html#141)### impl<'a> Copy for Prefix<'a>
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#473)### impl<'a> Copy for Arguments<'a>
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1203)1.36.0 · ### impl<'a> Copy for IoSlice<'a>
[source](https://doc.rust-lang.org/src/core/panic/location.rs.html#31)1.10.0 · ### impl<'a> Copy for Location<'a>
[source](https://doc.rust-lang.org/src/std/path.rs.html#1086)1.28.0 · ### impl<'a> Copy for Ancestors<'a>
[source](https://doc.rust-lang.org/src/std/path.rs.html#422)### impl<'a> Copy for PrefixComponent<'a>
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#2145)### impl<'a, T, const N: usize> Copy for ArrayWindows<'a, T, N>where T: 'a + [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/std/os/fd/owned.rs.html#28)1.63.0 · ### impl<'fd> Copy for BorrowedFd<'fd>
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#39)1.63.0 · ### impl<'handle> Copy for BorrowedHandle<'handle>
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/socket.rs.html#29)1.63.0 · ### impl<'socket> Copy for BorrowedSocket<'socket>
Available on **Windows** only.[source](https://doc.rust-lang.org/src/core/ops/control_flow.rs.html#82)1.55.0 · ### impl<B, C> Copy for ControlFlow<B, C>where B: [Copy](trait.copy "trait std::marker::Copy"), C: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/ptr/metadata.rs.html#235)### impl<Dyn> Copy for DynMetadata<Dyn>where Dyn: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/iter/sources/repeat_with.rs.html#73)1.28.0 · ### impl<F> Copy for RepeatWith<F>where F: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#266)### impl<Idx> Copy for RangeTo<Idx>where Idx: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#584)1.26.0 · ### impl<Idx> Copy for RangeToInclusive<Idx>where Idx: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/pin.rs.html#407)1.33.0 · ### impl<P> Copy for Pin<P>where P: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/std/primitive_docs.rs.html#1550-1552)### impl<Ret, T> Copy for fn (T₁, T₂, …, Tₙ) -> Ret
This trait is implemented on function pointers with any number of arguments.
[source](https://doc.rust-lang.org/src/core/ops/range.rs.html#664)1.17.0 · ### impl<T> Copy for Bound<T>where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/option.rs.html#515)### impl<T> Copy for Option<T>where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/task/poll.rs.html#11)1.36.0 · ### impl<T> Copy for Poll<T>where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#841)### impl<T> Copy for \*const Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#844)### impl<T> Copy for \*mut Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#848)### impl<T> Copy for &Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
Shared references can be copied, but mutable references *cannot*!
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#606)1.19.0 · ### impl<T> Copy for Reverse<T>where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/mem/mod.rs.html#1081)1.21.0 · ### impl<T> Copy for Discriminant<T>
[source](https://doc.rust-lang.org/src/core/mem/manually_drop.rs.html#48)1.20.0 · ### impl<T> Copy for ManuallyDrop<T>where T: [Copy](trait.copy "trait std::marker::Copy") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/num/saturating.rs.html#36)### impl<T> Copy for Saturating<T>where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/num/wrapping.rs.html#40)### impl<T> Copy for Wrapping<T>where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#709)1.25.0 · ### impl<T> Copy for NonNull<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> Copy for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/mem/maybe_uninit.rs.html#248)1.36.0 · ### impl<T> Copy for MaybeUninit<T>where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/result.rs.html#500)### impl<T, E> Copy for Result<T, E>where T: [Copy](trait.copy "trait std::marker::Copy"), E: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/core/up/up/portable-simd/crates/core_simd/src/masks.rs.html#93)### impl<T, const LANES: usize> Copy for Mask<T, LANES>where T: [MaskElement](../simd/trait.maskelement "trait std::simd::MaskElement"), [LaneCount](../simd/struct.lanecount "struct std::simd::LaneCount")<LANES>: [SupportedLaneCount](../simd/trait.supportedlanecount "trait std::simd::SupportedLaneCount"),
[source](https://doc.rust-lang.org/src/core/up/up/portable-simd/crates/core_simd/src/vector.rs.html#471)### impl<T, const LANES: usize> Copy for Simd<T, LANES>where T: [SimdElement](../simd/trait.simdelement "trait std::simd::SimdElement"), [LaneCount](../simd/struct.lanecount "struct std::simd::LaneCount")<LANES>: [SupportedLaneCount](../simd/trait.supportedlanecount "trait std::simd::SupportedLaneCount"),
[source](https://doc.rust-lang.org/src/core/array/mod.rs.html#347)1.58.0 · ### impl<T, const N: usize> Copy for [T; N]where T: [Copy](trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#629)### impl<T: Copy> Copy for TrySendError<T>
[source](https://doc.rust-lang.org/src/std/primitive_docs.rs.html#1057-1059)### impl<T: Copy> Copy for (T₁, T₂, …, Tₙ)
This trait is implemented on arbitrary-length tuples.
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#573)### impl<T: Copy> Copy for SendError<T>
[source](https://doc.rust-lang.org/src/core/ops/generator.rs.html#9)### impl<Y, R> Copy for GeneratorState<Y, R>where Y: [Copy](trait.copy "trait std::marker::Copy"), R: [Copy](trait.copy "trait std::marker::Copy"),
| programming_docs |
rust Trait std::marker::Unpin Trait std::marker::Unpin
========================
```
pub auto trait Unpin { }
```
Types that can be safely moved after being pinned.
Rust itself has no notion of immovable types, and considers moves (e.g., through assignment or [`mem::replace`](../mem/fn.replace)) to always be safe.
The [`Pin`](../pin/struct.pin) type is used instead to prevent moves through the type system. Pointers `P<T>` wrapped in the [`Pin<P<T>>`](../pin/struct.pin) wrapper can’t be moved out of. See the [`pin` module](../pin/index) documentation for more information on pinning.
Implementing the `Unpin` trait for `T` lifts the restrictions of pinning off the type, which then allows moving `T` out of [`Pin<P<T>>`](../pin/struct.pin) with functions such as [`mem::replace`](../mem/fn.replace).
`Unpin` has no consequence at all for non-pinned data. In particular, [`mem::replace`](../mem/fn.replace) happily moves `!Unpin` data (it works for any `&mut T`, not just when `T: Unpin`). However, you cannot use [`mem::replace`](../mem/fn.replace) on data wrapped inside a [`Pin<P<T>>`](../pin/struct.pin) because you cannot get the `&mut T` you need for that, and *that* is what makes this system work.
So this, for example, can only be done on types implementing `Unpin`:
```
use std::mem;
use std::pin::Pin;
let mut string = "this".to_string();
let mut pinned_string = Pin::new(&mut string);
// We need a mutable reference to call `mem::replace`.
// We can obtain such a reference by (implicitly) invoking `Pin::deref_mut`,
// but that is only possible because `String` implements `Unpin`.
mem::replace(&mut *pinned_string, "other".to_string());
```
This trait is automatically implemented for almost every type.
Implementors
------------
[source](https://doc.rust-lang.org/src/core/marker.rs.html#780)### impl !Unpin for PhantomPinned
[source](https://doc.rust-lang.org/src/core/task/wake.rs.html#236)1.36.0 · ### impl Unpin for Waker
[source](https://doc.rust-lang.org/src/core/marker.rs.html#783)### impl<'a, T> Unpin for &'a Twhere T: 'a + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#786)### impl<'a, T> Unpin for &'a mut Twhere T: 'a + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/ptr/metadata.rs.html#233)### impl<Dyn> Unpin for DynMetadata<Dyn>where Dyn: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/future/poll_fn.rs.html#46)1.64.0 · ### impl<F> Unpin for PollFn<F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
[source](https://doc.rust-lang.org/src/core/async_iter/from_iter.rs.html#19)### impl<I> Unpin for FromIter<I>
[source](https://doc.rust-lang.org/src/core/marker.rs.html#789)1.38.0 · ### impl<T> Unpin for \*const Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#792)1.38.0 · ### impl<T> Unpin for \*mut Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/future/ready.rs.html#15)1.48.0 · ### impl<T> Unpin for std::future::Ready<T>
[source](https://doc.rust-lang.org/src/alloc/rc.rs.html#2678)### impl<T> Unpin for Rc<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#2743)### impl<T> Unpin for Arc<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/boxed.rs.html#2041)const: [unstable](https://github.com/rust-lang/rust/issues/92521 "Tracking issue for const_box") · ### impl<T, A> Unpin for Box<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + 'static, T: ?[Sized](trait.sized "trait std::marker::Sized"),
Auto implementors
-----------------
### impl Unpin for BacktraceStatus
### impl Unpin for std::cmp::Ordering
### impl Unpin for TryReserveErrorKind
### impl Unpin for Infallible
### impl Unpin for VarError
### impl Unpin for c\_void
### impl Unpin for std::fmt::Alignment
### impl Unpin for ErrorKind
### impl Unpin for SeekFrom
### impl Unpin for IpAddr
### impl Unpin for Ipv6MulticastScope
### impl Unpin for Shutdown
### impl Unpin for std::net::SocketAddr
### impl Unpin for FpCategory
### impl Unpin for IntErrorKind
### impl Unpin for AncillaryError
### impl Unpin for BacktraceStyle
### impl Unpin for Which
### impl Unpin for SearchStep
### impl Unpin for std::sync::atomic::Ordering
### impl Unpin for RecvTimeoutError
### impl Unpin for TryRecvError
### impl Unpin for bool
### impl Unpin for char
### impl Unpin for f32
### impl Unpin for f64
### impl Unpin for i8
### impl Unpin for i16
### impl Unpin for i32
### impl Unpin for i64
### impl Unpin for i128
### impl Unpin for isize
### impl Unpin for str
### impl Unpin for u8
### impl Unpin for u16
### impl Unpin for u32
### impl Unpin for u64
### impl Unpin for u128
### impl Unpin for ()
### impl Unpin for usize
### impl Unpin for AllocError
### impl Unpin for Global
### impl Unpin for Layout
### impl Unpin for LayoutError
### impl Unpin for System
### impl Unpin for TypeId
### impl Unpin for TryFromSliceError
### impl Unpin for std::ascii::EscapeDefault
### impl Unpin for Backtrace
### impl Unpin for BacktraceFrame
### impl Unpin for BorrowError
### impl Unpin for BorrowMutError
### impl Unpin for CharTryFromError
### impl Unpin for DecodeUtf16Error
### impl Unpin for std::char::EscapeDebug
### impl Unpin for std::char::EscapeDefault
### impl Unpin for std::char::EscapeUnicode
### impl Unpin for ParseCharError
### impl Unpin for ToLowercase
### impl Unpin for ToUppercase
### impl Unpin for TryFromCharError
### impl Unpin for DefaultHasher
### impl Unpin for RandomState
### impl Unpin for TryReserveError
### impl Unpin for Args
### impl Unpin for ArgsOs
### impl Unpin for JoinPathsError
### impl Unpin for Vars
### impl Unpin for VarsOs
### impl Unpin for CStr
### impl Unpin for CString
### impl Unpin for FromBytesWithNulError
### impl Unpin for FromVecWithNulError
### impl Unpin for IntoStringError
### impl Unpin for NulError
### impl Unpin for OsStr
### impl Unpin for OsString
### impl Unpin for std::fmt::Error
### impl Unpin for DirBuilder
### impl Unpin for DirEntry
### impl Unpin for File
### impl Unpin for FileTimes
### impl Unpin for FileType
### impl Unpin for Metadata
### impl Unpin for OpenOptions
### impl Unpin for Permissions
### impl Unpin for ReadDir
### impl Unpin for SipHasher
### impl Unpin for std::io::Empty
### impl Unpin for std::io::Error
### impl Unpin for std::io::Repeat
### impl Unpin for Sink
### impl Unpin for Stderr
### impl Unpin for Stdin
### impl Unpin for Stdout
### impl Unpin for WriterPanicked
### impl Unpin for Assume
### impl Unpin for AddrParseError
### impl Unpin for IntoIncoming
### impl Unpin for Ipv4Addr
### impl Unpin for Ipv6Addr
### impl Unpin for SocketAddrV4
### impl Unpin for SocketAddrV6
### impl Unpin for TcpListener
### impl Unpin for TcpStream
### impl Unpin for UdpSocket
### impl Unpin for NonZeroI8
### impl Unpin for NonZeroI16
### impl Unpin for NonZeroI32
### impl Unpin for NonZeroI64
### impl Unpin for NonZeroI128
### impl Unpin for NonZeroIsize
### impl Unpin for NonZeroU8
### impl Unpin for NonZeroU16
### impl Unpin for NonZeroU32
### impl Unpin for NonZeroU64
### impl Unpin for NonZeroU128
### impl Unpin for NonZeroUsize
### impl Unpin for ParseFloatError
### impl Unpin for ParseIntError
### impl Unpin for TryFromIntError
### impl Unpin for RangeFull
### impl Unpin for PidFd
### impl Unpin for stat
### impl Unpin for OwnedFd
### impl Unpin for std::os::unix::net::SocketAddr
### impl Unpin for SocketCred
### impl Unpin for UnixDatagram
### impl Unpin for UnixListener
### impl Unpin for UnixStream
### impl Unpin for UCred
### impl Unpin for HandleOrInvalid
### impl Unpin for HandleOrNull
### impl Unpin for InvalidHandleError
### impl Unpin for NullHandleError
### impl Unpin for OwnedHandle
### impl Unpin for OwnedSocket
### impl Unpin for Path
### impl Unpin for PathBuf
### impl Unpin for StripPrefixError
### impl Unpin for Child
### impl Unpin for ChildStderr
### impl Unpin for ChildStdin
### impl Unpin for ChildStdout
### impl Unpin for Command
### impl Unpin for ExitCode
### impl Unpin for ExitStatus
### impl Unpin for ExitStatusError
### impl Unpin for Output
### impl Unpin for Stdio
### impl Unpin for ParseBoolError
### impl Unpin for Utf8Error
### impl Unpin for FromUtf8Error
### impl Unpin for FromUtf16Error
### impl Unpin for String
### impl Unpin for AtomicBool
### impl Unpin for AtomicI8
### impl Unpin for AtomicI16
### impl Unpin for AtomicI32
### impl Unpin for AtomicI64
### impl Unpin for AtomicIsize
### impl Unpin for AtomicU8
### impl Unpin for AtomicU16
### impl Unpin for AtomicU32
### impl Unpin for AtomicU64
### impl Unpin for AtomicUsize
### impl Unpin for RecvError
### impl Unpin for Barrier
### impl Unpin for BarrierWaitResult
### impl Unpin for Condvar
### impl Unpin for std::sync::Once
### impl Unpin for OnceState
### impl Unpin for WaitTimeoutResult
### impl Unpin for RawWaker
### impl Unpin for RawWakerVTable
### impl Unpin for AccessError
### impl Unpin for Builder
### impl Unpin for Thread
### impl Unpin for ThreadId
### impl Unpin for Duration
### impl Unpin for FromFloatSecsError
### impl Unpin for Instant
### impl Unpin for SystemTime
### impl Unpin for SystemTimeError
### impl Unpin for Alignment
### impl Unpin for Argument
### impl Unpin for Count
### impl Unpin for FormatSpec
### impl<'a> !Unpin for Demand<'a>
### impl<'a> Unpin for AncillaryData<'a>
### impl<'a> Unpin for Component<'a>
### impl<'a> Unpin for Prefix<'a>
### impl<'a> Unpin for SplitPaths<'a>
### impl<'a> Unpin for Arguments<'a>
### impl<'a> Unpin for Formatter<'a>
### impl<'a> Unpin for BorrowedCursor<'a>
### impl<'a> Unpin for IoSlice<'a>
### impl<'a> Unpin for IoSliceMut<'a>
### impl<'a> Unpin for StderrLock<'a>
### impl<'a> Unpin for StdinLock<'a>
### impl<'a> Unpin for StdoutLock<'a>
### impl<'a> Unpin for std::net::Incoming<'a>
### impl<'a> Unpin for std::os::unix::net::Incoming<'a>
### impl<'a> Unpin for Messages<'a>
### impl<'a> Unpin for ScmCredentials<'a>
### impl<'a> Unpin for ScmRights<'a>
### impl<'a> Unpin for SocketAncillary<'a>
### impl<'a> Unpin for EncodeWide<'a>
### impl<'a> Unpin for Location<'a>
### impl<'a> Unpin for PanicInfo<'a>
### impl<'a> Unpin for Ancestors<'a>
### impl<'a> Unpin for Components<'a>
### impl<'a> Unpin for Display<'a>
### impl<'a> Unpin for std::path::Iter<'a>
### impl<'a> Unpin for PrefixComponent<'a>
### impl<'a> Unpin for CommandArgs<'a>
### impl<'a> Unpin for CommandEnvs<'a>
### impl<'a> Unpin for EscapeAscii<'a>
### impl<'a> Unpin for CharSearcher<'a>
### impl<'a> Unpin for std::str::Bytes<'a>
### impl<'a> Unpin for CharIndices<'a>
### impl<'a> Unpin for Chars<'a>
### impl<'a> Unpin for EncodeUtf16<'a>
### impl<'a> Unpin for std::str::EscapeDebug<'a>
### impl<'a> Unpin for std::str::EscapeDefault<'a>
### impl<'a> Unpin for std::str::EscapeUnicode<'a>
### impl<'a> Unpin for std::str::Lines<'a>
### impl<'a> Unpin for LinesAny<'a>
### impl<'a> Unpin for SplitAsciiWhitespace<'a>
### impl<'a> Unpin for SplitWhitespace<'a>
### impl<'a> Unpin for Utf8Chunk<'a>
### impl<'a> Unpin for Utf8Chunks<'a>
### impl<'a> Unpin for std::string::Drain<'a>
### impl<'a> Unpin for Context<'a>
### impl<'a, 'b> Unpin for DebugList<'a, 'b>where 'b: 'a,
### impl<'a, 'b> Unpin for DebugMap<'a, 'b>where 'b: 'a,
### impl<'a, 'b> Unpin for DebugSet<'a, 'b>where 'b: 'a,
### impl<'a, 'b> Unpin for DebugStruct<'a, 'b>where 'b: 'a,
### impl<'a, 'b> Unpin for DebugTuple<'a, 'b>where 'b: 'a,
### impl<'a, 'b> Unpin for CharSliceSearcher<'a, 'b>
### impl<'a, 'b> Unpin for StrSearcher<'a, 'b>
### impl<'a, 'b, const N: usize> Unpin for CharArrayRefSearcher<'a, 'b, N>
### impl<'a, 'f> Unpin for VaList<'a, 'f>where 'f: 'a,
### impl<'a, A> Unpin for std::option::Iter<'a, A>
### impl<'a, A> Unpin for std::option::IterMut<'a, A>
### impl<'a, B: ?Sized> Unpin for Cow<'a, B>where <B as [ToOwned](../borrow/trait.toowned "trait std::borrow::ToOwned")>::[Owned](../borrow/trait.toowned#associatedtype.Owned "type std::borrow::ToOwned::Owned"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, F> Unpin for CharPredicateSearcher<'a, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, I> Unpin for ByRefSized<'a, I>
### impl<'a, I, A> Unpin for Splice<'a, I, A>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K> Unpin for std::collections::hash\_set::Drain<'a, K>where K: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K> Unpin for std::collections::hash\_set::Iter<'a, K>
### impl<'a, K, F> Unpin for std::collections::hash\_set::DrainFilter<'a, K, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> Unpin for std::collections::hash\_map::Entry<'a, K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> Unpin for std::collections::btree\_map::Iter<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::btree\_map::IterMut<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::btree\_map::Keys<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::btree\_map::Range<'a, K, V>
### impl<'a, K, V> Unpin for RangeMut<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::btree\_map::Values<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::btree\_map::ValuesMut<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::hash\_map::Drain<'a, K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"), V: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> Unpin for std::collections::hash\_map::Iter<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::hash\_map::IterMut<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::hash\_map::Keys<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::hash\_map::OccupiedEntry<'a, K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> Unpin for std::collections::hash\_map::OccupiedError<'a, K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"), V: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> Unpin for std::collections::hash\_map::VacantEntry<'a, K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> Unpin for std::collections::hash\_map::Values<'a, K, V>
### impl<'a, K, V> Unpin for std::collections::hash\_map::ValuesMut<'a, K, V>
### impl<'a, K, V, A> Unpin for std::collections::btree\_map::Entry<'a, K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), K: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, A> Unpin for std::collections::btree\_map::OccupiedEntry<'a, K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, A> Unpin for std::collections::btree\_map::OccupiedError<'a, K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), V: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, A> Unpin for std::collections::btree\_map::VacantEntry<'a, K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), K: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, F> Unpin for std::collections::hash\_map::DrainFilter<'a, K, V, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, F, A> Unpin for std::collections::btree\_map::DrainFilter<'a, K, V, F, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, S> Unpin for RawEntryMut<'a, K, V, S>
### impl<'a, K, V, S> Unpin for RawEntryBuilder<'a, K, V, S>
### impl<'a, K, V, S> Unpin for RawEntryBuilderMut<'a, K, V, S>
### impl<'a, K, V, S> Unpin for RawOccupiedEntryMut<'a, K, V, S>
### impl<'a, K, V, S> Unpin for RawVacantEntryMut<'a, K, V, S>
### impl<'a, P> Unpin for MatchIndices<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for Matches<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for RMatchIndices<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for RMatches<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for std::str::RSplit<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for std::str::RSplitN<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for RSplitTerminator<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for std::str::Split<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for std::str::SplitInclusive<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for std::str::SplitN<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, P> Unpin for SplitTerminator<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T> Unpin for std::collections::binary\_heap::Drain<'a, T>
### impl<'a, T> Unpin for DrainSorted<'a, T>
### impl<'a, T> Unpin for std::collections::binary\_heap::Iter<'a, T>
### impl<'a, T> Unpin for PeekMut<'a, T>
### impl<'a, T> Unpin for std::collections::btree\_set::Iter<'a, T>
### impl<'a, T> Unpin for std::collections::btree\_set::Range<'a, T>
### impl<'a, T> Unpin for std::collections::btree\_set::SymmetricDifference<'a, T>
### impl<'a, T> Unpin for std::collections::btree\_set::Union<'a, T>
### impl<'a, T> Unpin for std::collections::linked\_list::Cursor<'a, T>
### impl<'a, T> Unpin for CursorMut<'a, T>
### impl<'a, T> Unpin for std::collections::linked\_list::Iter<'a, T>
### impl<'a, T> Unpin for std::collections::linked\_list::IterMut<'a, T>
### impl<'a, T> Unpin for std::collections::vec\_deque::Iter<'a, T>
### impl<'a, T> Unpin for std::collections::vec\_deque::IterMut<'a, T>
### impl<'a, T> Unpin for std::result::Iter<'a, T>
### impl<'a, T> Unpin for std::result::IterMut<'a, T>
### impl<'a, T> Unpin for Chunks<'a, T>
### impl<'a, T> Unpin for ChunksExact<'a, T>
### impl<'a, T> Unpin for ChunksExactMut<'a, T>
### impl<'a, T> Unpin for ChunksMut<'a, T>
### impl<'a, T> Unpin for std::slice::Iter<'a, T>
### impl<'a, T> Unpin for std::slice::IterMut<'a, T>
### impl<'a, T> Unpin for RChunks<'a, T>
### impl<'a, T> Unpin for RChunksExact<'a, T>
### impl<'a, T> Unpin for RChunksExactMut<'a, T>
### impl<'a, T> Unpin for RChunksMut<'a, T>
### impl<'a, T> Unpin for Windows<'a, T>
### impl<'a, T> Unpin for std::sync::mpsc::Iter<'a, T>
### impl<'a, T> Unpin for TryIter<'a, T>
### impl<'a, T, A> Unpin for std::collections::btree\_set::Difference<'a, T, A>
### impl<'a, T, A> Unpin for std::collections::btree\_set::Intersection<'a, T, A>
### impl<'a, T, A> Unpin for std::collections::vec\_deque::Drain<'a, T, A>
### impl<'a, T, A> Unpin for std::vec::Drain<'a, T, A>
### impl<'a, T, F> Unpin for std::collections::linked\_list::DrainFilter<'a, T, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, F, A> Unpin for std::collections::btree\_set::DrainFilter<'a, T, F, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, F, A> Unpin for std::vec::DrainFilter<'a, T, F, A>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for GroupBy<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for GroupByMut<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for std::slice::RSplit<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for RSplitMut<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for std::slice::RSplitN<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for RSplitNMut<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for std::slice::Split<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for std::slice::SplitInclusive<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for SplitInclusiveMut<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for SplitMut<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for std::slice::SplitN<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, P> Unpin for SplitNMut<'a, T, P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, S> Unpin for std::collections::hash\_set::Difference<'a, T, S>
### impl<'a, T, S> Unpin for std::collections::hash\_set::Intersection<'a, T, S>
### impl<'a, T, S> Unpin for std::collections::hash\_set::SymmetricDifference<'a, T, S>
### impl<'a, T, S> Unpin for std::collections::hash\_set::Union<'a, T, S>
### impl<'a, T, const N: usize> Unpin for std::slice::ArrayChunks<'a, T, N>
### impl<'a, T, const N: usize> Unpin for ArrayChunksMut<'a, T, N>
### impl<'a, T, const N: usize> Unpin for ArrayWindows<'a, T, N>
### impl<'a, T: ?Sized> Unpin for MutexGuard<'a, T>
### impl<'a, T: ?Sized> Unpin for RwLockReadGuard<'a, T>
### impl<'a, T: ?Sized> Unpin for RwLockWriteGuard<'a, T>
### impl<'a, const N: usize> Unpin for CharArraySearcher<'a, N>
### impl<'b, T: ?Sized> Unpin for Ref<'b, T>
### impl<'b, T: ?Sized> Unpin for RefMut<'b, T>
### impl<'data> Unpin for BorrowedBuf<'data>
### impl<'f> Unpin for VaListImpl<'f>
### impl<'fd> Unpin for BorrowedFd<'fd>
### impl<'handle> Unpin for BorrowedHandle<'handle>
### impl<'scope, 'env> Unpin for Scope<'scope, 'env>
### impl<'scope, T> Unpin for ScopedJoinHandle<'scope, T>
### impl<'socket> Unpin for BorrowedSocket<'socket>
### impl<A> Unpin for std::iter::Repeat<A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<A> Unpin for std::option::IntoIter<A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<A, B> Unpin for std::iter::Chain<A, B>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), B: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<A, B> Unpin for Zip<A, B>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), B: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<B> Unpin for std::io::Lines<B>where B: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<B> Unpin for std::io::Split<B>where B: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<B, C> Unpin for ControlFlow<B, C>where B: [Unpin](trait.unpin "trait std::marker::Unpin"), C: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<E> Unpin for Report<E>where E: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<F> Unpin for FromFn<F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<F> Unpin for OnceWith<F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<F> Unpin for RepeatWith<F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<H> Unpin for BuildHasherDefault<H>
### impl<I> Unpin for DecodeUtf16<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Cloned<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Copied<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Cycle<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Enumerate<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Flatten<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), <<I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item") as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[IntoIter](../iter/trait.intoiterator#associatedtype.IntoIter "type std::iter::IntoIterator::IntoIter"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Fuse<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Intersperse<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Peekable<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for Skip<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for StepBy<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I> Unpin for std::iter::Take<I>where I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, F> Unpin for FilterMap<I, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, F> Unpin for Inspect<I, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, F> Unpin for Map<I, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), I: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, G> Unpin for IntersperseWith<I, G>where G: [Unpin](trait.unpin "trait std::marker::Unpin"), I: [Unpin](trait.unpin "trait std::marker::Unpin"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, P> Unpin for Filter<I, P>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, P> Unpin for MapWhile<I, P>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, P> Unpin for SkipWhile<I, P>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, P> Unpin for TakeWhile<I, P>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, St, F> Unpin for Scan<I, St, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), I: [Unpin](trait.unpin "trait std::marker::Unpin"), St: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, U, F> Unpin for FlatMap<I, U, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), I: [Unpin](trait.unpin "trait std::marker::Unpin"), <U as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[IntoIter](../iter/trait.intoiterator#associatedtype.IntoIter "type std::iter::IntoIterator::IntoIter"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<I, const N: usize> Unpin for std::iter::ArrayChunks<I, N>where I: [Unpin](trait.unpin "trait std::marker::Unpin"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<Idx> Unpin for std::ops::Range<Idx>where Idx: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<Idx> Unpin for RangeFrom<Idx>where Idx: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<Idx> Unpin for RangeInclusive<Idx>where Idx: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<Idx> Unpin for RangeTo<Idx>where Idx: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<Idx> Unpin for RangeToInclusive<Idx>where Idx: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K> Unpin for std::collections::hash\_set::IntoIter<K>where K: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V> Unpin for std::collections::hash\_map::IntoIter<K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"), V: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V> Unpin for std::collections::hash\_map::IntoKeys<K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"), V: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V> Unpin for std::collections::hash\_map::IntoValues<K, V>where K: [Unpin](trait.unpin "trait std::marker::Unpin"), V: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V, A> Unpin for std::collections::btree\_map::IntoIter<K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V, A> Unpin for std::collections::btree\_map::IntoKeys<K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V, A> Unpin for std::collections::btree\_map::IntoValues<K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V, A> Unpin for BTreeMap<K, V, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<K, V, S> Unpin for HashMap<K, V, S>where K: [Unpin](trait.unpin "trait std::marker::Unpin"), S: [Unpin](trait.unpin "trait std::marker::Unpin"), V: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<P> Unpin for Pin<P>where P: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<R> Unpin for BufReader<R>where R: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<R> Unpin for std::io::Bytes<R>where R: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<Ret, T> Unpin for fn (T₁, T₂, …, Tₙ) -> Ret
### impl<T> Unpin for Bound<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Option<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for TryLockError<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for TrySendError<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Poll<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for [T]where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for (T₁, T₂, …, Tₙ)where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for OnceCell<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Reverse<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for std::collections::binary\_heap::IntoIter<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for IntoIterSorted<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for std::collections::linked\_list::IntoIter<T>
### impl<T> Unpin for BinaryHeap<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for LinkedList<T>
### impl<T> Unpin for Pending<T>
### impl<T> Unpin for std::io::Cursor<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for std::io::Take<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for std::iter::Empty<T>
### impl<T> Unpin for std::iter::Once<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Rev<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Discriminant<T>
### impl<T> Unpin for Saturating<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Wrapping<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Yeet<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for AssertUnwindSafe<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for std::result::IntoIter<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for AtomicPtr<T>
### impl<T> Unpin for std::sync::mpsc::IntoIter<T>
### impl<T> Unpin for Receiver<T>
### impl<T> Unpin for SendError<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for Sender<T>
### impl<T> Unpin for SyncSender<T>
### impl<T> Unpin for OnceLock<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for PoisonError<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for std::task::Ready<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T> Unpin for JoinHandle<T>
### impl<T> Unpin for LocalKey<T>
### impl<T> Unpin for MaybeUninit<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, A> Unpin for std::collections::btree\_set::IntoIter<T, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, A> Unpin for BTreeSet<T, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, A> Unpin for VecDeque<T, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, A> Unpin for std::collections::vec\_deque::IntoIter<T, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, A> Unpin for std::vec::IntoIter<T, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, A> Unpin for Vec<T, A>where A: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, E> Unpin for Result<T, E>where E: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, F> Unpin for LazyCell<T, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, F> Unpin for Successors<T, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, F> Unpin for LazyLock<T, F>where F: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, S> Unpin for HashSet<T, S>where S: [Unpin](trait.unpin "trait std::marker::Unpin"), T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, U> Unpin for std::io::Chain<T, U>where T: [Unpin](trait.unpin "trait std::marker::Unpin"), U: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, const LANES: usize> Unpin for Mask<T, LANES>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, const LANES: usize> Unpin for Simd<T, LANES>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, const N: usize> Unpin for [T; N]where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T, const N: usize> Unpin for std::array::IntoIter<T, N>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for ThinBox<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for Cell<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for RefCell<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for SyncUnsafeCell<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for UnsafeCell<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for ManuallyDrop<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for NonNull<T>
### impl<T: ?Sized> Unpin for std::rc::Weak<T>
### impl<T: ?Sized> Unpin for Exclusive<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for Mutex<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for RwLock<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> Unpin for std::sync::Weak<T>
### impl<T: ?Sized> Unpin for PhantomData<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<W> Unpin for BufWriter<W>where W: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<W> Unpin for IntoInnerError<W>where W: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<W> Unpin for LineWriter<W>where W: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<Y, R> Unpin for GeneratorState<Y, R>where R: [Unpin](trait.unpin "trait std::marker::Unpin"), Y: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<const LANES: usize> Unpin for LaneCount<LANES>
| programming_docs |
rust Struct std::marker::PhantomData Struct std::marker::PhantomData
===============================
```
pub struct PhantomData<T>where T: ?Sized;
```
Zero-sized type used to mark things that “act like” they own a `T`.
Adding a `PhantomData<T>` field to your type tells the compiler that your type acts as though it stores a value of type `T`, even though it doesn’t really. This information is used when computing certain safety properties.
For a more in-depth explanation of how to use `PhantomData<T>`, please see [the Nomicon](https://doc.rust-lang.org/nomicon/phantom-data.html).
A ghastly note 👻👻👻
------------------
Though they both have scary names, `PhantomData` and ‘phantom types’ are related, but not identical. A phantom type parameter is simply a type parameter which is never used. In Rust, this often causes the compiler to complain, and the solution is to add a “dummy” use by way of `PhantomData`.
Examples
--------
### Unused lifetime parameters
Perhaps the most common use case for `PhantomData` is a struct that has an unused lifetime parameter, typically as part of some unsafe code. For example, here is a struct `Slice` that has two pointers of type `*const T`, presumably pointing into an array somewhere:
ⓘ
```
struct Slice<'a, T> {
start: *const T,
end: *const T,
}
```
The intention is that the underlying data is only valid for the lifetime `'a`, so `Slice` should not outlive `'a`. However, this intent is not expressed in the code, since there are no uses of the lifetime `'a` and hence it is not clear what data it applies to. We can correct this by telling the compiler to act *as if* the `Slice` struct contained a reference `&'a T`:
```
use std::marker::PhantomData;
struct Slice<'a, T: 'a> {
start: *const T,
end: *const T,
phantom: PhantomData<&'a T>,
}
```
This also in turn requires the annotation `T: 'a`, indicating that any references in `T` are valid over the lifetime `'a`.
When initializing a `Slice` you simply provide the value `PhantomData` for the field `phantom`:
```
fn borrow_vec<T>(vec: &Vec<T>) -> Slice<'_, T> {
let ptr = vec.as_ptr();
Slice {
start: ptr,
end: unsafe { ptr.add(vec.len()) },
phantom: PhantomData,
}
}
```
### Unused type parameters
It sometimes happens that you have unused type parameters which indicate what type of data a struct is “tied” to, even though that data is not actually found in the struct itself. Here is an example where this arises with [FFI](../../book/ch19-01-unsafe-rust#using-extern-functions-to-call-external-code). The foreign interface uses handles of type `*mut ()` to refer to Rust values of different types. We track the Rust type using a phantom type parameter on the struct `ExternalResource` which wraps a handle.
```
use std::marker::PhantomData;
use std::mem;
struct ExternalResource<R> {
resource_handle: *mut (),
resource_type: PhantomData<R>,
}
impl<R: ResType> ExternalResource<R> {
fn new() -> Self {
let size_of_res = mem::size_of::<R>();
Self {
resource_handle: foreign_lib::new(size_of_res),
resource_type: PhantomData,
}
}
fn do_stuff(&self, param: ParamType) {
let foreign_params = convert_params(param);
foreign_lib::do_stuff(self.resource_handle, foreign_params);
}
}
```
### Ownership and the drop check
Adding a field of type `PhantomData<T>` indicates that your type owns data of type `T`. This in turn implies that when your type is dropped, it may drop one or more instances of the type `T`. This has bearing on the Rust compiler’s [drop check](https://doc.rust-lang.org/nomicon/dropck.html) analysis.
If your struct does not in fact *own* the data of type `T`, it is better to use a reference type, like `PhantomData<&'a T>` (ideally) or `PhantomData<*const T>` (if no lifetime applies), so as not to indicate ownership.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> Clone for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)#### fn clone(&self) -> PhantomData<T>
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#2604)### impl<T> Debug for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/fmt/mod.rs.html#2605)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · ### impl<T> Default for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)const: [unstable](https://github.com/rust-lang/rust/issues/87864 "Tracking issue for const_default_impls") · #### fn default() -> PhantomData<T>
Returns the “default value” for a type. [Read more](../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> Hash for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)#### fn hash<H>(&self, &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> Ord for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)#### fn cmp(&self, \_other: &PhantomData<T>) -> Ordering
This method returns an [`Ordering`](../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> PartialEq<PhantomData<T>> for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)#### fn eq(&self, \_other: &PhantomData<T>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> PartialOrd<PhantomData<T>> for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)#### fn partial\_cmp(&self, \_other: &PhantomData<T>) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> Copy for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> Eq for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> StructuralEq for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#680)### impl<T> StructuralPartialEq for PhantomData<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
Auto Trait Implementations
--------------------------
### impl<T: ?Sized> RefUnwindSafe for PhantomData<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T: ?Sized> Send for PhantomData<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T: ?Sized> Sync for PhantomData<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T: ?Sized> Unpin for PhantomData<T>where T: [Unpin](trait.unpin "trait std::marker::Unpin"),
### impl<T: ?Sized> UnwindSafe for PhantomData<T>where T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Trait std::marker::Send Trait std::marker::Send
=======================
```
pub unsafe auto trait Send { }
```
Types that can be transferred across thread boundaries.
This trait is automatically implemented when the compiler determines it’s appropriate.
An example of a non-`Send` type is the reference-counting pointer [`rc::Rc`](../rc/struct.rc). If two threads attempt to clone [`Rc`](../rc/struct.rc)s that point to the same reference-counted value, they might try to update the reference count at the same time, which is [undefined behavior](../../reference/behavior-considered-undefined) because [`Rc`](../rc/struct.rc) doesn’t use atomic operations. Its cousin [`sync::Arc`](../sync/struct.arc) does use atomic operations (incurring some overhead) and thus is `Send`.
See [the Nomicon](https://doc.rust-lang.org/nomicon/send-and-sync.html) for more details.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/env.rs.html#796)1.26.0 · ### impl !Send for Args
[source](https://doc.rust-lang.org/src/std/env.rs.html#837)1.26.0 · ### impl !Send for ArgsOs
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#127)1.63.0 · ### impl Send for BorrowedHandle<'\_>
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#125)1.63.0 · ### impl Send for HandleOrInvalid
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#123)1.63.0 · ### impl Send for HandleOrNull
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#121)1.63.0 · ### impl Send for OwnedHandle
Available on **Windows** only.[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2878)1.6.0 · ### impl Send for std::string::Drain<'\_>
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#128)### impl Send for std::sync::Once
[source](https://doc.rust-lang.org/src/core/task/wake.rs.html#238)1.36.0 · ### impl Send for Waker
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1208)1.44.0 · ### impl<'a> Send for IoSlice<'a>
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1065)1.44.0 · ### impl<'a> Send for IoSliceMut<'a>
[source](https://doc.rust-lang.org/src/core/ptr/metadata.rs.html#222)### impl<Dyn> Send for DynMetadata<Dyn>where Dyn: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#43)### impl<T> !Send for \*const Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#45)### impl<T> !Send for \*mut Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#59)1.25.0 · ### impl<T> !Send for NonNull<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
`NonNull` pointers are not `Send` because the data they reference may be aliased.
[source](https://doc.rust-lang.org/src/alloc/rc.rs.html#315)### impl<T> !Send for Rc<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/rc.rs.html#2157)1.4.0 · ### impl<T> !Send for std::rc::Weak<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#684)### impl<T> Send for &Twhere T: [Sync](trait.sync "trait std::marker::Sync") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#686)### impl<T> Send for &mut Twhere T: [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/boxed/thin.rs.html#44)### impl<T> Send for ThinBox<T>where T: [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
`ThinBox<T>` is `Send` if `T` is `Send` because the data is owned.
[source](https://doc.rust-lang.org/src/core/cell.rs.html#249)### impl<T> Send for Cell<T>where T: [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/cell.rs.html#1152)### impl<T> Send for RefCell<T>where T: [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#2003)### impl<T> Send for std::collections::linked\_list::Cursor<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#2009)### impl<T> Send for CursorMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1991)### impl<T> Send for std::collections::linked\_list::Iter<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1997)### impl<T> Send for std::collections::linked\_list::IterMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1985)### impl<T> Send for LinkedList<T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/iter_mut.rs.html#36)### impl<T> Send for std::collections::vec\_deque::IterMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#2124)1.31.0 · ### impl<T> Send for ChunksExactMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#1792)### impl<T> Send for ChunksMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#84)### impl<T> Send for std::slice::Iter<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#205)### impl<T> Send for std::slice::IterMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#3190)1.31.0 · ### impl<T> Send for RChunksExactMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#2851)1.31.0 · ### impl<T> Send for RChunksMut<'\_, T>where T: [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#192)### impl<T> Send for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#241)### impl<T> Send for Arc<T>where T: [Sync](trait.sync "trait std::marker::Sync") + [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#296)1.4.0 · ### impl<T> Send for std::sync::Weak<T>where T: [Sync](trait.sync "trait std::marker::Sync") + [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/std/thread/mod.rs.html#1461)1.29.0 · ### impl<T> Send for JoinHandle<T>
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/drain.rs.html#62)1.6.0 · ### impl<T, A> Send for std::collections::vec\_deque::Drain<'\_, T, A>where T: [Send](trait.send "trait std::marker::Send"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/alloc/vec/drain.rs.html#151)1.6.0 · ### impl<T, A> Send for std::vec::Drain<'\_, T, A>where T: [Send](trait.send "trait std::marker::Send"), A: [Send](trait.send "trait std::marker::Send") + [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/vec/into_iter.rs.html#140)### impl<T, A> Send for std::vec::IntoIter<T, A>where T: [Send](trait.send "trait std::marker::Send"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Send](trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#350)### impl<T: Send> Send for Receiver<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#507)### impl<T: Send> Send for Sender<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#564)### impl<T: Send> Send for SyncSender<T>
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#338)### impl<T: Send> Send for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#174)### impl<T: ?Sized + Send> Send for Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#86)### impl<T: ?Sized + Send> Send for RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#202)### impl<T: ?Sized> !Send for MutexGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#115)### impl<T: ?Sized> !Send for RwLockReadGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#141)### impl<T: ?Sized> !Send for RwLockWriteGuard<'\_, T>
Auto implementors
-----------------
### impl !Send for Vars
### impl !Send for VarsOs
### impl !Send for OnceState
### impl !Send for RawWaker
### impl Send for BacktraceStatus
### impl Send for std::cmp::Ordering
### impl Send for TryReserveErrorKind
### impl Send for Infallible
### impl Send for VarError
### impl Send for c\_void
### impl Send for std::fmt::Alignment
### impl Send for ErrorKind
### impl Send for SeekFrom
### impl Send for IpAddr
### impl Send for Ipv6MulticastScope
### impl Send for Shutdown
### impl Send for std::net::SocketAddr
### impl Send for FpCategory
### impl Send for IntErrorKind
### impl Send for AncillaryError
### impl Send for BacktraceStyle
### impl Send for Which
### impl Send for SearchStep
### impl Send for std::sync::atomic::Ordering
### impl Send for RecvTimeoutError
### impl Send for TryRecvError
### impl Send for bool
### impl Send for char
### impl Send for f32
### impl Send for f64
### impl Send for i8
### impl Send for i16
### impl Send for i32
### impl Send for i64
### impl Send for i128
### impl Send for isize
### impl Send for str
### impl Send for u8
### impl Send for u16
### impl Send for u32
### impl Send for u64
### impl Send for u128
### impl Send for ()
### impl Send for usize
### impl Send for AllocError
### impl Send for Global
### impl Send for Layout
### impl Send for LayoutError
### impl Send for System
### impl Send for TypeId
### impl Send for TryFromSliceError
### impl Send for std::ascii::EscapeDefault
### impl Send for Backtrace
### impl Send for BacktraceFrame
### impl Send for BorrowError
### impl Send for BorrowMutError
### impl Send for CharTryFromError
### impl Send for DecodeUtf16Error
### impl Send for std::char::EscapeDebug
### impl Send for std::char::EscapeDefault
### impl Send for std::char::EscapeUnicode
### impl Send for ParseCharError
### impl Send for ToLowercase
### impl Send for ToUppercase
### impl Send for TryFromCharError
### impl Send for DefaultHasher
### impl Send for RandomState
### impl Send for TryReserveError
### impl Send for JoinPathsError
### impl Send for CStr
### impl Send for CString
### impl Send for FromBytesWithNulError
### impl Send for FromVecWithNulError
### impl Send for IntoStringError
### impl Send for NulError
### impl Send for OsStr
### impl Send for OsString
### impl Send for std::fmt::Error
### impl Send for DirBuilder
### impl Send for DirEntry
### impl Send for File
### impl Send for FileTimes
### impl Send for FileType
### impl Send for Metadata
### impl Send for OpenOptions
### impl Send for Permissions
### impl Send for ReadDir
### impl Send for SipHasher
### impl Send for std::io::Empty
### impl Send for std::io::Error
### impl Send for std::io::Repeat
### impl Send for Sink
### impl Send for Stderr
### impl Send for Stdin
### impl Send for Stdout
### impl Send for WriterPanicked
### impl Send for Assume
### impl Send for AddrParseError
### impl Send for IntoIncoming
### impl Send for Ipv4Addr
### impl Send for Ipv6Addr
### impl Send for SocketAddrV4
### impl Send for SocketAddrV6
### impl Send for TcpListener
### impl Send for TcpStream
### impl Send for UdpSocket
### impl Send for NonZeroI8
### impl Send for NonZeroI16
### impl Send for NonZeroI32
### impl Send for NonZeroI64
### impl Send for NonZeroI128
### impl Send for NonZeroIsize
### impl Send for NonZeroU8
### impl Send for NonZeroU16
### impl Send for NonZeroU32
### impl Send for NonZeroU64
### impl Send for NonZeroU128
### impl Send for NonZeroUsize
### impl Send for ParseFloatError
### impl Send for ParseIntError
### impl Send for TryFromIntError
### impl Send for RangeFull
### impl Send for PidFd
### impl Send for stat
### impl Send for OwnedFd
### impl Send for std::os::unix::net::SocketAddr
### impl Send for SocketCred
### impl Send for UnixDatagram
### impl Send for UnixListener
### impl Send for UnixStream
### impl Send for UCred
### impl Send for InvalidHandleError
### impl Send for NullHandleError
### impl Send for OwnedSocket
### impl Send for Path
### impl Send for PathBuf
### impl Send for StripPrefixError
### impl Send for Child
### impl Send for ChildStderr
### impl Send for ChildStdin
### impl Send for ChildStdout
### impl Send for Command
### impl Send for ExitCode
### impl Send for ExitStatus
### impl Send for ExitStatusError
### impl Send for Output
### impl Send for Stdio
### impl Send for ParseBoolError
### impl Send for Utf8Error
### impl Send for FromUtf8Error
### impl Send for FromUtf16Error
### impl Send for String
### impl Send for AtomicBool
### impl Send for AtomicI8
### impl Send for AtomicI16
### impl Send for AtomicI32
### impl Send for AtomicI64
### impl Send for AtomicIsize
### impl Send for AtomicU8
### impl Send for AtomicU16
### impl Send for AtomicU32
### impl Send for AtomicU64
### impl Send for AtomicUsize
### impl Send for RecvError
### impl Send for Barrier
### impl Send for BarrierWaitResult
### impl Send for Condvar
### impl Send for WaitTimeoutResult
### impl Send for RawWakerVTable
### impl Send for AccessError
### impl Send for Builder
### impl Send for Thread
### impl Send for ThreadId
### impl Send for Duration
### impl Send for FromFloatSecsError
### impl Send for Instant
### impl Send for SystemTime
### impl Send for SystemTimeError
### impl Send for PhantomPinned
### impl Send for Alignment
### impl Send for Argument
### impl Send for Count
### impl Send for FormatSpec
### impl<'a> !Send for Demand<'a>
### impl<'a> !Send for Arguments<'a>
### impl<'a> !Send for Formatter<'a>
### impl<'a> !Send for StderrLock<'a>
### impl<'a> !Send for StdinLock<'a>
### impl<'a> !Send for StdoutLock<'a>
### impl<'a> !Send for PanicInfo<'a>
### impl<'a> Send for AncillaryData<'a>
### impl<'a> Send for Component<'a>
### impl<'a> Send for Prefix<'a>
### impl<'a> Send for SplitPaths<'a>
### impl<'a> Send for BorrowedCursor<'a>
### impl<'a> Send for std::net::Incoming<'a>
### impl<'a> Send for std::os::unix::net::Incoming<'a>
### impl<'a> Send for Messages<'a>
### impl<'a> Send for ScmCredentials<'a>
### impl<'a> Send for ScmRights<'a>
### impl<'a> Send for SocketAncillary<'a>
### impl<'a> Send for EncodeWide<'a>
### impl<'a> Send for Location<'a>
### impl<'a> Send for Ancestors<'a>
### impl<'a> Send for Components<'a>
### impl<'a> Send for Display<'a>
### impl<'a> Send for std::path::Iter<'a>
### impl<'a> Send for PrefixComponent<'a>
### impl<'a> Send for CommandArgs<'a>
### impl<'a> Send for CommandEnvs<'a>
### impl<'a> Send for EscapeAscii<'a>
### impl<'a> Send for CharSearcher<'a>
### impl<'a> Send for std::str::Bytes<'a>
### impl<'a> Send for CharIndices<'a>
### impl<'a> Send for Chars<'a>
### impl<'a> Send for EncodeUtf16<'a>
### impl<'a> Send for std::str::EscapeDebug<'a>
### impl<'a> Send for std::str::EscapeDefault<'a>
### impl<'a> Send for std::str::EscapeUnicode<'a>
### impl<'a> Send for std::str::Lines<'a>
### impl<'a> Send for LinesAny<'a>
### impl<'a> Send for SplitAsciiWhitespace<'a>
### impl<'a> Send for SplitWhitespace<'a>
### impl<'a> Send for Utf8Chunk<'a>
### impl<'a> Send for Utf8Chunks<'a>
### impl<'a> Send for Context<'a>
### impl<'a, 'b> !Send for DebugList<'a, 'b>
### impl<'a, 'b> !Send for DebugMap<'a, 'b>
### impl<'a, 'b> !Send for DebugSet<'a, 'b>
### impl<'a, 'b> !Send for DebugStruct<'a, 'b>
### impl<'a, 'b> !Send for DebugTuple<'a, 'b>
### impl<'a, 'b> Send for CharSliceSearcher<'a, 'b>
### impl<'a, 'b> Send for StrSearcher<'a, 'b>
### impl<'a, 'b, const N: usize> Send for CharArrayRefSearcher<'a, 'b, N>
### impl<'a, 'f> !Send for VaList<'a, 'f>
### impl<'a, A> Send for std::option::Iter<'a, A>where A: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, A> Send for std::option::IterMut<'a, A>where A: [Send](trait.send "trait std::marker::Send"),
### impl<'a, B: ?Sized> Send for Cow<'a, B>where B: [Sync](trait.sync "trait std::marker::Sync"), <B as [ToOwned](../borrow/trait.toowned "trait std::borrow::ToOwned")>::[Owned](../borrow/trait.toowned#associatedtype.Owned "type std::borrow::ToOwned::Owned"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, F> Send for CharPredicateSearcher<'a, F>where F: [Send](trait.send "trait std::marker::Send"),
### impl<'a, I> Send for ByRefSized<'a, I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<'a, I, A> Send for Splice<'a, I, A>where A: [Send](trait.send "trait std::marker::Send"), I: [Send](trait.send "trait std::marker::Send"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, K> Send for std::collections::hash\_set::Drain<'a, K>where K: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K> Send for std::collections::hash\_set::Iter<'a, K>where K: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, F> Send for std::collections::hash\_set::DrainFilter<'a, K, F>where F: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::hash\_map::Entry<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::btree\_map::Iter<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Send for std::collections::btree\_map::IterMut<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::btree\_map::Keys<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Send for std::collections::btree\_map::Range<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Send for RangeMut<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::btree\_map::Values<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Send for std::collections::btree\_map::ValuesMut<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::hash\_map::Drain<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::hash\_map::Iter<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Send for std::collections::hash\_map::IterMut<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::hash\_map::Keys<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Send for std::collections::hash\_map::OccupiedEntry<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::hash\_map::OccupiedError<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::hash\_map::VacantEntry<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V> Send for std::collections::hash\_map::Values<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Send for std::collections::hash\_map::ValuesMut<'a, K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Send for std::collections::btree\_map::Entry<'a, K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Send for std::collections::btree\_map::OccupiedEntry<'a, K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Send for std::collections::btree\_map::OccupiedError<'a, K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Send for std::collections::btree\_map::VacantEntry<'a, K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, F> Send for std::collections::hash\_map::DrainFilter<'a, K, V, F>where F: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, F, A> Send for std::collections::btree\_map::DrainFilter<'a, K, V, F, A>where A: [Send](trait.send "trait std::marker::Send"), F: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Send for RawEntryMut<'a, K, V, S>where K: [Send](trait.send "trait std::marker::Send"), S: [Send](trait.send "trait std::marker::Send") + [Sync](trait.sync "trait std::marker::Sync"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Send for RawEntryBuilder<'a, K, V, S>where K: [Sync](trait.sync "trait std::marker::Sync"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Send for RawEntryBuilderMut<'a, K, V, S>where K: [Send](trait.send "trait std::marker::Send"), S: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Send for RawOccupiedEntryMut<'a, K, V, S>where K: [Send](trait.send "trait std::marker::Send"), S: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Send for RawVacantEntryMut<'a, K, V, S>where K: [Send](trait.send "trait std::marker::Send"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for MatchIndices<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for Matches<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for RMatchIndices<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for RMatches<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for std::str::RSplit<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for std::str::RSplitN<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for RSplitTerminator<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for std::str::Split<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for std::str::SplitInclusive<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for std::str::SplitN<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, P> Send for SplitTerminator<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Send](trait.send "trait std::marker::Send"),
### impl<'a, T> !Send for std::sync::mpsc::Iter<'a, T>
### impl<'a, T> !Send for TryIter<'a, T>
### impl<'a, T> Send for std::collections::binary\_heap::Drain<'a, T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T> Send for DrainSorted<'a, T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T> Send for std::collections::binary\_heap::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for PeekMut<'a, T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T> Send for std::collections::btree\_set::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for std::collections::btree\_set::Range<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for std::collections::btree\_set::SymmetricDifference<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for std::collections::btree\_set::Union<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for std::collections::vec\_deque::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for std::result::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for std::result::IterMut<'a, T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T> Send for Chunks<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for ChunksExact<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for RChunks<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for RChunksExact<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Send for Windows<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Send for std::collections::btree\_set::Difference<'a, T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Send for std::collections::btree\_set::Intersection<'a, T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, F> !Send for std::collections::linked\_list::DrainFilter<'a, T, F>
### impl<'a, T, F, A> Send for std::collections::btree\_set::DrainFilter<'a, T, F, A>where A: [Send](trait.send "trait std::marker::Send"), F: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, F, A> Send for std::vec::DrainFilter<'a, T, F, A>where A: [Send](trait.send "trait std::marker::Send"), F: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, P> Send for GroupBy<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Send for GroupByMut<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, P> Send for std::slice::RSplit<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Send for RSplitMut<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, P> Send for std::slice::RSplitN<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Send for RSplitNMut<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, P> Send for std::slice::Split<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Send for std::slice::SplitInclusive<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Send for SplitInclusiveMut<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, P> Send for SplitMut<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, P> Send for std::slice::SplitN<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Send for SplitNMut<'a, T, P>where P: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, T, S> Send for std::collections::hash\_set::Difference<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, S> Send for std::collections::hash\_set::Intersection<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, S> Send for std::collections::hash\_set::SymmetricDifference<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, S> Send for std::collections::hash\_set::Union<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, const N: usize> !Send for ArrayWindows<'a, T, N>
### impl<'a, T, const N: usize> Send for std::slice::ArrayChunks<'a, T, N>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, const N: usize> Send for ArrayChunksMut<'a, T, N>where T: [Send](trait.send "trait std::marker::Send"),
### impl<'a, const N: usize> Send for CharArraySearcher<'a, N>
### impl<'b, T> !Send for Ref<'b, T>
### impl<'b, T> !Send for RefMut<'b, T>
### impl<'data> Send for BorrowedBuf<'data>
### impl<'f> !Send for VaListImpl<'f>
### impl<'fd> Send for BorrowedFd<'fd>
### impl<'scope, 'env> Send for Scope<'scope, 'env>
### impl<'scope, T> Send for ScopedJoinHandle<'scope, T>where T: [Send](trait.send "trait std::marker::Send") + [Sync](trait.sync "trait std::marker::Sync"),
### impl<'socket> Send for BorrowedSocket<'socket>
### impl<A> Send for std::iter::Repeat<A>where A: [Send](trait.send "trait std::marker::Send"),
### impl<A> Send for std::option::IntoIter<A>where A: [Send](trait.send "trait std::marker::Send"),
### impl<A, B> Send for std::iter::Chain<A, B>where A: [Send](trait.send "trait std::marker::Send"), B: [Send](trait.send "trait std::marker::Send"),
### impl<A, B> Send for Zip<A, B>where A: [Send](trait.send "trait std::marker::Send"), B: [Send](trait.send "trait std::marker::Send"),
### impl<B> Send for std::io::Lines<B>where B: [Send](trait.send "trait std::marker::Send"),
### impl<B> Send for std::io::Split<B>where B: [Send](trait.send "trait std::marker::Send"),
### impl<B, C> Send for ControlFlow<B, C>where B: [Send](trait.send "trait std::marker::Send"), C: [Send](trait.send "trait std::marker::Send"),
### impl<E> Send for Report<E>where E: [Send](trait.send "trait std::marker::Send"),
### impl<F> Send for PollFn<F>where F: [Send](trait.send "trait std::marker::Send"),
### impl<F> Send for FromFn<F>where F: [Send](trait.send "trait std::marker::Send"),
### impl<F> Send for OnceWith<F>where F: [Send](trait.send "trait std::marker::Send"),
### impl<F> Send for RepeatWith<F>where F: [Send](trait.send "trait std::marker::Send"),
### impl<H> Send for BuildHasherDefault<H>
### impl<I> Send for FromIter<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for DecodeUtf16<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Cloned<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Copied<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Cycle<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Enumerate<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Flatten<I>where I: [Send](trait.send "trait std::marker::Send"), <<I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item") as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[IntoIter](../iter/trait.intoiterator#associatedtype.IntoIter "type std::iter::IntoIterator::IntoIter"): [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Fuse<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Intersperse<I>where I: [Send](trait.send "trait std::marker::Send"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Peekable<I>where I: [Send](trait.send "trait std::marker::Send"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for Skip<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for StepBy<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I> Send for std::iter::Take<I>where I: [Send](trait.send "trait std::marker::Send"),
### impl<I, F> Send for FilterMap<I, F>where F: [Send](trait.send "trait std::marker::Send"), I: [Send](trait.send "trait std::marker::Send"),
### impl<I, F> Send for Inspect<I, F>where F: [Send](trait.send "trait std::marker::Send"), I: [Send](trait.send "trait std::marker::Send"),
### impl<I, F> Send for Map<I, F>where F: [Send](trait.send "trait std::marker::Send"), I: [Send](trait.send "trait std::marker::Send"),
### impl<I, G> Send for IntersperseWith<I, G>where G: [Send](trait.send "trait std::marker::Send"), I: [Send](trait.send "trait std::marker::Send"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Send](trait.send "trait std::marker::Send"),
### impl<I, P> Send for Filter<I, P>where I: [Send](trait.send "trait std::marker::Send"), P: [Send](trait.send "trait std::marker::Send"),
### impl<I, P> Send for MapWhile<I, P>where I: [Send](trait.send "trait std::marker::Send"), P: [Send](trait.send "trait std::marker::Send"),
### impl<I, P> Send for SkipWhile<I, P>where I: [Send](trait.send "trait std::marker::Send"), P: [Send](trait.send "trait std::marker::Send"),
### impl<I, P> Send for TakeWhile<I, P>where I: [Send](trait.send "trait std::marker::Send"), P: [Send](trait.send "trait std::marker::Send"),
### impl<I, St, F> Send for Scan<I, St, F>where F: [Send](trait.send "trait std::marker::Send"), I: [Send](trait.send "trait std::marker::Send"), St: [Send](trait.send "trait std::marker::Send"),
### impl<I, U, F> Send for FlatMap<I, U, F>where F: [Send](trait.send "trait std::marker::Send"), I: [Send](trait.send "trait std::marker::Send"), <U as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[IntoIter](../iter/trait.intoiterator#associatedtype.IntoIter "type std::iter::IntoIterator::IntoIter"): [Send](trait.send "trait std::marker::Send"),
### impl<I, const N: usize> Send for std::iter::ArrayChunks<I, N>where I: [Send](trait.send "trait std::marker::Send"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Send](trait.send "trait std::marker::Send"),
### impl<Idx> Send for std::ops::Range<Idx>where Idx: [Send](trait.send "trait std::marker::Send"),
### impl<Idx> Send for RangeFrom<Idx>where Idx: [Send](trait.send "trait std::marker::Send"),
### impl<Idx> Send for RangeInclusive<Idx>where Idx: [Send](trait.send "trait std::marker::Send"),
### impl<Idx> Send for RangeTo<Idx>where Idx: [Send](trait.send "trait std::marker::Send"),
### impl<Idx> Send for RangeToInclusive<Idx>where Idx: [Send](trait.send "trait std::marker::Send"),
### impl<K> Send for std::collections::hash\_set::IntoIter<K>where K: [Send](trait.send "trait std::marker::Send"),
### impl<K, V> Send for std::collections::hash\_map::IntoIter<K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<K, V> Send for std::collections::hash\_map::IntoKeys<K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<K, V> Send for std::collections::hash\_map::IntoValues<K, V>where K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<K, V, A> Send for std::collections::btree\_map::IntoIter<K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<K, V, A> Send for std::collections::btree\_map::IntoKeys<K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<K, V, A> Send for std::collections::btree\_map::IntoValues<K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<K, V, A> Send for BTreeMap<K, V, A>where A: [Send](trait.send "trait std::marker::Send"), K: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<K, V, S> Send for HashMap<K, V, S>where K: [Send](trait.send "trait std::marker::Send"), S: [Send](trait.send "trait std::marker::Send"), V: [Send](trait.send "trait std::marker::Send"),
### impl<P> Send for Pin<P>where P: [Send](trait.send "trait std::marker::Send"),
### impl<R> Send for BufReader<R>where R: [Send](trait.send "trait std::marker::Send"),
### impl<R> Send for std::io::Bytes<R>where R: [Send](trait.send "trait std::marker::Send"),
### impl<Ret, T> Send for fn (T₁, T₂, …, Tₙ) -> Ret
### impl<T> Send for Bound<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Option<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for TryLockError<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for TrySendError<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Poll<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for [T]where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for (T₁, T₂, …, Tₙ)where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for OnceCell<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Reverse<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::collections::binary\_heap::IntoIter<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for IntoIterSorted<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::collections::linked\_list::IntoIter<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for BinaryHeap<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Pending<T>
### impl<T> Send for std::future::Ready<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::io::Cursor<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::io::Take<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::iter::Empty<T>
### impl<T> Send for std::iter::Once<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Rev<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Discriminant<T>
### impl<T> Send for Saturating<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Wrapping<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for Yeet<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for AssertUnwindSafe<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::result::IntoIter<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::sync::mpsc::IntoIter<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for SendError<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for PoisonError<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for std::task::Ready<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Send for LocalKey<T>
### impl<T> Send for MaybeUninit<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T, A> Send for std::collections::btree\_set::IntoIter<T, A>where A: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, A> Send for BTreeSet<T, A>where A: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, A> Send for VecDeque<T, A>where A: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, A> Send for std::collections::vec\_deque::IntoIter<T, A>where A: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, A> Send for Vec<T, A>where A: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, E> Send for Result<T, E>where E: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, F> Send for LazyCell<T, F>where F: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, F> Send for Successors<T, F>where F: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, F> Send for LazyLock<T, F>where F: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, S> Send for HashSet<T, S>where S: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<T, U> Send for std::io::Chain<T, U>where T: [Send](trait.send "trait std::marker::Send"), U: [Send](trait.send "trait std::marker::Send"),
### impl<T, const LANES: usize> Send for Mask<T, LANES>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T, const LANES: usize> Send for Simd<T, LANES>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T, const N: usize> Send for [T; N]where T: [Send](trait.send "trait std::marker::Send"),
### impl<T, const N: usize> Send for std::array::IntoIter<T, N>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T: ?Sized> Send for SyncUnsafeCell<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T: ?Sized> Send for UnsafeCell<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T: ?Sized> Send for ManuallyDrop<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T: ?Sized> Send for Exclusive<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T: ?Sized> Send for PhantomData<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T: ?Sized, A> Send for Box<T, A>where A: [Send](trait.send "trait std::marker::Send"), T: [Send](trait.send "trait std::marker::Send"),
### impl<W> Send for BufWriter<W>where W: [Send](trait.send "trait std::marker::Send"),
### impl<W> Send for IntoInnerError<W>where W: [Send](trait.send "trait std::marker::Send"),
### impl<W> Send for LineWriter<W>where W: [Send](trait.send "trait std::marker::Send"),
### impl<Y, R> Send for GeneratorState<Y, R>where R: [Send](trait.send "trait std::marker::Send"), Y: [Send](trait.send "trait std::marker::Send"),
### impl<const LANES: usize> Send for LaneCount<LANES>
| programming_docs |
rust Trait std::marker::Sized Trait std::marker::Sized
========================
```
pub trait Sized { }
```
Types with a constant size known at compile time.
All type parameters have an implicit bound of `Sized`. The special syntax `?Sized` can be used to remove this bound if it’s not appropriate.
```
struct Foo<T>(T);
struct Bar<T: ?Sized>(T);
// struct FooUse(Foo<[i32]>); // error: Sized is not implemented for [i32]
struct BarUse(Bar<[i32]>); // OK
```
The one exception is the implicit `Self` type of a trait. A trait does not have an implicit `Sized` bound as this is incompatible with [trait object](../../book/ch17-02-trait-objects)s where, by definition, the trait needs to work with all possible implementors, and thus could be any size.
Although Rust will let you bind `Sized` to a trait, you won’t be able to use it to form a trait object later:
```
trait Foo { }
trait Bar: Sized { }
struct Impl;
impl Foo for Impl { }
impl Bar for Impl { }
let x: &dyn Foo = &Impl; // OK
// let y: &dyn Bar = &Impl; // error: the trait `Bar` cannot
// be made into an object
```
Implementors
------------
rust Trait std::marker::Sync Trait std::marker::Sync
=======================
```
pub unsafe auto trait Sync { }
```
Types for which it is safe to share references between threads.
This trait is automatically implemented when the compiler determines it’s appropriate.
The precise definition is: a type `T` is [`Sync`](trait.sync "Sync") if and only if `&T` is [`Send`](trait.send "Send"). In other words, if there is no possibility of [undefined behavior](../../reference/behavior-considered-undefined) (including data races) when passing `&T` references between threads.
As one would expect, primitive types like [`u8`](../primitive.u8 "u8") and [`f64`](../primitive.f64 "f64") are all [`Sync`](trait.sync "Sync"), and so are simple aggregate types containing them, like tuples, structs and enums. More examples of basic [`Sync`](trait.sync "Sync") types include “immutable” types like `&T`, and those with simple inherited mutability, such as [`Box<T>`](../boxed/struct.box), [`Vec<T>`](../vec/struct.vec) and most other collection types. (Generic parameters need to be [`Sync`](trait.sync "Sync") for their container to be [`Sync`](trait.sync "Sync").)
A somewhat surprising consequence of the definition is that `&mut T` is `Sync` (if `T` is `Sync`) even though it seems like that might provide unsynchronized mutation. The trick is that a mutable reference behind a shared reference (that is, `& &mut T`) becomes read-only, as if it were a `& &T`. Hence there is no risk of a data race.
Types that are not `Sync` are those that have “interior mutability” in a non-thread-safe form, such as [`Cell`](../cell/struct.cell) and [`RefCell`](../cell/struct.refcell). These types allow for mutation of their contents even through an immutable, shared reference. For example the `set` method on [`Cell<T>`](../cell/struct.cell) takes `&self`, so it requires only a shared reference [`&Cell<T>`](../cell/struct.cell). The method performs no synchronization, thus [`Cell`](../cell/struct.cell) cannot be `Sync`.
Another example of a non-`Sync` type is the reference-counting pointer [`Rc`](../rc/struct.rc). Given any reference [`&Rc<T>`](../rc/struct.rc), you can clone a new [`Rc<T>`](../rc/struct.rc), modifying the reference counts in a non-atomic way.
For cases when one does need thread-safe interior mutability, Rust provides [atomic data types](../sync/atomic/index), as well as explicit locking via [`sync::Mutex`](../sync/struct.mutex) and [`sync::RwLock`](../sync/struct.rwlock). These types ensure that any mutation cannot cause data races, hence the types are `Sync`. Likewise, [`sync::Arc`](../sync/struct.arc) provides a thread-safe analogue of [`Rc`](../rc/struct.rc).
Any types with interior mutability must also use the [`cell::UnsafeCell`](../cell/struct.unsafecell) wrapper around the value(s) which can be mutated through a shared reference. Failing to doing this is [undefined behavior](../../reference/behavior-considered-undefined). For example, [`transmute`](../mem/fn.transmute)-ing from `&T` to `&mut T` is invalid.
See [the Nomicon](https://doc.rust-lang.org/nomicon/send-and-sync.html) for more details about `Sync`.
Implementors
------------
[source](https://doc.rust-lang.org/src/std/env.rs.html#799)1.26.0 · ### impl !Sync for Args
[source](https://doc.rust-lang.org/src/std/env.rs.html#840)1.26.0 · ### impl !Sync for ArgsOs
[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#135)1.63.0 · ### impl Sync for BorrowedHandle<'\_>
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#133)1.63.0 · ### impl Sync for HandleOrInvalid
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#131)1.63.0 · ### impl Sync for HandleOrNull
Available on **Windows** only.[source](https://doc.rust-lang.org/src/std/os/windows/io/handle.rs.html#129)1.63.0 · ### impl Sync for OwnedHandle
Available on **Windows** only.[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2876)1.6.0 · ### impl Sync for std::string::Drain<'\_>
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#162)### impl Sync for AtomicBool
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2675-2693)1.34.0 · ### impl Sync for AtomicI8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2715-2733)1.34.0 · ### impl Sync for AtomicI16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2755-2773)1.34.0 · ### impl Sync for AtomicI32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2795-2813)1.34.0 · ### impl Sync for AtomicI64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)### impl Sync for AtomicIsize
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2695-2713)1.34.0 · ### impl Sync for AtomicU8
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2735-2753)1.34.0 · ### impl Sync for AtomicU16
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2775-2793)1.34.0 · ### impl Sync for AtomicU32
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2815-2833)1.34.0 · ### impl Sync for AtomicU64
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#2922-2926)### impl Sync for AtomicUsize
[source](https://doc.rust-lang.org/src/std/sync/once.rs.html#126)### impl Sync for std::sync::Once
[source](https://doc.rust-lang.org/src/core/task/wake.rs.html#240)1.36.0 · ### impl Sync for Waker
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1211)1.44.0 · ### impl<'a> Sync for IoSlice<'a>
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1068)1.44.0 · ### impl<'a> Sync for IoSliceMut<'a>
[source](https://doc.rust-lang.org/src/core/ptr/metadata.rs.html#223)### impl<Dyn> Sync for DynMetadata<Dyn>where Dyn: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#481)### impl<T> !Sync for \*const Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/marker.rs.html#483)### impl<T> !Sync for \*mut Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/cell.rs.html#257)### impl<T> !Sync for Cell<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/cell.rs.html#1155)### impl<T> !Sync for RefCell<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/cell.rs.html#1873)### impl<T> !Sync for UnsafeCell<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#64)1.25.0 · ### impl<T> !Sync for NonNull<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
`NonNull` pointers are not `Sync` because the data they reference may be aliased.
[source](https://doc.rust-lang.org/src/alloc/rc.rs.html#323)### impl<T> !Sync for Rc<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/rc.rs.html#2159)1.4.0 · ### impl<T> !Sync for std::rc::Weak<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#353)### impl<T> !Sync for Receiver<T>
[source](https://doc.rust-lang.org/src/std/sync/mpsc/mod.rs.html#510)### impl<T> !Sync for Sender<T>
[source](https://doc.rust-lang.org/src/alloc/boxed/thin.rs.html#48)### impl<T> Sync for ThinBox<T>where T: [Sync](trait.sync "trait std::marker::Sync") + ?[Sized](trait.sized "trait std::marker::Sized"),
`ThinBox<T>` is `Sync` if `T` is `Sync` because the data is owned.
[source](https://doc.rust-lang.org/src/core/cell.rs.html#2039)### impl<T> Sync for SyncUnsafeCell<T>where T: [Sync](trait.sync "trait std::marker::Sync") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#2006)### impl<T> Sync for std::collections::linked\_list::Cursor<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#2012)### impl<T> Sync for CursorMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1994)### impl<T> Sync for std::collections::linked\_list::Iter<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#2000)### impl<T> Sync for std::collections::linked\_list::IterMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1988)### impl<T> Sync for LinkedList<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/iter_mut.rs.html#38)### impl<T> Sync for std::collections::vec\_deque::IterMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#2127)1.31.0 · ### impl<T> Sync for ChunksExactMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#1795)### impl<T> Sync for ChunksMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#82)### impl<T> Sync for std::slice::Iter<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#203)### impl<T> Sync for std::slice::IterMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#3193)1.31.0 · ### impl<T> Sync for RChunksExactMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/slice/iter.rs.html#2854)1.31.0 · ### impl<T> Sync for RChunksMut<'\_, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/core/sync/atomic.rs.html#195)### impl<T> Sync for AtomicPtr<T>
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#243)### impl<T> Sync for Arc<T>where T: [Sync](trait.sync "trait std::marker::Sync") + [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/sync/exclusive.rs.html#90)### impl<T> Sync for Exclusive<T>where T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/sync.rs.html#298)1.4.0 · ### impl<T> Sync for std::sync::Weak<T>where T: [Sync](trait.sync "trait std::marker::Sync") + [Send](trait.send "trait std::marker::Send") + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/std/thread/mod.rs.html#1463)1.29.0 · ### impl<T> Sync for JoinHandle<T>
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/drain.rs.html#60)1.6.0 · ### impl<T, A> Sync for std::collections::vec\_deque::Drain<'\_, T, A>where T: [Sync](trait.sync "trait std::marker::Sync"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/alloc/vec/drain.rs.html#149)1.6.0 · ### impl<T, A> Sync for std::vec::Drain<'\_, T, A>where T: [Sync](trait.sync "trait std::marker::Sync"), A: [Sync](trait.sync "trait std::marker::Sync") + [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/vec/into_iter.rs.html#142)### impl<T, A> Sync for std::vec::IntoIter<T, A>where T: [Sync](trait.sync "trait std::marker::Sync"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/std/sync/lazy_lock.rs.html#112)### impl<T, F: Send> Sync for LazyLock<T, F>where [OnceLock](../sync/struct.oncelock "struct std::sync::OnceLock")<T>: [Sync](trait.sync "trait std::marker::Sync"),
[source](https://doc.rust-lang.org/src/std/sync/once_lock.rs.html#336)### impl<T: Sync + Send> Sync for OnceLock<T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#88)### impl<T: ?Sized + Send + Sync> Sync for RwLock<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#176)### impl<T: ?Sized + Send> Sync for Mutex<T>
[source](https://doc.rust-lang.org/src/std/sync/mutex.rs.html#204)1.19.0 · ### impl<T: ?Sized + Sync> Sync for MutexGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#118)1.23.0 · ### impl<T: ?Sized + Sync> Sync for RwLockReadGuard<'\_, T>
[source](https://doc.rust-lang.org/src/std/sync/rwlock.rs.html#144)1.23.0 · ### impl<T: ?Sized + Sync> Sync for RwLockWriteGuard<'\_, T>
Auto implementors
-----------------
### impl !Sync for Vars
### impl !Sync for VarsOs
### impl !Sync for OnceState
### impl !Sync for RawWaker
### impl Sync for BacktraceStatus
### impl Sync for std::cmp::Ordering
### impl Sync for TryReserveErrorKind
### impl Sync for Infallible
### impl Sync for VarError
### impl Sync for c\_void
### impl Sync for std::fmt::Alignment
### impl Sync for ErrorKind
### impl Sync for SeekFrom
### impl Sync for IpAddr
### impl Sync for Ipv6MulticastScope
### impl Sync for Shutdown
### impl Sync for std::net::SocketAddr
### impl Sync for FpCategory
### impl Sync for IntErrorKind
### impl Sync for AncillaryError
### impl Sync for BacktraceStyle
### impl Sync for Which
### impl Sync for SearchStep
### impl Sync for std::sync::atomic::Ordering
### impl Sync for RecvTimeoutError
### impl Sync for TryRecvError
### impl Sync for bool
### impl Sync for char
### impl Sync for f32
### impl Sync for f64
### impl Sync for i8
### impl Sync for i16
### impl Sync for i32
### impl Sync for i64
### impl Sync for i128
### impl Sync for isize
### impl Sync for str
### impl Sync for u8
### impl Sync for u16
### impl Sync for u32
### impl Sync for u64
### impl Sync for u128
### impl Sync for ()
### impl Sync for usize
### impl Sync for AllocError
### impl Sync for Global
### impl Sync for Layout
### impl Sync for LayoutError
### impl Sync for System
### impl Sync for TypeId
### impl Sync for TryFromSliceError
### impl Sync for std::ascii::EscapeDefault
### impl Sync for Backtrace
### impl Sync for BacktraceFrame
### impl Sync for BorrowError
### impl Sync for BorrowMutError
### impl Sync for CharTryFromError
### impl Sync for DecodeUtf16Error
### impl Sync for std::char::EscapeDebug
### impl Sync for std::char::EscapeDefault
### impl Sync for std::char::EscapeUnicode
### impl Sync for ParseCharError
### impl Sync for ToLowercase
### impl Sync for ToUppercase
### impl Sync for TryFromCharError
### impl Sync for DefaultHasher
### impl Sync for RandomState
### impl Sync for TryReserveError
### impl Sync for JoinPathsError
### impl Sync for CStr
### impl Sync for CString
### impl Sync for FromBytesWithNulError
### impl Sync for FromVecWithNulError
### impl Sync for IntoStringError
### impl Sync for NulError
### impl Sync for OsStr
### impl Sync for OsString
### impl Sync for std::fmt::Error
### impl Sync for DirBuilder
### impl Sync for DirEntry
### impl Sync for File
### impl Sync for FileTimes
### impl Sync for FileType
### impl Sync for Metadata
### impl Sync for OpenOptions
### impl Sync for Permissions
### impl Sync for ReadDir
### impl Sync for SipHasher
### impl Sync for std::io::Empty
### impl Sync for std::io::Error
### impl Sync for std::io::Repeat
### impl Sync for Sink
### impl Sync for Stderr
### impl Sync for Stdin
### impl Sync for Stdout
### impl Sync for WriterPanicked
### impl Sync for Assume
### impl Sync for AddrParseError
### impl Sync for IntoIncoming
### impl Sync for Ipv4Addr
### impl Sync for Ipv6Addr
### impl Sync for SocketAddrV4
### impl Sync for SocketAddrV6
### impl Sync for TcpListener
### impl Sync for TcpStream
### impl Sync for UdpSocket
### impl Sync for NonZeroI8
### impl Sync for NonZeroI16
### impl Sync for NonZeroI32
### impl Sync for NonZeroI64
### impl Sync for NonZeroI128
### impl Sync for NonZeroIsize
### impl Sync for NonZeroU8
### impl Sync for NonZeroU16
### impl Sync for NonZeroU32
### impl Sync for NonZeroU64
### impl Sync for NonZeroU128
### impl Sync for NonZeroUsize
### impl Sync for ParseFloatError
### impl Sync for ParseIntError
### impl Sync for TryFromIntError
### impl Sync for RangeFull
### impl Sync for PidFd
### impl Sync for stat
### impl Sync for OwnedFd
### impl Sync for std::os::unix::net::SocketAddr
### impl Sync for SocketCred
### impl Sync for UnixDatagram
### impl Sync for UnixListener
### impl Sync for UnixStream
### impl Sync for UCred
### impl Sync for InvalidHandleError
### impl Sync for NullHandleError
### impl Sync for OwnedSocket
### impl Sync for Path
### impl Sync for PathBuf
### impl Sync for StripPrefixError
### impl Sync for Child
### impl Sync for ChildStderr
### impl Sync for ChildStdin
### impl Sync for ChildStdout
### impl Sync for Command
### impl Sync for ExitCode
### impl Sync for ExitStatus
### impl Sync for ExitStatusError
### impl Sync for Output
### impl Sync for Stdio
### impl Sync for ParseBoolError
### impl Sync for Utf8Error
### impl Sync for FromUtf8Error
### impl Sync for FromUtf16Error
### impl Sync for String
### impl Sync for RecvError
### impl Sync for Barrier
### impl Sync for BarrierWaitResult
### impl Sync for Condvar
### impl Sync for WaitTimeoutResult
### impl Sync for RawWakerVTable
### impl Sync for AccessError
### impl Sync for Builder
### impl Sync for Thread
### impl Sync for ThreadId
### impl Sync for Duration
### impl Sync for FromFloatSecsError
### impl Sync for Instant
### impl Sync for SystemTime
### impl Sync for SystemTimeError
### impl Sync for PhantomPinned
### impl Sync for Alignment
### impl Sync for Argument
### impl Sync for Count
### impl Sync for FormatSpec
### impl<'a> !Sync for Demand<'a>
### impl<'a> !Sync for Arguments<'a>
### impl<'a> !Sync for Formatter<'a>
### impl<'a> !Sync for PanicInfo<'a>
### impl<'a> Sync for AncillaryData<'a>
### impl<'a> Sync for Component<'a>
### impl<'a> Sync for Prefix<'a>
### impl<'a> Sync for SplitPaths<'a>
### impl<'a> Sync for BorrowedCursor<'a>
### impl<'a> Sync for StderrLock<'a>
### impl<'a> Sync for StdinLock<'a>
### impl<'a> Sync for StdoutLock<'a>
### impl<'a> Sync for std::net::Incoming<'a>
### impl<'a> Sync for std::os::unix::net::Incoming<'a>
### impl<'a> Sync for Messages<'a>
### impl<'a> Sync for ScmCredentials<'a>
### impl<'a> Sync for ScmRights<'a>
### impl<'a> Sync for SocketAncillary<'a>
### impl<'a> Sync for EncodeWide<'a>
### impl<'a> Sync for Location<'a>
### impl<'a> Sync for Ancestors<'a>
### impl<'a> Sync for Components<'a>
### impl<'a> Sync for Display<'a>
### impl<'a> Sync for std::path::Iter<'a>
### impl<'a> Sync for PrefixComponent<'a>
### impl<'a> Sync for CommandArgs<'a>
### impl<'a> Sync for CommandEnvs<'a>
### impl<'a> Sync for EscapeAscii<'a>
### impl<'a> Sync for CharSearcher<'a>
### impl<'a> Sync for std::str::Bytes<'a>
### impl<'a> Sync for CharIndices<'a>
### impl<'a> Sync for Chars<'a>
### impl<'a> Sync for EncodeUtf16<'a>
### impl<'a> Sync for std::str::EscapeDebug<'a>
### impl<'a> Sync for std::str::EscapeDefault<'a>
### impl<'a> Sync for std::str::EscapeUnicode<'a>
### impl<'a> Sync for std::str::Lines<'a>
### impl<'a> Sync for LinesAny<'a>
### impl<'a> Sync for SplitAsciiWhitespace<'a>
### impl<'a> Sync for SplitWhitespace<'a>
### impl<'a> Sync for Utf8Chunk<'a>
### impl<'a> Sync for Utf8Chunks<'a>
### impl<'a> Sync for Context<'a>
### impl<'a, 'b> !Sync for DebugList<'a, 'b>
### impl<'a, 'b> !Sync for DebugMap<'a, 'b>
### impl<'a, 'b> !Sync for DebugSet<'a, 'b>
### impl<'a, 'b> !Sync for DebugStruct<'a, 'b>
### impl<'a, 'b> !Sync for DebugTuple<'a, 'b>
### impl<'a, 'b> Sync for CharSliceSearcher<'a, 'b>
### impl<'a, 'b> Sync for StrSearcher<'a, 'b>
### impl<'a, 'b, const N: usize> Sync for CharArrayRefSearcher<'a, 'b, N>
### impl<'a, 'f> !Sync for VaList<'a, 'f>
### impl<'a, A> Sync for std::option::Iter<'a, A>where A: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, A> Sync for std::option::IterMut<'a, A>where A: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, B: ?Sized> Sync for Cow<'a, B>where B: [Sync](trait.sync "trait std::marker::Sync"), <B as [ToOwned](../borrow/trait.toowned "trait std::borrow::ToOwned")>::[Owned](../borrow/trait.toowned#associatedtype.Owned "type std::borrow::ToOwned::Owned"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, F> Sync for CharPredicateSearcher<'a, F>where F: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, I> Sync for ByRefSized<'a, I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, I, A> Sync for Splice<'a, I, A>where A: [Sync](trait.sync "trait std::marker::Sync"), I: [Sync](trait.sync "trait std::marker::Sync"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K> Sync for std::collections::hash\_set::Drain<'a, K>where K: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K> Sync for std::collections::hash\_set::Iter<'a, K>where K: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, F> Sync for std::collections::hash\_set::DrainFilter<'a, K, F>where F: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::Entry<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::btree\_map::Iter<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::btree\_map::IterMut<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::btree\_map::Keys<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::btree\_map::Range<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for RangeMut<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::btree\_map::Values<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::btree\_map::ValuesMut<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::Drain<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::Iter<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::IterMut<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::Keys<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::OccupiedEntry<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::OccupiedError<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::VacantEntry<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::Values<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for std::collections::hash\_map::ValuesMut<'a, K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Sync for std::collections::btree\_map::Entry<'a, K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Sync for std::collections::btree\_map::OccupiedEntry<'a, K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Sync for std::collections::btree\_map::OccupiedError<'a, K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Sync for std::collections::btree\_map::VacantEntry<'a, K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, F> Sync for std::collections::hash\_map::DrainFilter<'a, K, V, F>where F: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, F, A> Sync for std::collections::btree\_map::DrainFilter<'a, K, V, F, A>where A: [Sync](trait.sync "trait std::marker::Sync"), F: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Sync for RawEntryMut<'a, K, V, S>where K: [Sync](trait.sync "trait std::marker::Sync"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Sync for RawEntryBuilder<'a, K, V, S>where K: [Sync](trait.sync "trait std::marker::Sync"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Sync for RawEntryBuilderMut<'a, K, V, S>where K: [Sync](trait.sync "trait std::marker::Sync"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Sync for RawOccupiedEntryMut<'a, K, V, S>where K: [Sync](trait.sync "trait std::marker::Sync"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Sync for RawVacantEntryMut<'a, K, V, S>where K: [Sync](trait.sync "trait std::marker::Sync"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for MatchIndices<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for Matches<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for RMatchIndices<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for RMatches<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for std::str::RSplit<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for std::str::RSplitN<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for RSplitTerminator<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for std::str::Split<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for std::str::SplitInclusive<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for std::str::SplitN<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, P> Sync for SplitTerminator<'a, P>where <P as [Pattern](../str/pattern/trait.pattern "trait std::str::pattern::Pattern")<'a>>::[Searcher](../str/pattern/trait.pattern#associatedtype.Searcher "type std::str::pattern::Pattern::Searcher"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> !Sync for std::sync::mpsc::Iter<'a, T>
### impl<'a, T> !Sync for TryIter<'a, T>
### impl<'a, T> Sync for std::collections::binary\_heap::Drain<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for DrainSorted<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::collections::binary\_heap::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for PeekMut<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::collections::btree\_set::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::collections::btree\_set::Range<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::collections::btree\_set::SymmetricDifference<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::collections::btree\_set::Union<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::collections::vec\_deque::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::result::Iter<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for std::result::IterMut<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for Chunks<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for ChunksExact<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for RChunks<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for RChunksExact<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for Windows<'a, T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Sync for std::collections::btree\_set::Difference<'a, T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Sync for std::collections::btree\_set::Intersection<'a, T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, F> !Sync for std::collections::linked\_list::DrainFilter<'a, T, F>
### impl<'a, T, F, A> Sync for std::collections::btree\_set::DrainFilter<'a, T, F, A>where A: [Sync](trait.sync "trait std::marker::Sync"), F: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, F, A> Sync for std::vec::DrainFilter<'a, T, F, A>where A: [Sync](trait.sync "trait std::marker::Sync"), F: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for GroupBy<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for GroupByMut<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for std::slice::RSplit<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for RSplitMut<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for std::slice::RSplitN<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for RSplitNMut<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for std::slice::Split<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for std::slice::SplitInclusive<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for SplitInclusiveMut<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for SplitMut<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for std::slice::SplitN<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, P> Sync for SplitNMut<'a, T, P>where P: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, S> Sync for std::collections::hash\_set::Difference<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, S> Sync for std::collections::hash\_set::Intersection<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, S> Sync for std::collections::hash\_set::SymmetricDifference<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, S> Sync for std::collections::hash\_set::Union<'a, T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, const N: usize> !Sync for ArrayWindows<'a, T, N>
### impl<'a, T, const N: usize> Sync for std::slice::ArrayChunks<'a, T, N>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, T, const N: usize> Sync for ArrayChunksMut<'a, T, N>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<'a, const N: usize> Sync for CharArraySearcher<'a, N>
### impl<'b, T> !Sync for Ref<'b, T>
### impl<'b, T> !Sync for RefMut<'b, T>
### impl<'data> Sync for BorrowedBuf<'data>
### impl<'f> !Sync for VaListImpl<'f>
### impl<'fd> Sync for BorrowedFd<'fd>
### impl<'scope, 'env> Sync for Scope<'scope, 'env>
### impl<'scope, T> Sync for ScopedJoinHandle<'scope, T>where T: [Send](trait.send "trait std::marker::Send") + [Sync](trait.sync "trait std::marker::Sync"),
### impl<'socket> Sync for BorrowedSocket<'socket>
### impl<A> Sync for std::iter::Repeat<A>where A: [Sync](trait.sync "trait std::marker::Sync"),
### impl<A> Sync for std::option::IntoIter<A>where A: [Sync](trait.sync "trait std::marker::Sync"),
### impl<A, B> Sync for std::iter::Chain<A, B>where A: [Sync](trait.sync "trait std::marker::Sync"), B: [Sync](trait.sync "trait std::marker::Sync"),
### impl<A, B> Sync for Zip<A, B>where A: [Sync](trait.sync "trait std::marker::Sync"), B: [Sync](trait.sync "trait std::marker::Sync"),
### impl<B> Sync for std::io::Lines<B>where B: [Sync](trait.sync "trait std::marker::Sync"),
### impl<B> Sync for std::io::Split<B>where B: [Sync](trait.sync "trait std::marker::Sync"),
### impl<B, C> Sync for ControlFlow<B, C>where B: [Sync](trait.sync "trait std::marker::Sync"), C: [Sync](trait.sync "trait std::marker::Sync"),
### impl<E> Sync for Report<E>where E: [Sync](trait.sync "trait std::marker::Sync"),
### impl<F> Sync for PollFn<F>where F: [Sync](trait.sync "trait std::marker::Sync"),
### impl<F> Sync for FromFn<F>where F: [Sync](trait.sync "trait std::marker::Sync"),
### impl<F> Sync for OnceWith<F>where F: [Sync](trait.sync "trait std::marker::Sync"),
### impl<F> Sync for RepeatWith<F>where F: [Sync](trait.sync "trait std::marker::Sync"),
### impl<H> Sync for BuildHasherDefault<H>
### impl<I> Sync for FromIter<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for DecodeUtf16<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Cloned<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Copied<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Cycle<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Enumerate<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Flatten<I>where I: [Sync](trait.sync "trait std::marker::Sync"), <<I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item") as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[IntoIter](../iter/trait.intoiterator#associatedtype.IntoIter "type std::iter::IntoIterator::IntoIter"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Fuse<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Intersperse<I>where I: [Sync](trait.sync "trait std::marker::Sync"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Peekable<I>where I: [Sync](trait.sync "trait std::marker::Sync"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for Skip<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for StepBy<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I> Sync for std::iter::Take<I>where I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, F> Sync for FilterMap<I, F>where F: [Sync](trait.sync "trait std::marker::Sync"), I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, F> Sync for Inspect<I, F>where F: [Sync](trait.sync "trait std::marker::Sync"), I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, F> Sync for Map<I, F>where F: [Sync](trait.sync "trait std::marker::Sync"), I: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, G> Sync for IntersperseWith<I, G>where G: [Sync](trait.sync "trait std::marker::Sync"), I: [Sync](trait.sync "trait std::marker::Sync"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, P> Sync for Filter<I, P>where I: [Sync](trait.sync "trait std::marker::Sync"), P: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, P> Sync for MapWhile<I, P>where I: [Sync](trait.sync "trait std::marker::Sync"), P: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, P> Sync for SkipWhile<I, P>where I: [Sync](trait.sync "trait std::marker::Sync"), P: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, P> Sync for TakeWhile<I, P>where I: [Sync](trait.sync "trait std::marker::Sync"), P: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, St, F> Sync for Scan<I, St, F>where F: [Sync](trait.sync "trait std::marker::Sync"), I: [Sync](trait.sync "trait std::marker::Sync"), St: [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, U, F> Sync for FlatMap<I, U, F>where F: [Sync](trait.sync "trait std::marker::Sync"), I: [Sync](trait.sync "trait std::marker::Sync"), <U as [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[IntoIter](../iter/trait.intoiterator#associatedtype.IntoIter "type std::iter::IntoIterator::IntoIter"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<I, const N: usize> Sync for std::iter::ArrayChunks<I, N>where I: [Sync](trait.sync "trait std::marker::Sync"), <I as [Iterator](../iter/trait.iterator "trait std::iter::Iterator")>::[Item](../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [Sync](trait.sync "trait std::marker::Sync"),
### impl<Idx> Sync for std::ops::Range<Idx>where Idx: [Sync](trait.sync "trait std::marker::Sync"),
### impl<Idx> Sync for RangeFrom<Idx>where Idx: [Sync](trait.sync "trait std::marker::Sync"),
### impl<Idx> Sync for RangeInclusive<Idx>where Idx: [Sync](trait.sync "trait std::marker::Sync"),
### impl<Idx> Sync for RangeTo<Idx>where Idx: [Sync](trait.sync "trait std::marker::Sync"),
### impl<Idx> Sync for RangeToInclusive<Idx>where Idx: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K> Sync for std::collections::hash\_set::IntoIter<K>where K: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V> Sync for std::collections::hash\_map::IntoIter<K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V> Sync for std::collections::hash\_map::IntoKeys<K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V> Sync for std::collections::hash\_map::IntoValues<K, V>where K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Sync for std::collections::btree\_map::IntoIter<K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Sync for std::collections::btree\_map::IntoKeys<K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Sync for std::collections::btree\_map::IntoValues<K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Sync for BTreeMap<K, V, A>where A: [Sync](trait.sync "trait std::marker::Sync"), K: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<K, V, S> Sync for HashMap<K, V, S>where K: [Sync](trait.sync "trait std::marker::Sync"), S: [Sync](trait.sync "trait std::marker::Sync"), V: [Sync](trait.sync "trait std::marker::Sync"),
### impl<P> Sync for Pin<P>where P: [Sync](trait.sync "trait std::marker::Sync"),
### impl<R> Sync for BufReader<R>where R: [Sync](trait.sync "trait std::marker::Sync"),
### impl<R> Sync for std::io::Bytes<R>where R: [Sync](trait.sync "trait std::marker::Sync"),
### impl<Ret, T> Sync for fn (T₁, T₂, …, Tₙ) -> Ret
### impl<T> !Sync for OnceCell<T>
### impl<T> !Sync for std::sync::mpsc::IntoIter<T>
### impl<T> Sync for Bound<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Option<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for TryLockError<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for TrySendError<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Poll<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for [T]where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for (T₁, T₂, …, Tₙ)where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Reverse<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for std::collections::binary\_heap::IntoIter<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for IntoIterSorted<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for std::collections::linked\_list::IntoIter<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for BinaryHeap<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Pending<T>
### impl<T> Sync for std::future::Ready<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for std::io::Cursor<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for std::io::Take<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for std::iter::Empty<T>
### impl<T> Sync for std::iter::Once<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Rev<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Discriminant<T>
### impl<T> Sync for Saturating<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Wrapping<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for Yeet<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for AssertUnwindSafe<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for std::result::IntoIter<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for SendError<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for SyncSender<T>where T: [Send](trait.send "trait std::marker::Send"),
### impl<T> Sync for PoisonError<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for std::task::Ready<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T> Sync for LocalKey<T>
### impl<T> Sync for MaybeUninit<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, A> Sync for std::collections::btree\_set::IntoIter<T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, A> Sync for BTreeSet<T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, A> Sync for VecDeque<T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, A> Sync for std::collections::vec\_deque::IntoIter<T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, A> Sync for Vec<T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, E> Sync for Result<T, E>where E: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, F> Sync for Successors<T, F>where F: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, F = fn() -> T> !Sync for LazyCell<T, F>
### impl<T, S> Sync for HashSet<T, S>where S: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, U> Sync for std::io::Chain<T, U>where T: [Sync](trait.sync "trait std::marker::Sync"), U: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, const LANES: usize> Sync for Mask<T, LANES>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, const LANES: usize> Sync for Simd<T, LANES>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, const N: usize> Sync for [T; N]where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T, const N: usize> Sync for std::array::IntoIter<T, N>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T: ?Sized> Sync for ManuallyDrop<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T: ?Sized> Sync for PhantomData<T>where T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<T: ?Sized, A> Sync for Box<T, A>where A: [Sync](trait.sync "trait std::marker::Sync"), T: [Sync](trait.sync "trait std::marker::Sync"),
### impl<W> Sync for BufWriter<W>where W: [Sync](trait.sync "trait std::marker::Sync"),
### impl<W> Sync for IntoInnerError<W>where W: [Sync](trait.sync "trait std::marker::Sync"),
### impl<W> Sync for LineWriter<W>where W: [Sync](trait.sync "trait std::marker::Sync"),
### impl<Y, R> Sync for GeneratorState<Y, R>where R: [Sync](trait.sync "trait std::marker::Sync"), Y: [Sync](trait.sync "trait std::marker::Sync"),
### impl<const LANES: usize> Sync for LaneCount<LANES>
| programming_docs |
rust Struct std::marker::PhantomPinned Struct std::marker::PhantomPinned
=================================
```
pub struct PhantomPinned;
```
A marker type which does not implement `Unpin`.
If a type contains a `PhantomPinned`, it will not implement `Unpin` by default.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl Clone for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)#### fn clone(&self) -> PhantomPinned
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl Debug for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl Default for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)#### fn default() -> PhantomPinned
Returns the “default value” for a type. [Read more](../default/trait.default#tymethod.default)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl Hash for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)#### fn hash<\_\_H>(&self, state: &mut \_\_H)where \_\_H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl Ord for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)#### fn cmp(&self, other: &PhantomPinned) -> Ordering
This method returns an [`Ordering`](../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl PartialEq<PhantomPinned> for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)#### fn eq(&self, other: &PhantomPinned) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl PartialOrd<PhantomPinned> for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)#### fn partial\_cmp(&self, other: &PhantomPinned) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)1.0.0 · #### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)1.0.0 · #### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)1.0.0 · #### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)1.0.0 · #### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl Copy for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl Eq for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl StructuralEq for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#776)### impl StructuralPartialEq for PhantomPinned
[source](https://doc.rust-lang.org/src/core/marker.rs.html#780)### impl !Unpin for PhantomPinned
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for PhantomPinned
### impl Send for PhantomPinned
### impl Sync for PhantomPinned
### impl UnwindSafe for PhantomPinned
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Trait std::marker::Destruct Trait std::marker::Destruct
===========================
```
pub trait Destruct { }
```
🔬This is a nightly-only experimental API. (`const_trait_impl` [#67792](https://github.com/rust-lang/rust/issues/67792))
A marker for types that can be dropped.
This should be used for `~const` bounds, as non-const bounds will always hold for every type.
Implementors
------------
rust Module std::u128 Module std::u128
================
👎Deprecating in a future Rust version: all constants in this module replaced by associated constants on `u128`
Constants for the 128-bit unsigned integer type.
*[See also the `u128` primitive type](../primitive.u128 "u128").*
New code should use the associated constants directly on the primitive type.
Constants
---------
[MAX](constant.max "std::u128::MAX constant")Deprecation planned
The largest value that can be represented by this integer type. Use [`u128::MAX`](../primitive.u128#associatedconstant.MAX "u128::MAX") instead.
[MIN](constant.min "std::u128::MIN constant")Deprecation planned
The smallest value that can be represented by this integer type. Use [`u128::MIN`](../primitive.u128#associatedconstant.MIN "u128::MIN") instead.
rust Constant std::u128::MAX Constant std::u128::MAX
=======================
```
pub const MAX: u128 = u128::MAX; // 340_282_366_920_938_463_463_374_607_431_768_211_455u128
```
👎Deprecating in a future Rust version: replaced by the `MAX` associated constant on this type
The largest value that can be represented by this integer type. Use [`u128::MAX`](../primitive.u128#associatedconstant.MAX "u128::MAX") instead.
Examples
--------
```
// deprecated way
let max = std::u128::MAX;
// intended way
let max = u128::MAX;
```
rust Constant std::u128::MIN Constant std::u128::MIN
=======================
```
pub const MIN: u128 = u128::MIN; // 0u128
```
👎Deprecating in a future Rust version: replaced by the `MIN` associated constant on this type
The smallest value that can be represented by this integer type. Use [`u128::MIN`](../primitive.u128#associatedconstant.MIN "u128::MIN") instead.
Examples
--------
```
// deprecated way
let min = std::u128::MIN;
// intended way
let min = u128::MIN;
```
rust Module std::i16 Module std::i16
===============
👎Deprecating in a future Rust version: all constants in this module replaced by associated constants on `i16`
Constants for the 16-bit signed integer type.
*[See also the `i16` primitive type](../primitive.i16 "i16").*
New code should use the associated constants directly on the primitive type.
Constants
---------
[MAX](constant.max "std::i16::MAX constant")Deprecation planned
The largest value that can be represented by this integer type. Use [`i16::MAX`](../primitive.i16#associatedconstant.MAX "i16::MAX") instead.
[MIN](constant.min "std::i16::MIN constant")Deprecation planned
The smallest value that can be represented by this integer type. Use [`i16::MIN`](../primitive.i16#associatedconstant.MIN "i16::MIN") instead.
rust Constant std::i16::MAX Constant std::i16::MAX
======================
```
pub const MAX: i16 = i16::MAX; // 32_767i16
```
👎Deprecating in a future Rust version: replaced by the `MAX` associated constant on this type
The largest value that can be represented by this integer type. Use [`i16::MAX`](../primitive.i16#associatedconstant.MAX "i16::MAX") instead.
Examples
--------
```
// deprecated way
let max = std::i16::MAX;
// intended way
let max = i16::MAX;
```
rust Constant std::i16::MIN Constant std::i16::MIN
======================
```
pub const MIN: i16 = i16::MIN; // -32_768i16
```
👎Deprecating in a future Rust version: replaced by the `MIN` associated constant on this type
The smallest value that can be represented by this integer type. Use [`i16::MIN`](../primitive.i16#associatedconstant.MIN "i16::MIN") instead.
Examples
--------
```
// deprecated way
let min = std::i16::MIN;
// intended way
let min = i16::MIN;
```
rust Struct std::collections::BinaryHeap Struct std::collections::BinaryHeap
===================================
```
pub struct BinaryHeap<T> { /* private fields */ }
```
A priority queue implemented with a binary heap.
This will be a max-heap.
It is a logic error for an item to be modified in such a way that the item’s ordering relative to any other item, as determined by the [`Ord`](../cmp/trait.ord) trait, changes while it is in the heap. This is normally only possible through [`Cell`](../cell/struct.cell), [`RefCell`](../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `BinaryHeap` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
Examples
--------
```
use std::collections::BinaryHeap;
// Type inference lets us omit an explicit type signature (which
// would be `BinaryHeap<i32>` in this example).
let mut heap = BinaryHeap::new();
// We can use peek to look at the next item in the heap. In this case,
// there's no items in there yet so we get None.
assert_eq!(heap.peek(), None);
// Let's add some scores...
heap.push(1);
heap.push(5);
heap.push(2);
// Now peek shows the most important item in the heap.
assert_eq!(heap.peek(), Some(&5));
// We can check the length of a heap.
assert_eq!(heap.len(), 3);
// We can iterate over the items in the heap, although they are returned in
// a random order.
for x in &heap {
println!("{x}");
}
// If we instead pop these scores, they should come back in order.
assert_eq!(heap.pop(), Some(5));
assert_eq!(heap.pop(), Some(2));
assert_eq!(heap.pop(), Some(1));
assert_eq!(heap.pop(), None);
// We can clear the heap of any remaining items.
heap.clear();
// The heap should now be empty.
assert!(heap.is_empty())
```
A `BinaryHeap` with a known list of items can be initialized from an array:
```
use std::collections::BinaryHeap;
let heap = BinaryHeap::from([1, 5, 2]);
```
### Min-heap
Either [`core::cmp::Reverse`](../cmp/struct.reverse) or a custom [`Ord`](../cmp/trait.ord) implementation can be used to make `BinaryHeap` a min-heap. This makes `heap.pop()` return the smallest value instead of the greatest one.
```
use std::collections::BinaryHeap;
use std::cmp::Reverse;
let mut heap = BinaryHeap::new();
// Wrap values in `Reverse`
heap.push(Reverse(1));
heap.push(Reverse(5));
heap.push(Reverse(2));
// If we pop these scores now, they should come back in the reverse order.
assert_eq!(heap.pop(), Some(Reverse(1)));
assert_eq!(heap.pop(), Some(Reverse(2)));
assert_eq!(heap.pop(), Some(Reverse(5)));
assert_eq!(heap.pop(), None);
```
Time complexity
---------------
| [push](struct.binaryheap#method.push) | [pop](struct.binaryheap#method.pop) | [peek](struct.binaryheap#method.peek)/[peek\_mut](struct.binaryheap#method.peek_mut) |
| --- | --- | --- |
| *O*(1)~ | *O*(log(*n*)) | *O*(1) |
The value for `push` is an expected cost; the method documentation gives a more detailed analysis.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#359)### impl<T> BinaryHeap<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#373)#### pub fn new() -> BinaryHeap<T>
Creates an empty `BinaryHeap` as a max-heap.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();
heap.push(4);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#394)#### pub fn with\_capacity(capacity: usize) -> BinaryHeap<T>
Creates an empty `BinaryHeap` with at least the specified capacity.
The binary heap will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is 0, the binary heap will not allocate.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::with_capacity(10);
heap.push(4);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#428)1.12.0 · #### pub fn peek\_mut(&mut self) -> Option<PeekMut<'\_, T>>
Returns a mutable reference to the greatest item in the binary heap, or `None` if it is empty.
Note: If the `PeekMut` value is leaked, the heap may be in an inconsistent state.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();
assert!(heap.peek_mut().is_none());
heap.push(1);
heap.push(5);
heap.push(2);
{
let mut val = heap.peek_mut().unwrap();
*val = 0;
}
assert_eq!(heap.peek(), Some(&2));
```
##### Time complexity
If the item is modified then the worst case time complexity is *O*(log(*n*)), otherwise it’s *O*(1).
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#452)#### pub fn pop(&mut self) -> Option<T>
Removes the greatest item from the binary heap and returns it, or `None` if it is empty.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::from([1, 3]);
assert_eq!(heap.pop(), Some(3));
assert_eq!(heap.pop(), Some(1));
assert_eq!(heap.pop(), None);
```
##### Time complexity
The worst case cost of `pop` on a heap containing *n* elements is *O*(log(*n*)).
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#496)#### pub fn push(&mut self, item: T)
Pushes an item onto the binary heap.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();
heap.push(3);
heap.push(5);
heap.push(1);
assert_eq!(heap.len(), 3);
assert_eq!(heap.peek(), Some(&5));
```
##### Time complexity
The expected cost of `push`, averaged over every possible ordering of the elements being pushed, and over a sufficiently large number of pushes, is *O*(1). This is the most meaningful cost metric when pushing elements that are *not* already in any sorted pattern.
The time complexity degrades if elements are pushed in predominantly ascending order. In the worst case, elements are pushed in ascending sorted order and the amortized cost per push is *O*(log(*n*)) against a heap containing *n* elements.
The worst case cost of a *single* call to `push` is *O*(*n*). The worst case occurs when capacity is exhausted and needs a resize. The resize cost has been amortized in the previous figures.
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#523)1.5.0 · #### pub fn into\_sorted\_vec(self) -> Vec<T, Global>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Consumes the `BinaryHeap` and returns a vector in sorted (ascending) order.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::from([1, 2, 4, 5, 7]);
heap.push(6);
heap.push(3);
let vec = heap.into_sorted_vec();
assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#742)1.11.0 · #### pub fn append(&mut self, other: &mut BinaryHeap<T>)
Moves all the elements of `other` into `self`, leaving `other` empty.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut a = BinaryHeap::from([-10, 1, 2, 3, 3]);
let mut b = BinaryHeap::from([-20, 5, 43]);
a.append(&mut b);
assert_eq!(a.into_sorted_vec(), [-20, -10, 1, 2, 3, 3, 5, 43]);
assert!(b.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#781)#### pub fn drain\_sorted(&mut self) -> DrainSorted<'\_, T>
Notable traits for [DrainSorted](binary_heap/struct.drainsorted "struct std::collections::binary_heap::DrainSorted")<'\_, T>
```
impl<T> Iterator for DrainSorted<'_, T>where
T: Ord,
type Item = T;
```
🔬This is a nightly-only experimental API. (`binary_heap_drain_sorted` [#59278](https://github.com/rust-lang/rust/issues/59278))
Clears the binary heap, returning an iterator over the removed elements in heap order. If the iterator is dropped before being fully consumed, it drops the remaining elements in heap order.
The returned iterator keeps a mutable borrow on the heap to optimize its implementation.
Note:
* `.drain_sorted()` is *O*(*n* \* log(*n*)); much slower than `.drain()`. You should use the latter for most cases.
##### Examples
Basic usage:
```
#![feature(binary_heap_drain_sorted)]
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::from([1, 2, 3, 4, 5]);
assert_eq!(heap.len(), 5);
drop(heap.drain_sorted()); // removes all elements in heap order
assert_eq!(heap.len(), 0);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#805-807)#### pub fn retain<F>(&mut self, f: F)where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
🔬This is a nightly-only experimental API. (`binary_heap_retain` [#71503](https://github.com/rust-lang/rust/issues/71503))
Retains only the elements specified by the predicate.
In other words, remove all elements `e` for which `f(&e)` returns `false`. The elements are visited in unsorted (and unspecified) order.
##### Examples
Basic usage:
```
#![feature(binary_heap_retain)]
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::from([-10, -5, 1, 2, 4, 13]);
heap.retain(|x| x % 2 == 0); // only keep even numbers
assert_eq!(heap.into_sorted_vec(), [-10, 2, 4])
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#824)### impl<T> BinaryHeap<T>
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#842)#### pub fn iter(&self) -> Iter<'\_, T>
Notable traits for [Iter](binary_heap/struct.iter "struct std::collections::binary_heap::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Returns an iterator visiting all values in the underlying vector, in arbitrary order.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let heap = BinaryHeap::from([1, 2, 3, 4]);
// Print 1, 2, 3, 4 in arbitrary order
for x in heap.iter() {
println!("{x}");
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#861)#### pub fn into\_iter\_sorted(self) -> IntoIterSorted<T>
Notable traits for [IntoIterSorted](binary_heap/struct.intoitersorted "struct std::collections::binary_heap::IntoIterSorted")<T>
```
impl<T> Iterator for IntoIterSorted<T>where
T: Ord,
type Item = T;
```
🔬This is a nightly-only experimental API. (`binary_heap_into_iter_sorted` [#59278](https://github.com/rust-lang/rust/issues/59278))
Returns an iterator which retrieves elements in heap order. This method consumes the original heap.
##### Examples
Basic usage:
```
#![feature(binary_heap_into_iter_sorted)]
use std::collections::BinaryHeap;
let heap = BinaryHeap::from([1, 2, 3, 4, 5]);
assert_eq!(heap.into_iter_sorted().take(2).collect::<Vec<_>>(), [5, 4]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#888)#### pub fn peek(&self) -> Option<&T>
Returns the greatest item in the binary heap, or `None` if it is empty.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();
assert_eq!(heap.peek(), None);
heap.push(1);
heap.push(5);
heap.push(2);
assert_eq!(heap.peek(), Some(&5));
```
##### Time complexity
Cost is *O*(1) in the worst case.
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#906)#### pub fn capacity(&self) -> usize
Returns the number of elements the binary heap can hold without reallocating.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::with_capacity(100);
assert!(heap.capacity() >= 100);
heap.push(4);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#937)#### pub fn reserve\_exact(&mut self, additional: usize)
Reserves the minimum capacity for at least `additional` elements more than the current length. Unlike [`reserve`](struct.binaryheap#method.reserve), this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling `reserve_exact`, capacity will be greater than or equal to `self.len() + additional`. Does nothing if the capacity is already sufficient.
##### Panics
Panics if the new capacity overflows [`usize`](../primitive.usize "usize").
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();
heap.reserve_exact(100);
assert!(heap.capacity() >= 100);
heap.push(4);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#963)#### pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least `additional` elements more than the current length. The allocator may reserve more space to speculatively avoid frequent allocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional`. Does nothing if capacity is already sufficient.
##### Panics
Panics if the new capacity overflows [`usize`](../primitive.usize "usize").
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();
heap.reserve(100);
assert!(heap.capacity() >= 100);
heap.push(4);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1005)1.63.0 · #### pub fn try\_reserve\_exact( &mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve the minimum capacity for at least `additional` elements more than the current length. Unlike [`try_reserve`](struct.binaryheap#method.try_reserve), this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling `try_reserve_exact`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer [`try_reserve`](struct.binaryheap#method.try_reserve) if future insertions are expected.
##### Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::BinaryHeap;
use std::collections::TryReserveError;
fn find_max_slow(data: &[u32]) -> Result<Option<u32>, TryReserveError> {
let mut heap = BinaryHeap::new();
// Pre-reserve the memory, exiting if we can't
heap.try_reserve_exact(data.len())?;
// Now we know this can't OOM in the middle of our complex work
heap.extend(data.iter());
Ok(heap.pop())
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1041)1.63.0 · #### pub fn try\_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least `additional` elements more than the current length. The allocator may reserve more space to speculatively avoid frequent allocations. After calling `try_reserve`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if capacity is already sufficient. This method preserves the contents even if an error occurs.
##### Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::BinaryHeap;
use std::collections::TryReserveError;
fn find_max_slow(data: &[u32]) -> Result<Option<u32>, TryReserveError> {
let mut heap = BinaryHeap::new();
// Pre-reserve the memory, exiting if we can't
heap.try_reserve(data.len())?;
// Now we know this can't OOM in the middle of our complex work
heap.extend(data.iter());
Ok(heap.pop())
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1060)#### pub fn shrink\_to\_fit(&mut self)
Discards as much additional capacity as possible.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap: BinaryHeap<i32> = BinaryHeap::with_capacity(100);
assert!(heap.capacity() >= 100);
heap.shrink_to_fit();
assert!(heap.capacity() == 0);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1083)1.56.0 · #### pub fn shrink\_to(&mut self, min\_capacity: usize)
Discards capacity with a lower bound.
The capacity will remain at least as large as both the length and the supplied value.
If the current capacity is less than the lower limit, this is a no-op.
##### Examples
```
use std::collections::BinaryHeap;
let mut heap: BinaryHeap<i32> = BinaryHeap::with_capacity(100);
assert!(heap.capacity() >= 100);
heap.shrink_to(10);
assert!(heap.capacity() >= 10);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1105)#### pub fn as\_slice(&self) -> &[T]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
🔬This is a nightly-only experimental API. (`binary_heap_as_slice` [#83659](https://github.com/rust-lang/rust/issues/83659))
Returns a slice of all values in the underlying vector, in arbitrary order.
##### Examples
Basic usage:
```
#![feature(binary_heap_as_slice)]
use std::collections::BinaryHeap;
use std::io::{self, Write};
let heap = BinaryHeap::from([1, 2, 3, 4, 5, 6, 7]);
io::sink().write(heap.as_slice()).unwrap();
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1128)1.5.0 · #### pub fn into\_vec(self) -> Vec<T, Global>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Consumes the `BinaryHeap` and returns the underlying vector in arbitrary order.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let heap = BinaryHeap::from([1, 2, 3, 4, 5, 6, 7]);
let vec = heap.into_vec();
// Will print in some order
for x in vec {
println!("{x}");
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1146)#### pub fn len(&self) -> usize
Returns the length of the binary heap.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let heap = BinaryHeap::from([1, 3]);
assert_eq!(heap.len(), 2);
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1170)#### pub fn is\_empty(&self) -> bool
Checks if the binary heap is empty.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();
assert!(heap.is_empty());
heap.push(3);
heap.push(5);
heap.push(1);
assert!(!heap.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1199)1.6.0 · #### pub fn drain(&mut self) -> Drain<'\_, T>
Notable traits for [Drain](binary_heap/struct.drain "struct std::collections::binary_heap::Drain")<'\_, T>
```
impl<T> Iterator for Drain<'_, T>
type Item = T;
```
Clears the binary heap, returning an iterator over the removed elements in arbitrary order. If the iterator is dropped before being fully consumed, it drops the remaining elements in arbitrary order.
The returned iterator keeps a mutable borrow on the heap to optimize its implementation.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::from([1, 3]);
assert!(!heap.is_empty());
for x in heap.drain() {
println!("{x}");
}
assert!(heap.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1220)#### pub fn clear(&mut self)
Drops all items from the binary heap.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::from([1, 3]);
assert!(!heap.is_empty());
heap.clear();
assert!(heap.is_empty());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#333)### impl<T> Clone for BinaryHeap<T>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#334)#### fn clone(&self) -> BinaryHeap<T>
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#338)#### fn clone\_from(&mut self, source: &BinaryHeap<T>)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#353)1.4.0 · ### impl<T> Debug for BinaryHeap<T>where T: [Debug](../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#354)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#344)### impl<T> Default for BinaryHeap<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#347)#### fn default() -> BinaryHeap<T>
Creates an empty `BinaryHeap<T>`.
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1707)1.2.0 · ### impl<'a, T> Extend<&'a T> for BinaryHeap<T>where T: 'a + [Ord](../cmp/trait.ord "trait std::cmp::Ord") + [Copy](../marker/trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1708)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [&'a](../primitive.reference) T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1713)#### fn extend\_one(&mut self, &'a T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1718)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1658)### impl<T> Extend<T> for BinaryHeap<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1660)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1665)#### fn extend\_one(&mut self, item: T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1670)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1586)1.56.0 · ### impl<T, const N: usize> From<[T; N]> for BinaryHeap<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1596)#### fn from(arr: [T; N]) -> BinaryHeap<T>
```
use std::collections::BinaryHeap;
let mut h1 = BinaryHeap::from([1, 4, 2, 3]);
let mut h2: BinaryHeap<_> = [1, 4, 2, 3].into();
while let Some((a, b)) = h1.pop().zip(h2.pop()) {
assert_eq!(a, b);
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1602)1.5.0 · ### impl<T> From<BinaryHeap<T>> for Vec<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1607)#### fn from(heap: BinaryHeap<T>) -> Vec<T, Global>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Converts a `BinaryHeap<T>` into a `Vec<T>`.
This conversion requires no data movement or allocation, and has constant time complexity.
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1574)1.5.0 · ### impl<T> From<Vec<T, Global>> for BinaryHeap<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1578)#### fn from(vec: Vec<T, Global>) -> BinaryHeap<T>
Converts a `Vec<T>` into a `BinaryHeap<T>`.
This conversion happens in-place, and has *O*(*n*) time complexity.
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1613)### impl<T> FromIterator<T> for BinaryHeap<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1614)#### fn from\_iter<I>(iter: I) -> BinaryHeap<T>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1648)### impl<'a, T> IntoIterator for &'a BinaryHeap<T>
#### type Item = &'a T
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1652)#### fn into\_iter(self) -> Iter<'a, T>
Notable traits for [Iter](binary_heap/struct.iter "struct std::collections::binary_heap::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1620)### impl<T> IntoIterator for BinaryHeap<T>
[source](https://doc.rust-lang.org/src/alloc/collections/binary_heap.rs.html#1642)#### fn into\_iter(self) -> IntoIter<T>
Notable traits for [IntoIter](binary_heap/struct.intoiter "struct std::collections::binary_heap::IntoIter")<T>
```
impl<T> Iterator for IntoIter<T>
type Item = T;
```
Creates a consuming iterator, that is, one that moves each value out of the binary heap in arbitrary order. The binary heap cannot be used after calling this.
##### Examples
Basic usage:
```
use std::collections::BinaryHeap;
let heap = BinaryHeap::from([1, 2, 3, 4]);
// Print 1, 2, 3, 4 in arbitrary order
for x in heap.into_iter() {
// x has type i32, not &i32
println!("{x}");
}
```
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
Auto Trait Implementations
--------------------------
### impl<T> RefUnwindSafe for BinaryHeap<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T> Send for BinaryHeap<T>where T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T> Sync for BinaryHeap<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<T> Unpin for BinaryHeap<T>where T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T> UnwindSafe for BinaryHeap<T>where T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Module std::collections Module std::collections
=======================
Collection types.
Rust’s standard collection library provides efficient implementations of the most common general purpose programming data structures. By using the standard implementations, it should be possible for two libraries to communicate without significant data conversion.
To get this out of the way: you should probably just use [`Vec`](../vec/struct.vec "Vec") or [`HashMap`](hash_map/struct.hashmap "HashMap"). These two collections cover most use cases for generic data storage and processing. They are exceptionally good at doing what they do. All the other collections in the standard library have specific use cases where they are the optimal choice, but these cases are borderline *niche* in comparison. Even when `Vec` and `HashMap` are technically suboptimal, they’re probably a good enough choice to get started.
Rust’s collections can be grouped into four major categories:
* Sequences: [`Vec`](../vec/struct.vec "Vec"), [`VecDeque`](struct.vecdeque "VecDeque"), [`LinkedList`](struct.linkedlist "LinkedList")
* Maps: [`HashMap`](hash_map/struct.hashmap "HashMap"), [`BTreeMap`](struct.btreemap "BTreeMap")
* Sets: [`HashSet`](hash_set/struct.hashset "HashSet"), [`BTreeSet`](struct.btreeset "BTreeSet")
* Misc: [`BinaryHeap`](struct.binaryheap "BinaryHeap")
When Should You Use Which Collection?
-------------------------------------
These are fairly high-level and quick break-downs of when each collection should be considered. Detailed discussions of strengths and weaknesses of individual collections can be found on their own documentation pages.
#### Use a `Vec` when:
* You want to collect items up to be processed or sent elsewhere later, and don’t care about any properties of the actual values being stored.
* You want a sequence of elements in a particular order, and will only be appending to (or near) the end.
* You want a stack.
* You want a resizable array.
* You want a heap-allocated array.
#### Use a `VecDeque` when:
* You want a [`Vec`](../vec/struct.vec "Vec") that supports efficient insertion at both ends of the sequence.
* You want a queue.
* You want a double-ended queue (deque).
#### Use a `LinkedList` when:
* You want a [`Vec`](../vec/struct.vec "Vec") or [`VecDeque`](struct.vecdeque "VecDeque") of unknown size, and can’t tolerate amortization.
* You want to efficiently split and append lists.
* You are *absolutely* certain you *really*, *truly*, want a doubly linked list.
#### Use a `HashMap` when:
* You want to associate arbitrary keys with an arbitrary value.
* You want a cache.
* You want a map, with no extra functionality.
#### Use a `BTreeMap` when:
* You want a map sorted by its keys.
* You want to be able to get a range of entries on-demand.
* You’re interested in what the smallest or largest key-value pair is.
* You want to find the largest or smallest key that is smaller or larger than something.
#### Use the `Set` variant of any of these `Map`s when:
* You just want to remember which keys you’ve seen.
* There is no meaningful value to associate with your keys.
* You just want a set.
#### Use a `BinaryHeap` when:
* You want to store a bunch of elements, but only ever want to process the “biggest” or “most important” one at any given time.
* You want a priority queue.
Performance
-----------
Choosing the right collection for the job requires an understanding of what each collection is good at. Here we briefly summarize the performance of different collections for certain important operations. For further details, see each type’s documentation, and note that the names of actual methods may differ from the tables below on certain collections.
Throughout the documentation, we will follow a few conventions. For all operations, the collection’s size is denoted by n. If another collection is involved in the operation, it contains m elements. Operations which have an *amortized* cost are suffixed with a `*`. Operations with an *expected* cost are suffixed with a `~`.
All amortized costs are for the potential need to resize when capacity is exhausted. If a resize occurs it will take *O*(*n*) time. Our collections never automatically shrink, so removal operations aren’t amortized. Over a sufficiently large series of operations, the average cost per operation will deterministically equal the given cost.
Only [`HashMap`](hash_map/struct.hashmap "HashMap") has expected costs, due to the probabilistic nature of hashing. It is theoretically possible, though very unlikely, for [`HashMap`](hash_map/struct.hashmap "HashMap") to experience worse performance.
### Sequences
| | get(i) | insert(i) | remove(i) | append | split\_off(i) |
| --- | --- | --- | --- | --- | --- |
| [`Vec`](../vec/struct.vec "Vec") | *O*(1) | *O*(*n*-*i*)\* | *O*(*n*-*i*) | *O*(*m*)\* | *O*(*n*-*i*) |
| [`VecDeque`](struct.vecdeque "VecDeque") | *O*(1) | *O*(min(*i*, *n*-*i*))\* | *O*(min(*i*, *n*-*i*)) | *O*(*m*)\* | *O*(min(*i*, *n*-*i*)) |
| [`LinkedList`](struct.linkedlist "LinkedList") | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(1) | *O*(min(*i*, *n*-*i*)) |
Note that where ties occur, [`Vec`](../vec/struct.vec "Vec") is generally going to be faster than [`VecDeque`](struct.vecdeque "VecDeque"), and [`VecDeque`](struct.vecdeque "VecDeque") is generally going to be faster than [`LinkedList`](struct.linkedlist "LinkedList").
### Maps
For Sets, all operations have the cost of the equivalent Map operation.
| | get | insert | remove | range | append |
| --- | --- | --- | --- | --- | --- |
| [`HashMap`](hash_map/struct.hashmap "HashMap") | *O*(1)~ | *O*(1)~\* | *O*(1)~ | N/A | N/A |
| [`BTreeMap`](struct.btreemap "BTreeMap") | *O*(log(*n*)) | *O*(log(*n*)) | *O*(log(*n*)) | *O*(log(*n*)) | *O*(*n*+*m*) |
Correct and Efficient Usage of Collections
------------------------------------------
Of course, knowing which collection is the right one for the job doesn’t instantly permit you to use it correctly. Here are some quick tips for efficient and correct usage of the standard collections in general. If you’re interested in how to use a specific collection in particular, consult its documentation for detailed discussion and code examples.
### Capacity Management
Many collections provide several constructors and methods that refer to “capacity”. These collections are generally built on top of an array. Optimally, this array would be exactly the right size to fit only the elements stored in the collection, but for the collection to do this would be very inefficient. If the backing array was exactly the right size at all times, then every time an element is inserted, the collection would have to grow the array to fit it. Due to the way memory is allocated and managed on most computers, this would almost surely require allocating an entirely new array and copying every single element from the old one into the new one. Hopefully you can see that this wouldn’t be very efficient to do on every operation.
Most collections therefore use an *amortized* allocation strategy. They generally let themselves have a fair amount of unoccupied space so that they only have to grow on occasion. When they do grow, they allocate a substantially larger array to move the elements into so that it will take a while for another grow to be required. While this strategy is great in general, it would be even better if the collection *never* had to resize its backing array. Unfortunately, the collection itself doesn’t have enough information to do this itself. Therefore, it is up to us programmers to give it hints.
Any `with_capacity` constructor will instruct the collection to allocate enough space for the specified number of elements. Ideally this will be for exactly that many elements, but some implementation details may prevent this. See collection-specific documentation for details. In general, use `with_capacity` when you know exactly how many elements will be inserted, or at least have a reasonable upper-bound on that number.
When anticipating a large influx of elements, the `reserve` family of methods can be used to hint to the collection how much room it should make for the coming items. As with `with_capacity`, the precise behavior of these methods will be specific to the collection of interest.
For optimal performance, collections will generally avoid shrinking themselves. If you believe that a collection will not soon contain any more elements, or just really need the memory, the `shrink_to_fit` method prompts the collection to shrink the backing array to the minimum size capable of holding its elements.
Finally, if ever you’re interested in what the actual capacity of the collection is, most collections provide a `capacity` method to query this information on demand. This can be useful for debugging purposes, or for use with the `reserve` methods.
### Iterators
Iterators are a powerful and robust mechanism used throughout Rust’s standard libraries. Iterators provide a sequence of values in a generic, safe, efficient and convenient way. The contents of an iterator are usually *lazily* evaluated, so that only the values that are actually needed are ever actually produced, and no allocation need be done to temporarily store them. Iterators are primarily consumed using a `for` loop, although many functions also take iterators where a collection or sequence of values is desired.
All of the standard collections provide several iterators for performing bulk manipulation of their contents. The three primary iterators almost every collection should provide are `iter`, `iter_mut`, and `into_iter`. Some of these are not provided on collections where it would be unsound or unreasonable to provide them.
`iter` provides an iterator of immutable references to all the contents of a collection in the most “natural” order. For sequence collections like [`Vec`](../vec/struct.vec "Vec"), this means the items will be yielded in increasing order of index starting at 0. For ordered collections like [`BTreeMap`](struct.btreemap "BTreeMap"), this means that the items will be yielded in sorted order. For unordered collections like [`HashMap`](hash_map/struct.hashmap "HashMap"), the items will be yielded in whatever order the internal representation made most convenient. This is great for reading through all the contents of the collection.
```
let vec = vec![1, 2, 3, 4];
for x in vec.iter() {
println!("vec contained {x:?}");
}
```
`iter_mut` provides an iterator of *mutable* references in the same order as `iter`. This is great for mutating all the contents of the collection.
```
let mut vec = vec![1, 2, 3, 4];
for x in vec.iter_mut() {
*x += 1;
}
```
`into_iter` transforms the actual collection into an iterator over its contents by-value. This is great when the collection itself is no longer needed, and the values are needed elsewhere. Using `extend` with `into_iter` is the main way that contents of one collection are moved into another. `extend` automatically calls `into_iter`, and takes any `T: [IntoIterator](../iter/trait.intoiterator "iter::IntoIterator")`. Calling `collect` on an iterator itself is also a great way to convert one collection into another. Both of these methods should internally use the capacity management tools discussed in the previous section to do this as efficiently as possible.
```
let mut vec1 = vec![1, 2, 3, 4];
let vec2 = vec![10, 20, 30, 40];
vec1.extend(vec2);
```
```
use std::collections::VecDeque;
let vec = [1, 2, 3, 4];
let buf: VecDeque<_> = vec.into_iter().collect();
```
Iterators also provide a series of *adapter* methods for performing common threads to sequences. Among the adapters are functional favorites like `map`, `fold`, `skip` and `take`. Of particular interest to collections is the `rev` adapter, which reverses any iterator that supports this operation. Most collections provide reversible iterators as the way to iterate over them in reverse order.
```
let vec = vec![1, 2, 3, 4];
for x in vec.iter().rev() {
println!("vec contained {x:?}");
}
```
Several other collection methods also return iterators to yield a sequence of results but avoid allocating an entire collection to store the result in. This provides maximum flexibility as `collect` or `extend` can be called to “pipe” the sequence into any collection if desired. Otherwise, the sequence can be looped over with a `for` loop. The iterator can also be discarded after partial use, preventing the computation of the unused items.
### Entries
The `entry` API is intended to provide an efficient mechanism for manipulating the contents of a map conditionally on the presence of a key or not. The primary motivating use case for this is to provide efficient accumulator maps. For instance, if one wishes to maintain a count of the number of times each key has been seen, they will have to perform some conditional logic on whether this is the first time the key has been seen or not. Normally, this would require a `find` followed by an `insert`, effectively duplicating the search effort on each insertion.
When a user calls `map.entry(key)`, the map will search for the key and then yield a variant of the `Entry` enum.
If a `Vacant(entry)` is yielded, then the key *was not* found. In this case the only valid operation is to `insert` a value into the entry. When this is done, the vacant entry is consumed and converted into a mutable reference to the value that was inserted. This allows for further manipulation of the value beyond the lifetime of the search itself. This is useful if complex logic needs to be performed on the value regardless of whether the value was just inserted.
If an `Occupied(entry)` is yielded, then the key *was* found. In this case, the user has several options: they can `get`, `insert` or `remove` the value of the occupied entry. Additionally, they can convert the occupied entry into a mutable reference to its value, providing symmetry to the vacant `insert` case.
#### Examples
Here are the two primary ways in which `entry` is used. First, a simple example where the logic performed on the values is trivial.
##### Counting the number of times each character in a string occurs
```
use std::collections::btree_map::BTreeMap;
let mut count = BTreeMap::new();
let message = "she sells sea shells by the sea shore";
for c in message.chars() {
*count.entry(c).or_insert(0) += 1;
}
assert_eq!(count.get(&'s'), Some(&8));
println!("Number of occurrences of each character");
for (char, count) in &count {
println!("{char}: {count}");
}
```
When the logic to be performed on the value is more complex, we may simply use the `entry` API to ensure that the value is initialized and perform the logic afterwards.
##### Tracking the inebriation of customers at a bar
```
use std::collections::btree_map::BTreeMap;
// A client of the bar. They have a blood alcohol level.
struct Person { blood_alcohol: f32 }
// All the orders made to the bar, by client ID.
let orders = vec![1, 2, 1, 2, 3, 4, 1, 2, 2, 3, 4, 1, 1, 1];
// Our clients.
let mut blood_alcohol = BTreeMap::new();
for id in orders {
// If this is the first time we've seen this customer, initialize them
// with no blood alcohol. Otherwise, just retrieve them.
let person = blood_alcohol.entry(id).or_insert(Person { blood_alcohol: 0.0 });
// Reduce their blood alcohol level. It takes time to order and drink a beer!
person.blood_alcohol *= 0.9;
// Check if they're sober enough to have another beer.
if person.blood_alcohol > 0.3 {
// Too drunk... for now.
println!("Sorry {id}, I have to cut you off");
} else {
// Have another!
person.blood_alcohol += 0.1;
}
}
```
Insert and complex keys
-----------------------
If we have a more complex key, calls to `insert` will not update the value of the key. For example:
```
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::hash::{Hash, Hasher};
#[derive(Debug)]
struct Foo {
a: u32,
b: &'static str,
}
// we will compare `Foo`s by their `a` value only.
impl PartialEq for Foo {
fn eq(&self, other: &Self) -> bool { self.a == other.a }
}
impl Eq for Foo {}
// we will hash `Foo`s by their `a` value only.
impl Hash for Foo {
fn hash<H: Hasher>(&self, h: &mut H) { self.a.hash(h); }
}
impl PartialOrd for Foo {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { self.a.partial_cmp(&other.a) }
}
impl Ord for Foo {
fn cmp(&self, other: &Self) -> Ordering { self.a.cmp(&other.a) }
}
let mut map = BTreeMap::new();
map.insert(Foo { a: 1, b: "baz" }, 99);
// We already have a Foo with an a of 1, so this will be updating the value.
map.insert(Foo { a: 1, b: "xyz" }, 100);
// The value has been updated...
assert_eq!(map.values().next().unwrap(), &100);
// ...but the key hasn't changed. b is still "baz", not "xyz".
assert_eq!(map.keys().next().unwrap().b, "baz");
```
Modules
-------
[binary\_heap](binary_heap/index "std::collections::binary_heap mod")
A priority queue implemented with a binary heap.
[btree\_map](btree_map/index "std::collections::btree_map mod")
An ordered map based on a B-Tree.
[btree\_set](btree_set/index "std::collections::btree_set mod")
An ordered set based on a B-Tree.
[hash\_map](hash_map/index "std::collections::hash_map mod")
A hash map implemented with quadratic probing and SIMD lookup.
[hash\_set](hash_set/index "std::collections::hash_set mod")
A hash set implemented as a `HashMap` where the value is `()`.
[linked\_list](linked_list/index "std::collections::linked_list mod")
A doubly-linked list with owned nodes.
[vec\_deque](vec_deque/index "std::collections::vec_deque mod")
A double-ended queue (deque) implemented with a growable ring buffer.
Structs
-------
[BTreeMap](struct.btreemap "std::collections::BTreeMap struct")
An ordered map based on a [B-Tree](https://en.wikipedia.org/wiki/B-tree).
[BTreeSet](struct.btreeset "std::collections::BTreeSet struct")
An ordered set based on a B-Tree.
[BinaryHeap](struct.binaryheap "std::collections::BinaryHeap struct")
A priority queue implemented with a binary heap.
[HashMap](struct.hashmap "std::collections::HashMap struct")
A [hash map](index#use-a-hashmap-when) implemented with quadratic probing and SIMD lookup.
[HashSet](struct.hashset "std::collections::HashSet struct")
A [hash set](index#use-the-set-variant-of-any-of-these-maps-when) implemented as a `HashMap` where the value is `()`.
[LinkedList](struct.linkedlist "std::collections::LinkedList struct")
A doubly-linked list with owned nodes.
[TryReserveError](struct.tryreserveerror "std::collections::TryReserveError struct")
The error type for `try_reserve` methods.
[VecDeque](struct.vecdeque "std::collections::VecDeque struct")
A double-ended queue implemented with a growable ring buffer.
Enums
-----
[TryReserveErrorKind](enum.tryreserveerrorkind "std::collections::TryReserveErrorKind enum")Experimental
Details of the allocation that caused a `TryReserveError`
rust Struct std::collections::HashSet Struct std::collections::HashSet
================================
```
pub struct HashSet<T, S = RandomState> { /* private fields */ }
```
A [hash set](index#use-the-set-variant-of-any-of-these-maps-when) implemented as a `HashMap` where the value is `()`.
As with the [`HashMap`](hash_map/struct.hashmap) type, a `HashSet` requires that the elements implement the [`Eq`](../cmp/trait.eq "Eq") and [`Hash`](../hash/trait.hash "Hash") traits. This can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`. If you implement these yourself, it is important that the following property holds:
```
k1 == k2 -> hash(k1) == hash(k2)
```
In other words, if two keys are equal, their hashes must be equal.
It is a logic error for a key to be modified in such a way that the key’s hash, as determined by the [`Hash`](../hash/trait.hash "Hash") trait, or its equality, as determined by the [`Eq`](../cmp/trait.eq "Eq") trait, changes while it is in the map. This is normally only possible through [`Cell`](../cell/struct.cell), [`RefCell`](../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `HashSet` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
Examples
--------
```
use std::collections::HashSet;
// Type inference lets us omit an explicit type signature (which
// would be `HashSet<String>` in this example).
let mut books = HashSet::new();
// Add some books.
books.insert("A Dance With Dragons".to_string());
books.insert("To Kill a Mockingbird".to_string());
books.insert("The Odyssey".to_string());
books.insert("The Great Gatsby".to_string());
// Check for a specific one.
if !books.contains("The Winds of Winter") {
println!("We have {} books, but The Winds of Winter ain't one.",
books.len());
}
// Remove a book.
books.remove("The Odyssey");
// Iterate over everything.
for book in &books {
println!("{book}");
}
```
The easiest way to use `HashSet` with a custom type is to derive [`Eq`](../cmp/trait.eq "Eq") and [`Hash`](../hash/trait.hash "Hash"). We must also derive [`PartialEq`](../cmp/trait.partialeq "PartialEq"), this will in the future be implied by [`Eq`](../cmp/trait.eq "Eq").
```
use std::collections::HashSet;
#[derive(Hash, Eq, PartialEq, Debug)]
struct Viking {
name: String,
power: usize,
}
let mut vikings = HashSet::new();
vikings.insert(Viking { name: "Einar".to_string(), power: 9 });
vikings.insert(Viking { name: "Einar".to_string(), power: 9 });
vikings.insert(Viking { name: "Olaf".to_string(), power: 4 });
vikings.insert(Viking { name: "Harald".to_string(), power: 8 });
// Use derived implementation to print the vikings.
for x in &vikings {
println!("{x:?}");
}
```
A `HashSet` with a known list of items can be initialized from an array:
```
use std::collections::HashSet;
let viking_names = HashSet::from(["Einar", "Olaf", "Harald"]);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#117-155)### impl<T> HashSet<T, RandomState>
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#132-134)#### pub fn new() -> HashSet<T, RandomState>
Creates an empty `HashSet`.
The hash set is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
##### Examples
```
use std::collections::HashSet;
let set: HashSet<i32> = HashSet::new();
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#152-154)#### pub fn with\_capacity(capacity: usize) -> HashSet<T, RandomState>
Creates an empty `HashSet` with at least the specified capacity.
The hash set will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is 0, the hash set will not allocate.
##### Examples
```
use std::collections::HashSet;
let set: HashSet<i32> = HashSet::with_capacity(10);
assert!(set.capacity() >= 10);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#157-431)### impl<T, S> HashSet<T, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#169-171)#### pub fn capacity(&self) -> usize
Returns the number of elements the set can hold without reallocating.
##### Examples
```
use std::collections::HashSet;
let set: HashSet<i32> = HashSet::with_capacity(100);
assert!(set.capacity() >= 100);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#197-199)#### pub fn iter(&self) -> Iter<'\_, T>
Notable traits for [Iter](hash_set/struct.iter "struct std::collections::hash_set::Iter")<'a, K>
```
impl<'a, K> Iterator for Iter<'a, K>
type Item = &'a K;
```
An iterator visiting all elements in arbitrary order. The iterator element type is `&'a T`.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert("a");
set.insert("b");
// Will print in an arbitrary order.
for x in set.iter() {
println!("{x}");
}
```
##### Performance
In the current implementation, iterating over set takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#215-217)#### pub fn len(&self) -> usize
Returns the number of elements in the set.
##### Examples
```
use std::collections::HashSet;
let mut v = HashSet::new();
assert_eq!(v.len(), 0);
v.insert(1);
assert_eq!(v.len(), 1);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#233-235)#### pub fn is\_empty(&self) -> bool
Returns `true` if the set contains no elements.
##### Examples
```
use std::collections::HashSet;
let mut v = HashSet::new();
assert!(v.is_empty());
v.insert(1);
assert!(!v.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#262-264)1.6.0 · #### pub fn drain(&mut self) -> Drain<'\_, T>
Notable traits for [Drain](hash_set/struct.drain "struct std::collections::hash_set::Drain")<'a, K>
```
impl<'a, K> Iterator for Drain<'a, K>
type Item = K;
```
Clears the set, returning all elements as an iterator. Keeps the allocated memory for reuse.
If the returned iterator is dropped before being fully consumed, it drops the remaining elements. The returned iterator keeps a mutable borrow on the set to optimize its implementation.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::from([1, 2, 3]);
assert!(!set.is_empty());
// print 1, 2, 3 in an arbitrary order
for i in set.drain() {
println!("{i}");
}
assert!(set.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#301-306)#### pub fn drain\_filter<F>(&mut self, pred: F) -> DrainFilter<'\_, T, F>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
Notable traits for [DrainFilter](hash_set/struct.drainfilter "struct std::collections::hash_set::DrainFilter")<'\_, K, F>
```
impl<K, F> Iterator for DrainFilter<'_, K, F>where
F: FnMut(&K) -> bool,
type Item = K;
```
🔬This is a nightly-only experimental API. (`hash_drain_filter` [#59618](https://github.com/rust-lang/rust/issues/59618))
Creates an iterator which uses a closure to determine if a value should be removed.
If the closure returns true, then the value is removed and yielded. If the closure returns false, the value will remain in the list and will not be yielded by the iterator.
If the iterator is only partially consumed or not consumed at all, each of the remaining values will still be subjected to the closure and removed and dropped if it returns true.
It is unspecified how many more values will be subjected to the closure if a panic occurs in the closure, or if a panic occurs while dropping a value, or if the `DrainFilter` itself is leaked.
##### Examples
Splitting a set into even and odd values, reusing the original set:
```
#![feature(hash_drain_filter)]
use std::collections::HashSet;
let mut set: HashSet<i32> = (0..8).collect();
let drained: HashSet<i32> = set.drain_filter(|v| v % 2 == 0).collect();
let mut evens = drained.into_iter().collect::<Vec<_>>();
let mut odds = set.into_iter().collect::<Vec<_>>();
evens.sort();
odds.sort();
assert_eq!(evens, vec![0, 2, 4, 6]);
assert_eq!(odds, vec![1, 3, 5, 7]);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#329-334)1.18.0 · #### pub fn retain<F>(&mut self, f: F)where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all elements `e` for which `f(&e)` returns `false`. The elements are visited in unsorted (and unspecified) order.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::from([1, 2, 3, 4, 5, 6]);
set.retain(|&k| k % 2 == 0);
assert_eq!(set.len(), 3);
```
##### Performance
In the current implementation, this operation takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#350-352)#### pub fn clear(&mut self)
Clears the set, removing all values.
##### Examples
```
use std::collections::HashSet;
let mut v = HashSet::new();
v.insert(1);
v.clear();
assert!(v.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#379-381)1.7.0 · #### pub fn with\_hasher(hasher: S) -> HashSet<T, S>
Creates a new empty hash set which will use the given hasher to hash keys.
The hash set is also created with the default initial capacity.
Warning: `hasher` is normally randomly generated, and is designed to allow `HashSet`s to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.
The `hash_builder` passed should implement the [`BuildHasher`](../hash/trait.buildhasher "BuildHasher") trait for the HashMap to be useful, see its documentation for details.
##### Examples
```
use std::collections::HashSet;
use std::collections::hash_map::RandomState;
let s = RandomState::new();
let mut set = HashSet::with_hasher(s);
set.insert(2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#410-412)1.7.0 · #### pub fn with\_capacity\_and\_hasher(capacity: usize, hasher: S) -> HashSet<T, S>
Creates an empty `HashSet` with at least the specified capacity, using `hasher` to hash the keys.
The hash set will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is 0, the hash set will not allocate.
Warning: `hasher` is normally randomly generated, and is designed to allow `HashSet`s to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.
The `hash_builder` passed should implement the [`BuildHasher`](../hash/trait.buildhasher "BuildHasher") trait for the HashMap to be useful, see its documentation for details.
##### Examples
```
use std::collections::HashSet;
use std::collections::hash_map::RandomState;
let s = RandomState::new();
let mut set = HashSet::with_capacity_and_hasher(10, s);
set.insert(1);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#428-430)1.9.0 · #### pub fn hasher(&self) -> &S
Returns a reference to the set’s [`BuildHasher`](../hash/trait.buildhasher "BuildHasher").
##### Examples
```
use std::collections::HashSet;
use std::collections::hash_map::RandomState;
let hasher = RandomState::new();
let set: HashSet<i32> = HashSet::with_hasher(hasher);
let hasher: &RandomState = set.hasher();
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#433-969)### impl<T, S> HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#458-460)#### pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least `additional` more elements to be inserted in the `HashSet`. The collection may reserve more space to speculatively avoid frequent reallocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional`. Does nothing if capacity is already sufficient.
##### Panics
Panics if the new allocation size overflows `usize`.
##### Examples
```
use std::collections::HashSet;
let mut set: HashSet<i32> = HashSet::new();
set.reserve(10);
assert!(set.capacity() >= 10);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#483-485)1.57.0 · #### pub fn try\_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least `additional` more elements to be inserted in the `HashSet`. The collection may reserve more space to speculatively avoid frequent reallocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if capacity is already sufficient.
##### Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::HashSet;
let mut set: HashSet<i32> = HashSet::new();
set.try_reserve(10).expect("why is the test harness OOMing on a handful of bytes?");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#505-507)#### pub fn shrink\_to\_fit(&mut self)
Shrinks the capacity of the set as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::with_capacity(100);
set.insert(1);
set.insert(2);
assert!(set.capacity() >= 100);
set.shrink_to_fit();
assert!(set.capacity() >= 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#530-532)1.56.0 · #### pub fn shrink\_to(&mut self, min\_capacity: usize)
Shrinks the capacity of the set with a lower limit. It will drop down no lower than the supplied limit while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
If the current capacity is less than the lower limit, this is a no-op.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::with_capacity(100);
set.insert(1);
set.insert(2);
assert!(set.capacity() >= 100);
set.shrink_to(10);
assert!(set.capacity() >= 10);
set.shrink_to(0);
assert!(set.capacity() >= 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#560-562)#### pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S>
Notable traits for [Difference](hash_set/struct.difference "struct std::collections::hash_set::Difference")<'a, T, S>
```
impl<'a, T, S> Iterator for Difference<'a, T, S>where
T: Eq + Hash,
S: BuildHasher,
type Item = &'a T;
```
Visits the values representing the difference, i.e., the values that are in `self` but not in `other`.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([4, 2, 3, 4]);
// Can be seen as `a - b`.
for x in a.difference(&b) {
println!("{x}"); // Print 1
}
let diff: HashSet<_> = a.difference(&b).collect();
assert_eq!(diff, [1].iter().collect());
// Note that difference is not symmetric,
// and `b - a` means something else:
let diff: HashSet<_> = b.difference(&a).collect();
assert_eq!(diff, [4].iter().collect());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#588-593)#### pub fn symmetric\_difference<'a>( &'a self, other: &'a HashSet<T, S>) -> SymmetricDifference<'a, T, S>
Notable traits for [SymmetricDifference](hash_set/struct.symmetricdifference "struct std::collections::hash_set::SymmetricDifference")<'a, T, S>
```
impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S>where
T: Eq + Hash,
S: BuildHasher,
type Item = &'a T;
```
Visits the values representing the symmetric difference, i.e., the values that are in `self` or in `other` but not in both.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([4, 2, 3, 4]);
// Print 1, 4 in arbitrary order.
for x in a.symmetric_difference(&b) {
println!("{x}");
}
let diff1: HashSet<_> = a.symmetric_difference(&b).collect();
let diff2: HashSet<_> = b.symmetric_difference(&a).collect();
assert_eq!(diff1, diff2);
assert_eq!(diff1, [1, 4].iter().collect());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#622-628)#### pub fn intersection<'a>( &'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S>
Notable traits for [Intersection](hash_set/struct.intersection "struct std::collections::hash_set::Intersection")<'a, T, S>
```
impl<'a, T, S> Iterator for Intersection<'a, T, S>where
T: Eq + Hash,
S: BuildHasher,
type Item = &'a T;
```
Visits the values representing the intersection, i.e., the values that are both in `self` and `other`.
When an equal element is present in `self` and `other` then the resulting `Intersection` may yield references to one or the other. This can be relevant if `T` contains fields which are not compared by its `Eq` implementation, and may hold different value between the two equal copies of `T` in the two sets.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([4, 2, 3, 4]);
// Print 2, 3 in arbitrary order.
for x in a.intersection(&b) {
println!("{x}");
}
let intersection: HashSet<_> = a.intersection(&b).collect();
assert_eq!(intersection, [2, 3].iter().collect());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#651-657)#### pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S>
Notable traits for [Union](hash_set/struct.union "struct std::collections::hash_set::Union")<'a, T, S>
```
impl<'a, T, S> Iterator for Union<'a, T, S>where
T: Eq + Hash,
S: BuildHasher,
type Item = &'a T;
```
Visits the values representing the union, i.e., all the values in `self` or `other`, without duplicates.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([4, 2, 3, 4]);
// Print 1, 2, 3, 4 in arbitrary order.
for x in a.union(&b) {
println!("{x}");
}
let union: HashSet<_> = a.union(&b).collect();
assert_eq!(union, [1, 2, 3, 4].iter().collect());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#676-682)#### pub fn contains<Q: ?Sized>(&self, value: &Q) -> boolwhere T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Returns `true` if the set contains a value.
The value may be any borrowed form of the set’s value type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the value type.
##### Examples
```
use std::collections::HashSet;
let set = HashSet::from([1, 2, 3]);
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#701-707)1.9.0 · #### pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>where T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Returns a reference to the value in the set, if any, that is equal to the given value.
The value may be any borrowed form of the set’s value type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the value type.
##### Examples
```
use std::collections::HashSet;
let set = HashSet::from([1, 2, 3]);
assert_eq!(set.get(&2), Some(&2));
assert_eq!(set.get(&4), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#727-731)#### pub fn get\_or\_insert(&mut self, value: T) -> &T
🔬This is a nightly-only experimental API. (`hash_set_entry` [#60896](https://github.com/rust-lang/rust/issues/60896))
Inserts the given `value` into the set if it is not present, then returns a reference to the value in the set.
##### Examples
```
#![feature(hash_set_entry)]
use std::collections::HashSet;
let mut set = HashSet::from([1, 2, 3]);
assert_eq!(set.len(), 3);
assert_eq!(set.get_or_insert(2), &2);
assert_eq!(set.get_or_insert(100), &100);
assert_eq!(set.len(), 4); // 100 was inserted
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#755-763)#### pub fn get\_or\_insert\_owned<Q: ?Sized>(&mut self, value: &Q) -> &Twhere T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [ToOwned](../borrow/trait.toowned "trait std::borrow::ToOwned")<Owned = T>,
🔬This is a nightly-only experimental API. (`hash_set_entry` [#60896](https://github.com/rust-lang/rust/issues/60896))
Inserts an owned copy of the given `value` into the set if it is not present, then returns a reference to the value in the set.
##### Examples
```
#![feature(hash_set_entry)]
use std::collections::HashSet;
let mut set: HashSet<String> = ["cat", "dog", "horse"]
.iter().map(|&pet| pet.to_owned()).collect();
assert_eq!(set.len(), 3);
for &pet in &["cat", "dog", "fish"] {
let value = set.get_or_insert_owned(pet);
assert_eq!(value, pet);
}
assert_eq!(set.len(), 4); // a new "fish" was inserted
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#787-796)#### pub fn get\_or\_insert\_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &Twhere T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"), F: [FnOnce](../ops/trait.fnonce "trait std::ops::FnOnce")([&](../primitive.reference)Q) -> T,
🔬This is a nightly-only experimental API. (`hash_set_entry` [#60896](https://github.com/rust-lang/rust/issues/60896))
Inserts a value computed from `f` into the set if the given `value` is not present, then returns a reference to the value in the set.
##### Examples
```
#![feature(hash_set_entry)]
use std::collections::HashSet;
let mut set: HashSet<String> = ["cat", "dog", "horse"]
.iter().map(|&pet| pet.to_owned()).collect();
assert_eq!(set.len(), 3);
for &pet in &["cat", "dog", "fish"] {
let value = set.get_or_insert_with(pet, str::to_owned);
assert_eq!(value, pet);
}
assert_eq!(set.len(), 4); // a new "fish" was inserted
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#816-822)#### pub fn is\_disjoint(&self, other: &HashSet<T, S>) -> bool
Returns `true` if `self` has no elements in common with `other`. This is equivalent to checking for an empty intersection.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let mut b = HashSet::new();
assert_eq!(a.is_disjoint(&b), true);
b.insert(4);
assert_eq!(a.is_disjoint(&b), true);
b.insert(1);
assert_eq!(a.is_disjoint(&b), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#842-844)#### pub fn is\_subset(&self, other: &HashSet<T, S>) -> bool
Returns `true` if the set is a subset of another, i.e., `other` contains at least all the values in `self`.
##### Examples
```
use std::collections::HashSet;
let sup = HashSet::from([1, 2, 3]);
let mut set = HashSet::new();
assert_eq!(set.is_subset(&sup), true);
set.insert(2);
assert_eq!(set.is_subset(&sup), true);
set.insert(4);
assert_eq!(set.is_subset(&sup), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#868-870)#### pub fn is\_superset(&self, other: &HashSet<T, S>) -> bool
Returns `true` if the set is a superset of another, i.e., `self` contains at least all the values in `other`.
##### Examples
```
use std::collections::HashSet;
let sub = HashSet::from([1, 2]);
let mut set = HashSet::new();
assert_eq!(set.is_superset(&sub), false);
set.insert(0);
set.insert(1);
assert_eq!(set.is_superset(&sub), false);
set.insert(2);
assert_eq!(set.is_superset(&sub), true);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#892-894)#### pub fn insert(&mut self, value: T) -> bool
Adds a value to the set.
Returns whether the value was newly inserted. That is:
* If the set did not previously contain this value, `true` is returned.
* If the set already contained this value, `false` is returned.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::new();
assert_eq!(set.insert(2), true);
assert_eq!(set.insert(2), false);
assert_eq!(set.len(), 1);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#913-915)1.9.0 · #### pub fn replace(&mut self, value: T) -> Option<T>
Adds a value to the set, replacing the existing value, if any, that is equal to the given one. Returns the replaced value.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(Vec::<i32>::new());
assert_eq!(set.get(&[][..]).unwrap().capacity(), 0);
set.replace(Vec::with_capacity(10));
assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#937-943)#### pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> boolwhere T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Removes a value from the set. Returns whether the value was present in the set.
The value may be any borrowed form of the set’s value type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the value type.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(2);
assert_eq!(set.remove(&2), true);
assert_eq!(set.remove(&2), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#962-968)1.9.0 · #### pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>where T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Removes and returns the value in the set, if any, that is equal to the given one.
The value may be any borrowed form of the set’s value type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the value type.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::from([1, 2, 3]);
assert_eq!(set.take(&2), Some(2));
assert_eq!(set.take(&2), None);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1156-1186)### impl<T, S> BitAnd<&HashSet<T, S>> for &HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash") + [Clone](../clone/trait.clone "trait std::clone::Clone"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher") + [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1183-1185)#### fn bitand(self, rhs: &HashSet<T, S>) -> HashSet<T, S>
Returns the intersection of `self` and `rhs` as a new `HashSet<T, S>`.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([2, 3, 4]);
let set = &a & &b;
let mut i = 0;
let expected = [2, 3];
for x in &set {
assert!(expected.contains(x));
i += 1;
}
assert_eq!(i, expected.len());
```
#### type Output = HashSet<T, S>
The resulting type after applying the `&` operator.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1123-1153)### impl<T, S> BitOr<&HashSet<T, S>> for &HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash") + [Clone](../clone/trait.clone "trait std::clone::Clone"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher") + [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1150-1152)#### fn bitor(self, rhs: &HashSet<T, S>) -> HashSet<T, S>
Returns the union of `self` and `rhs` as a new `HashSet<T, S>`.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([3, 4, 5]);
let set = &a | &b;
let mut i = 0;
let expected = [1, 2, 3, 4, 5];
for x in &set {
assert!(expected.contains(x));
i += 1;
}
assert_eq!(i, expected.len());
```
#### type Output = HashSet<T, S>
The resulting type after applying the `|` operator.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1189-1219)### impl<T, S> BitXor<&HashSet<T, S>> for &HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash") + [Clone](../clone/trait.clone "trait std::clone::Clone"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher") + [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1216-1218)#### fn bitxor(self, rhs: &HashSet<T, S>) -> HashSet<T, S>
Returns the symmetric difference of `self` and `rhs` as a new `HashSet<T, S>`.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([3, 4, 5]);
let set = &a ^ &b;
let mut i = 0;
let expected = [1, 2, 4, 5];
for x in &set {
assert!(expected.contains(x));
i += 1;
}
assert_eq!(i, expected.len());
```
#### type Output = HashSet<T, S>
The resulting type after applying the `^` operator.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#972-986)### impl<T, S> Clone for HashSet<T, S>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"), S: [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#978-980)#### fn clone(&self) -> Self
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#983-985)#### fn clone\_from(&mut self, other: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1012-1019)### impl<T, S> Debug for HashSet<T, S>where T: [Debug](../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1016-1018)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1111-1120)### impl<T, S> Default for HashSet<T, S>where S: [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1117-1119)#### fn default() -> HashSet<T, S>
Creates an empty `HashSet<T, S>` with the `Default` value for the hasher.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1089-1108)1.4.0 · ### impl<'a, T, S> Extend<&'a T> for HashSet<T, S>where T: 'a + [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash") + [Copy](../marker/trait.copy "trait std::marker::Copy"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1095-1097)#### fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1100-1102)#### fn extend\_one(&mut self, item: &'a T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1105-1107)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1067-1086)### impl<T, S> Extend<T> for HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1073-1075)#### fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1078-1080)#### fn extend\_one(&mut self, item: T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1083-1085)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1048-1064)1.56.0 · ### impl<T, const N: usize> From<[T; N]> for HashSet<T, RandomState>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1061-1063)#### fn from(arr: [T; N]) -> Self
##### Examples
```
use std::collections::HashSet;
let set1 = HashSet::from([1, 2, 3, 4]);
let set2: HashSet<_> = [1, 2, 3, 4].into();
assert_eq!(set1, set2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1022-1033)### impl<T, S> FromIterator<T> for HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher") + [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1028-1032)#### fn from\_iter<I: IntoIterator<Item = T>>(iter: I) -> HashSet<T, S>
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1446-1455)### impl<'a, T, S> IntoIterator for &'a HashSet<T, S>
#### type Item = &'a T
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1452-1454)#### fn into\_iter(self) -> Iter<'a, T>
Notable traits for [Iter](hash_set/struct.iter "struct std::collections::hash_set::Iter")<'a, K>
```
impl<'a, K> Iterator for Iter<'a, K>
type Item = &'a K;
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1458-1487)### impl<T, S> IntoIterator for HashSet<T, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1484-1486)#### fn into\_iter(self) -> IntoIter<T>
Notable traits for [IntoIter](hash_set/struct.intoiter "struct std::collections::hash_set::IntoIter")<K>
```
impl<K> Iterator for IntoIter<K>
type Item = K;
```
Creates a consuming iterator, that is, one that moves each value out of the set in arbitrary order. The set cannot be used after calling this.
##### Examples
```
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert("a".to_string());
set.insert("b".to_string());
// Not possible to collect to a Vec<String> with a regular `.iter()`.
let v: Vec<String> = set.into_iter().collect();
// Will print in an arbitrary order.
for x in &v {
println!("{x}");
}
```
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#989-1001)### impl<T, S> PartialEq<HashSet<T, S>> for HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#994-1000)#### fn eq(&self, other: &HashSet<T, S>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1222-1252)### impl<T, S> Sub<&HashSet<T, S>> for &HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash") + [Clone](../clone/trait.clone "trait std::clone::Clone"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher") + [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1249-1251)#### fn sub(self, rhs: &HashSet<T, S>) -> HashSet<T, S>
Returns the difference of `self` and `rhs` as a new `HashSet<T, S>`.
##### Examples
```
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([3, 4, 5]);
let set = &a - &b;
let mut i = 0;
let expected = [1, 2];
for x in &set {
assert!(expected.contains(x));
i += 1;
}
assert_eq!(i, expected.len());
```
#### type Output = HashSet<T, S>
The resulting type after applying the `-` operator.
[source](https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1004-1009)### impl<T, S> Eq for HashSet<T, S>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
Auto Trait Implementations
--------------------------
### impl<T, S> RefUnwindSafe for HashSet<T, S>where S: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T, S> Send for HashSet<T, S>where S: [Send](../marker/trait.send "trait std::marker::Send"), T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T, S> Sync for HashSet<T, S>where S: [Sync](../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<T, S> Unpin for HashSet<T, S>where S: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"), T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T, S> UnwindSafe for HashSet<T, S>where S: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Enum std::collections::TryReserveErrorKind Enum std::collections::TryReserveErrorKind
==========================================
```
pub enum TryReserveErrorKind {
CapacityOverflow,
AllocError {
layout: Layout,
/* private fields */
},
}
```
🔬This is a nightly-only experimental API. (`try_reserve_kind` [#48043](https://github.com/rust-lang/rust/issues/48043))
Details of the allocation that caused a `TryReserveError`
Variants
--------
### `CapacityOverflow`
🔬This is a nightly-only experimental API. (`try_reserve_kind` [#48043](https://github.com/rust-lang/rust/issues/48043))
Error due to the computed capacity exceeding the collection’s maximum (usually `isize::MAX` bytes).
### `AllocError`
#### Fields
`layout: [Layout](../alloc/struct.layout "struct std::alloc::Layout")`
🔬This is a nightly-only experimental API. (`try_reserve_kind` [#48043](https://github.com/rust-lang/rust/issues/48043))
The layout of allocation request that failed
🔬This is a nightly-only experimental API. (`try_reserve_kind` [#48043](https://github.com/rust-lang/rust/issues/48043))
The memory allocator returned an error
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl Clone for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)#### fn clone(&self) -> TryReserveErrorKind
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl Debug for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#122)### impl From<LayoutError> for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#125)#### fn from(LayoutError) -> TryReserveErrorKind
Always evaluates to [`TryReserveErrorKind::CapacityOverflow`](enum.tryreserveerrorkind#variant.CapacityOverflow "TryReserveErrorKind::CapacityOverflow").
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#114)### impl From<TryReserveErrorKind> for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#116)#### fn from(kind: TryReserveErrorKind) -> TryReserveError
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl PartialEq<TryReserveErrorKind> for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)#### fn eq(&self, other: &TryReserveErrorKind) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl Eq for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl StructuralEq for TryReserveErrorKind
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#80)### impl StructuralPartialEq for TryReserveErrorKind
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for TryReserveErrorKind
### impl Send for TryReserveErrorKind
### impl Sync for TryReserveErrorKind
### impl Unpin for TryReserveErrorKind
### impl UnwindSafe for TryReserveErrorKind
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::BTreeSet Struct std::collections::BTreeSet
=================================
```
pub struct BTreeSet<T, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An ordered set based on a B-Tree.
See [`BTreeMap`](struct.btreemap "BTreeMap")’s documentation for a detailed discussion of this collection’s performance benefits and drawbacks.
It is a logic error for an item to be modified in such a way that the item’s ordering relative to any other item, as determined by the [`Ord`](../cmp/trait.ord) trait, changes while it is in the set. This is normally only possible through [`Cell`](../cell/struct.cell), [`RefCell`](../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `BTreeSet` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
Iterators returned by [`BTreeSet::iter`](struct.btreeset#method.iter "BTreeSet::iter") produce their items in order, and take worst-case logarithmic and amortized constant time per item returned.
Examples
--------
```
use std::collections::BTreeSet;
// Type inference lets us omit an explicit type signature (which
// would be `BTreeSet<&str>` in this example).
let mut books = BTreeSet::new();
// Add some books.
books.insert("A Dance With Dragons");
books.insert("To Kill a Mockingbird");
books.insert("The Odyssey");
books.insert("The Great Gatsby");
// Check for a specific one.
if !books.contains("The Winds of Winter") {
println!("We have {} books, but The Winds of Winter ain't one.",
books.len());
}
// Remove a book.
books.remove("The Odyssey");
// Iterate over everything.
for book in &books {
println!("{book}");
}
```
A `BTreeSet` with a known list of items can be initialized from an array:
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#332)### impl<T> BTreeSet<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#348)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn new() -> BTreeSet<T, Global>
Makes a new, empty `BTreeSet`.
Does not allocate anything on its own.
##### Examples
```
use std::collections::BTreeSet;
let mut set: BTreeSet<i32> = BTreeSet::new();
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#353)### impl<T, A> BTreeSet<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#368)#### pub fn new\_in(alloc: A) -> BTreeSet<T, A>
🔬This is a nightly-only experimental API. (`btreemap_alloc` [#32838](https://github.com/rust-lang/rust/issues/32838))
Makes a new `BTreeSet` with a reasonable choice of B.
##### Examples
```
use std::collections::BTreeSet;
use std::alloc::Global;
let mut set: BTreeSet<i32> = BTreeSet::new_in(Global);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#400-404)1.17.0 · #### pub fn range<K, R>(&self, range: R) -> Range<'\_, T>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<K> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<K>,
Notable traits for [Range](btree_set/struct.range "struct std::collections::btree_set::Range")<'a, T>
```
impl<'a, T> Iterator for Range<'a, T>
type Item = &'a T;
```
Constructs a double-ended iterator over a sub-range of elements in the set. The simplest way is to use the range syntax `min..max`, thus `range(min..max)` will yield elements from min (inclusive) to max (exclusive). The range may also be entered as `(Bound<T>, Bound<T>)`, so for example `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive range from 4 to 10.
##### Panics
Panics if range `start > end`. Panics if range `start == end` and both bounds are `Excluded`.
##### Examples
```
use std::collections::BTreeSet;
use std::ops::Bound::Included;
let mut set = BTreeSet::new();
set.insert(3);
set.insert(5);
set.insert(8);
for &elem in set.range((Included(&4), Included(&8))) {
println!("{elem}");
}
assert_eq!(Some(&5), set.range(4..).next());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#430-432)#### pub fn difference(&'a self, other: &'a BTreeSet<T, A>) -> Difference<'a, T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [Difference](btree_set/struct.difference "struct std::collections::btree_set::Difference")<'a, T, A>
```
impl<'a, T, A> Iterator for Difference<'a, T, A>where
T: Ord,
A: Allocator + Clone,
type Item = &'a T;
```
Visits the elements representing the difference, i.e., the elements that are in `self` but not in `other`, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let diff: Vec<_> = a.difference(&b).cloned().collect();
assert_eq!(diff, [1]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#491-496)#### pub fn symmetric\_difference( &'a self, other: &'a BTreeSet<T, A>) -> SymmetricDifference<'a, T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [SymmetricDifference](btree_set/struct.symmetricdifference "struct std::collections::btree_set::SymmetricDifference")<'a, T>
```
impl<'a, T> Iterator for SymmetricDifference<'a, T>where
T: Ord,
type Item = &'a T;
```
Visits the elements representing the symmetric difference, i.e., the elements that are in `self` or in `other` but not in both, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let sym_diff: Vec<_> = a.symmetric_difference(&b).cloned().collect();
assert_eq!(sym_diff, [1, 3]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#522-524)#### pub fn intersection( &'a self, other: &'a BTreeSet<T, A>) -> Intersection<'a, T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [Intersection](btree_set/struct.intersection "struct std::collections::btree_set::Intersection")<'a, T, A>
```
impl<'a, T, A> Iterator for Intersection<'a, T, A>where
T: Ord,
A: Allocator + Clone,
type Item = &'a T;
```
Visits the elements representing the intersection, i.e., the elements that are both in `self` and `other`, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let intersection: Vec<_> = a.intersection(&b).cloned().collect();
assert_eq!(intersection, [2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#573-575)#### pub fn union(&'a self, other: &'a BTreeSet<T, A>) -> Union<'a, T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [Union](btree_set/struct.union "struct std::collections::btree_set::Union")<'a, T>
```
impl<'a, T> Iterator for Union<'a, T>where
T: Ord,
type Item = &'a T;
```
Visits the elements representing the union, i.e., all the elements in `self` or `other`, without duplicates, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
let mut b = BTreeSet::new();
b.insert(2);
let union: Vec<_> = a.union(&b).cloned().collect();
assert_eq!(union, [1, 2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#593-595)#### pub fn clear(&mut self)where A: [Clone](../clone/trait.clone "trait std::clone::Clone"),
Clears the set, removing all elements.
##### Examples
```
use std::collections::BTreeSet;
let mut v = BTreeSet::new();
v.insert(1);
v.clear();
assert!(v.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#616-619)#### pub fn contains<Q>(&self, value: &Q) -> boolwhere T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Returns `true` if the set contains an element equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#641-644)1.9.0 · #### pub fn get<Q>(&self, value: &Q) -> Option<&T>where T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Returns a reference to the element in the set, if any, that is equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.get(&2), Some(&2));
assert_eq!(set.get(&4), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#668-670)#### pub fn is\_disjoint(&self, other: &BTreeSet<T, A>) -> boolwhere T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Returns `true` if `self` has no elements in common with `other`. This is equivalent to checking for an empty intersection.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let mut b = BTreeSet::new();
assert_eq!(a.is_disjoint(&b), true);
b.insert(4);
assert_eq!(a.is_disjoint(&b), true);
b.insert(1);
assert_eq!(a.is_disjoint(&b), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#694-696)#### pub fn is\_subset(&self, other: &BTreeSet<T, A>) -> boolwhere T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Returns `true` if the set is a subset of another, i.e., `other` contains at least all the elements in `self`.
##### Examples
```
use std::collections::BTreeSet;
let sup = BTreeSet::from([1, 2, 3]);
let mut set = BTreeSet::new();
assert_eq!(set.is_subset(&sup), true);
set.insert(2);
assert_eq!(set.is_subset(&sup), true);
set.insert(4);
assert_eq!(set.is_subset(&sup), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#774-776)#### pub fn is\_superset(&self, other: &BTreeSet<T, A>) -> boolwhere T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Returns `true` if the set is a superset of another, i.e., `self` contains at least all the elements in `other`.
##### Examples
```
use std::collections::BTreeSet;
let sub = BTreeSet::from([1, 2]);
let mut set = BTreeSet::new();
assert_eq!(set.is_superset(&sub), false);
set.insert(0);
set.insert(1);
assert_eq!(set.is_superset(&sub), false);
set.insert(2);
assert_eq!(set.is_superset(&sub), true);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#801-803)#### pub fn first(&self) -> Option<&T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns a reference to the first element in the set, if any. This element is always the minimum of all elements in the set.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.first(), None);
set.insert(1);
assert_eq!(set.first(), Some(&1));
set.insert(2);
assert_eq!(set.first(), Some(&1));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#828-830)#### pub fn last(&self) -> Option<&T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns a reference to the last element in the set, if any. This element is always the maximum of all elements in the set.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.last(), None);
set.insert(1);
assert_eq!(set.last(), Some(&1));
set.insert(2);
assert_eq!(set.last(), Some(&2));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#853-855)#### pub fn pop\_first(&mut self) -> Option<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes the first element from the set and returns it, if any. The first element is always the minimum element in the set.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(1);
while let Some(n) = set.pop_first() {
assert_eq!(n, 1);
}
assert!(set.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#878-880)#### pub fn pop\_last(&mut self) -> Option<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes the last element from the set and returns it, if any. The last element is always the maximum element in the set.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(1);
while let Some(n) = set.pop_last() {
assert_eq!(n, 1);
}
assert!(set.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#910-912)#### pub fn insert(&mut self, value: T) -> boolwhere T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Adds a value to the set.
Returns whether the value was newly inserted. That is:
* If the set did not previously contain an equal value, `true` is returned.
* If the set already contained an equal value, `false` is returned, and the entry is not updated.
See the [module-level documentation](index#insert-and-complex-keys) for more.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.insert(2), true);
assert_eq!(set.insert(2), false);
assert_eq!(set.len(), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#933-935)1.9.0 · #### pub fn replace(&mut self, value: T) -> Option<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Adds a value to the set, replacing the existing element, if any, that is equal to the value. Returns the replaced element.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(Vec::<i32>::new());
assert_eq!(set.get(&[][..]).unwrap().capacity(), 0);
set.replace(Vec::with_capacity(10));
assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#959-962)#### pub fn remove<Q>(&mut self, value: &Q) -> boolwhere T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
If the set contains an element equal to the value, removes it from the set and drops it. Returns whether such an element was present.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(2);
assert_eq!(set.remove(&2), true);
assert_eq!(set.remove(&2), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#984-987)1.9.0 · #### pub fn take<Q>(&mut self, value: &Q) -> Option<T>where T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Removes and returns the element in the set, if any, that is equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.take(&2), Some(2));
assert_eq!(set.take(&2), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1008-1011)1.53.0 · #### pub fn retain<F>(&mut self, f: F)where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all elements `e` for which `f(&e)` returns `false`. The elements are visited in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::from([1, 2, 3, 4, 5, 6]);
// Keep only the even numbers.
set.retain(|&k| k % 2 == 0);
assert!(set.iter().eq([2, 4, 6].iter()));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1045-1048)1.11.0 · #### pub fn append(&mut self, other: &mut BTreeSet<T, A>)where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../clone/trait.clone "trait std::clone::Clone"),
Moves all elements from `other` into `self`, leaving `other` empty.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
let mut b = BTreeSet::new();
b.insert(3);
b.insert(4);
b.insert(5);
a.append(&mut b);
assert_eq!(a.len(), 5);
assert_eq!(b.len(), 0);
assert!(a.contains(&1));
assert!(a.contains(&2));
assert!(a.contains(&3));
assert!(a.contains(&4));
assert!(a.contains(&5));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1083-1086)1.11.0 · #### pub fn split\_off<Q>(&mut self, value: &Q) -> BTreeSet<T, A>where Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), T: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../clone/trait.clone "trait std::clone::Clone"),
Splits the collection into two at the value. Returns a new collection with all elements greater than or equal to the value.
##### Examples
Basic usage:
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(17);
a.insert(41);
let b = a.split_off(&3);
assert_eq!(a.len(), 2);
assert_eq!(b.len(), 3);
assert!(a.contains(&1));
assert!(a.contains(&2));
assert!(b.contains(&3));
assert!(b.contains(&17));
assert!(b.contains(&41));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1121-1124)#### pub fn drain\_filter<'a, F>(&'a mut self, pred: F) -> DrainFilter<'a, T, F, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), F: 'a + [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
Notable traits for [DrainFilter](btree_set/struct.drainfilter "struct std::collections::btree_set::DrainFilter")<'\_, T, F, A>
```
impl<'a, T, F, A> Iterator for DrainFilter<'_, T, F, A>where
A: Allocator + Clone,
F: 'a + FnMut(&T) -> bool,
type Item = T;
```
🔬This is a nightly-only experimental API. (`btree_drain_filter` [#70530](https://github.com/rust-lang/rust/issues/70530))
Creates an iterator that visits all elements in ascending order and uses a closure to determine if an element should be removed.
If the closure returns `true`, the element is removed from the set and yielded. If the closure returns `false`, or panics, the element remains in the set and will not be yielded.
If the iterator is only partially consumed or not consumed at all, each of the remaining elements is still subjected to the closure and removed and dropped if it returns `true`.
It is unspecified how many more elements will be subjected to the closure if a panic occurs in the closure, or if a panic occurs while dropping an element, or if the `DrainFilter` itself is leaked.
##### Examples
Splitting a set into even and odd values, reusing the original set:
```
#![feature(btree_drain_filter)]
use std::collections::BTreeSet;
let mut set: BTreeSet<i32> = (0..8).collect();
let evens: BTreeSet<_> = set.drain_filter(|v| v % 2 == 0).collect();
let odds = set;
assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![0, 2, 4, 6]);
assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 7]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1159)#### pub fn iter(&self) -> Iter<'\_, T>
Notable traits for [Iter](btree_set/struct.iter "struct std::collections::btree_set::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Gets an iterator that visits the elements in the `BTreeSet` in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(&1));
assert_eq!(set_iter.next(), Some(&2));
assert_eq!(set_iter.next(), Some(&3));
assert_eq!(set_iter.next(), None);
```
Values returned by the iterator are returned in ascending order:
```
use std::collections::BTreeSet;
let set = BTreeSet::from([3, 1, 2]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(&1));
assert_eq!(set_iter.next(), Some(&2));
assert_eq!(set_iter.next(), Some(&3));
assert_eq!(set_iter.next(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1178)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn len(&self) -> usize
Returns the number of elements in the set.
##### Examples
```
use std::collections::BTreeSet;
let mut v = BTreeSet::new();
assert_eq!(v.len(), 0);
v.insert(1);
assert_eq!(v.len(), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1197)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn is\_empty(&self) -> bool
Returns `true` if the set contains no elements.
##### Examples
```
use std::collections::BTreeSet;
let mut v = BTreeSet::new();
assert!(v.is_empty());
v.insert(1);
assert!(!v.is_empty());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1429)### impl<T, A> BitAnd<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1445)#### fn bitand(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the intersection of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([2, 3, 4]);
let result = &a & &b;
assert_eq!(result, BTreeSet::from([2, 3]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `&` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1454)### impl<T, A> BitOr<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1470)#### fn bitor(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the union of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([3, 4, 5]);
let result = &a | &b;
assert_eq!(result, BTreeSet::from([1, 2, 3, 4, 5]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `|` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1404)### impl<T, A> BitXor<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1420)#### fn bitxor(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([2, 3, 4]);
let result = &a ^ &b;
assert_eq!(result, BTreeSet::from([1, 4]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `^` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#120)### impl<T, A> Clone for BTreeSet<T, A>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#121)#### fn clone(&self) -> BTreeSet<T, A>
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#125)#### fn clone\_from(&mut self, other: &BTreeSet<T, A>)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1479)### impl<T, A> Debug for BTreeSet<T, A>where T: [Debug](../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1480)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1371)### impl<T> Default for BTreeSet<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1373)#### fn default() -> BTreeSet<T, Global>
Creates an empty `BTreeSet`.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1359)1.2.0 · ### impl<'a, T, A> Extend<&'a T> for BTreeSet<T, A>where T: 'a + [Ord](../cmp/trait.ord "trait std::cmp::Ord") + [Copy](../marker/trait.copy "trait std::marker::Copy"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1360)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [&'a](../primitive.reference) T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1365)#### fn extend\_one(&mut self, &'a T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1344)### impl<T, A> Extend<T> for BTreeSet<T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1346)#### fn extend<Iter>(&mut self, iter: Iter)where Iter: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1353)#### fn extend\_one(&mut self, elem: T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1226)1.56.0 · ### impl<T, const N: usize> From<[T; N]> for BTreeSet<T, Global>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1236)#### fn from(arr: [T; N]) -> BTreeSet<T, Global>
Converts a `[T; N]` into a `BTreeSet<T>`.
```
use std::collections::BTreeSet;
let set1 = BTreeSet::from([1, 2, 3, 4]);
let set2: BTreeSet<_> = [1, 2, 3, 4].into();
assert_eq!(set1, set2);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1203)### impl<T> FromIterator<T> for BTreeSet<T, Global>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1204)#### fn from\_iter<I>(iter: I) -> BTreeSet<T, Global>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#89)### impl<T, A> Hash for BTreeSet<T, A>where T: [Hash](../hash/trait.hash "trait std::hash::Hash"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#90)#### fn hash<H>(&self, state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1272)### impl<'a, T, A> IntoIterator for &'a BTreeSet<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Item = &'a T
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1276)#### fn into\_iter(self) -> Iter<'a, T>
Notable traits for [Iter](btree_set/struct.iter "struct std::collections::btree_set::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1250)### impl<T, A> IntoIterator for BTreeSet<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1266)#### fn into\_iter(self) -> IntoIter<T, A>
Notable traits for [IntoIter](btree_set/struct.intoiter "struct std::collections::btree_set::IntoIter")<T, A>
```
impl<T, A> Iterator for IntoIter<T, A>where
A: Allocator + Clone,
type Item = T;
```
Gets an iterator for moving out the `BTreeSet`’s contents.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3, 4]);
let v: Vec<_> = set.into_iter().collect();
assert_eq!(v, [1, 2, 3, 4]);
```
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = IntoIter<T, A>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#113)### impl<T, A> Ord for BTreeSet<T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#114)#### fn cmp(&self, other: &BTreeSet<T, A>) -> Ordering
This method returns an [`Ordering`](../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#96)### impl<T, A> PartialEq<BTreeSet<T, A>> for BTreeSet<T, A>where T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<T>, A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#97)#### fn eq(&self, other: &BTreeSet<T, A>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#106)### impl<T, A> PartialOrd<BTreeSet<T, A>> for BTreeSet<T, A>where T: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<T>, A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#107)#### fn partial\_cmp(&self, other: &BTreeSet<T, A>) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1379)### impl<T, A> Sub<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1395)#### fn sub(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the difference of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([3, 4, 5]);
let result = &a - &b;
assert_eq!(result, BTreeSet::from([1, 2]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `-` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#103)### impl<T, A> Eq for BTreeSet<T, A>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<T, A> RefUnwindSafe for BTreeSet<T, A>where A: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T, A> Send for BTreeSet<T, A>where A: [Send](../marker/trait.send "trait std::marker::Send"), T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T, A> Sync for BTreeSet<T, A>where A: [Sync](../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<T, A> Unpin for BTreeSet<T, A>where A: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T, A> UnwindSafe for BTreeSet<T, A>where A: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::VecDeque Struct std::collections::VecDeque
=================================
```
pub struct VecDeque<T, A = Global>where A: Allocator,{ /* private fields */ }
```
A double-ended queue implemented with a growable ring buffer.
The “default” usage of this type as a queue is to use [`push_back`](struct.vecdeque#method.push_back) to add to the queue, and [`pop_front`](struct.vecdeque#method.pop_front) to remove from the queue. [`extend`](struct.vecdeque#method.extend) and [`append`](struct.vecdeque#method.append) push onto the back in this manner, and iterating over `VecDeque` goes front to back.
A `VecDeque` with a known list of items can be initialized from an array:
```
use std::collections::VecDeque;
let deq = VecDeque::from([-1, 0, 1]);
```
Since `VecDeque` is a ring buffer, its elements are not necessarily contiguous in memory. If you want to access the elements as a single slice, such as for efficient sorting, you can use [`make_contiguous`](struct.vecdeque#method.make_contiguous). It rotates the `VecDeque` so that its elements do not wrap, and returns a mutable slice to the now-contiguous element sequence.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#520)### impl<T> VecDeque<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#533)#### pub fn new() -> VecDeque<T, Global>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Creates an empty deque.
##### Examples
```
use std::collections::VecDeque;
let deque: VecDeque<u32> = VecDeque::new();
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#549)#### pub fn with\_capacity(capacity: usize) -> VecDeque<T, Global>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Creates an empty deque with space for at least `capacity` elements.
##### Examples
```
use std::collections::VecDeque;
let deque: VecDeque<u32> = VecDeque::with_capacity(10);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#554)### impl<T, A> VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#566)#### pub fn new\_in(alloc: A) -> VecDeque<T, A>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
🔬This is a nightly-only experimental API. (`allocator_api` [#32838](https://github.com/rust-lang/rust/issues/32838))
Creates an empty deque.
##### Examples
```
use std::collections::VecDeque;
let deque: VecDeque<u32> = VecDeque::new();
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#580)#### pub fn with\_capacity\_in(capacity: usize, alloc: A) -> VecDeque<T, A>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
🔬This is a nightly-only experimental API. (`allocator_api` [#32838](https://github.com/rust-lang/rust/issues/32838))
Creates an empty deque with space for at least `capacity` elements.
##### Examples
```
use std::collections::VecDeque;
let deque: VecDeque<u32> = VecDeque::with_capacity(10);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#604)#### pub fn get(&self, index: usize) -> Option<&T>
Provides a reference to the element at the given index.
Element at index 0 is the front of the queue.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(3);
buf.push_back(4);
buf.push_back(5);
assert_eq!(buf.get(1), Some(&4));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#633)#### pub fn get\_mut(&mut self, index: usize) -> Option<&mut T>
Provides a mutable reference to the element at the given index.
Element at index 0 is the front of the queue.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(3);
buf.push_back(4);
buf.push_back(5);
if let Some(elem) = buf.get_mut(1) {
*elem = 7;
}
assert_eq!(buf[1], 7);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#666)#### pub fn swap(&mut self, i: usize, j: usize)
Swaps elements at indices `i` and `j`.
`i` and `j` may be equal.
Element at index 0 is the front of the queue.
##### Panics
Panics if either index is out of bounds.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(3);
buf.push_back(4);
buf.push_back(5);
assert_eq!(buf, [3, 4, 5]);
buf.swap(0, 2);
assert_eq!(buf, [5, 4, 3]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#687)#### pub fn capacity(&self) -> usize
Returns the number of elements the deque can hold without reallocating.
##### Examples
```
use std::collections::VecDeque;
let buf: VecDeque<i32> = VecDeque::with_capacity(10);
assert!(buf.capacity() >= 10);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#714)#### pub fn reserve\_exact(&mut self, additional: usize)
Reserves the minimum capacity for at least `additional` more elements to be inserted in the given deque. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer [`reserve`](struct.vecdeque#method.reserve) if future insertions are expected.
##### Panics
Panics if the new capacity overflows `usize`.
##### Examples
```
use std::collections::VecDeque;
let mut buf: VecDeque<i32> = [1].into();
buf.reserve_exact(10);
assert!(buf.capacity() >= 11);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#735)#### pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least `additional` more elements to be inserted in the given deque. The collection may reserve more space to speculatively avoid frequent reallocations.
##### Panics
Panics if the new capacity overflows `usize`.
##### Examples
```
use std::collections::VecDeque;
let mut buf: VecDeque<i32> = [1].into();
buf.reserve(10);
assert!(buf.capacity() >= 11);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#789)1.57.0 · #### pub fn try\_reserve\_exact( &mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve the minimum capacity for at least `additional` more elements to be inserted in the given deque. After calling `try_reserve_exact`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer [`try_reserve`](struct.vecdeque#method.try_reserve) if future insertions are expected.
##### Errors
If the capacity overflows `usize`, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::TryReserveError;
use std::collections::VecDeque;
fn process_data(data: &[u32]) -> Result<VecDeque<u32>, TryReserveError> {
let mut output = VecDeque::new();
// Pre-reserve the memory, exiting if we can't
output.try_reserve_exact(data.len())?;
// Now we know this can't OOM(Out-Of-Memory) in the middle of our complex work
output.extend(data.iter().map(|&val| {
val * 2 + 5 // very complicated
}));
Ok(output)
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#827)1.57.0 · #### pub fn try\_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least `additional` more elements to be inserted in the given deque. The collection may reserve more space to speculatively avoid frequent reallocations. After calling `try_reserve`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if capacity is already sufficient. This method preserves the contents even if an error occurs.
##### Errors
If the capacity overflows `usize`, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::TryReserveError;
use std::collections::VecDeque;
fn process_data(data: &[u32]) -> Result<VecDeque<u32>, TryReserveError> {
let mut output = VecDeque::new();
// Pre-reserve the memory, exiting if we can't
output.try_reserve(data.len())?;
// Now we know this can't OOM in the middle of our complex work
output.extend(data.iter().map(|&val| {
val * 2 + 5 // very complicated
}));
Ok(output)
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#861)1.5.0 · #### pub fn shrink\_to\_fit(&mut self)
Shrinks the capacity of the deque as much as possible.
It will drop down as close as possible to the length but the allocator may still inform the deque that there is space for a few more elements.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::with_capacity(15);
buf.extend(0..4);
assert_eq!(buf.capacity(), 15);
buf.shrink_to_fit();
assert!(buf.capacity() >= 4);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#886)1.56.0 · #### pub fn shrink\_to(&mut self, min\_capacity: usize)
Shrinks the capacity of the deque with a lower bound.
The capacity will remain at least as large as both the length and the supplied value.
If the current capacity is less than the lower limit, this is a no-op.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::with_capacity(15);
buf.extend(0..4);
assert_eq!(buf.capacity(), 15);
buf.shrink_to(6);
assert!(buf.capacity() >= 6);
buf.shrink_to(0);
assert!(buf.capacity() >= 4);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#968)1.16.0 · #### pub fn truncate(&mut self, len: usize)
Shortens the deque, keeping the first `len` elements and dropping the rest.
If `len` is greater than the deque’s current length, this has no effect.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(5);
buf.push_back(10);
buf.push_back(15);
assert_eq!(buf, [5, 10, 15]);
buf.truncate(1);
assert_eq!(buf, [5]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1015)#### pub fn allocator(&self) -> &A
🔬This is a nightly-only experimental API. (`allocator_api` [#32838](https://github.com/rust-lang/rust/issues/32838))
Returns a reference to the underlying allocator.
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1035)#### pub fn iter(&self) -> Iter<'\_, T>
Notable traits for [Iter](vec_deque/struct.iter "struct std::collections::vec_deque::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Returns a front-to-back iterator.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(5);
buf.push_back(3);
buf.push_back(4);
let b: &[_] = &[&5, &3, &4];
let c: Vec<&i32> = buf.iter().collect();
assert_eq!(&c[..], b);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1057)#### pub fn iter\_mut(&mut self) -> IterMut<'\_, T>
Notable traits for [IterMut](vec_deque/struct.itermut "struct std::collections::vec_deque::IterMut")<'a, T>
```
impl<'a, T> Iterator for IterMut<'a, T>
type Item = &'a mut T;
```
Returns a front-to-back iterator that returns mutable references.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(5);
buf.push_back(3);
buf.push_back(4);
for num in buf.iter_mut() {
*num = *num - 2;
}
let b: &[_] = &[&mut 3, &mut 1, &mut 2];
assert_eq!(&buf.iter_mut().collect::<Vec<&mut i32>>()[..], b);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1093)1.5.0 · #### pub fn as\_slices(&self) -> (&[T], &[T])
Returns a pair of slices which contain, in order, the contents of the deque.
If [`make_contiguous`](struct.vecdeque#method.make_contiguous) was previously called, all elements of the deque will be in the first slice and the second slice will be empty.
##### Examples
```
use std::collections::VecDeque;
let mut deque = VecDeque::new();
deque.push_back(0);
deque.push_back(1);
deque.push_back(2);
assert_eq!(deque.as_slices(), (&[0, 1, 2][..], &[][..]));
deque.push_front(10);
deque.push_front(9);
assert_eq!(deque.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1131)1.5.0 · #### pub fn as\_mut\_slices(&mut self) -> (&mut [T], &mut [T])
Returns a pair of slices which contain, in order, the contents of the deque.
If [`make_contiguous`](struct.vecdeque#method.make_contiguous) was previously called, all elements of the deque will be in the first slice and the second slice will be empty.
##### Examples
```
use std::collections::VecDeque;
let mut deque = VecDeque::new();
deque.push_back(0);
deque.push_back(1);
deque.push_front(10);
deque.push_front(9);
deque.as_mut_slices().0[0] = 42;
deque.as_mut_slices().1[0] = 24;
assert_eq!(deque.as_slices(), (&[42, 10][..], &[24, 1][..]));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1157)#### pub fn len(&self) -> usize
Returns the number of elements in the deque.
##### Examples
```
use std::collections::VecDeque;
let mut deque = VecDeque::new();
assert_eq!(deque.len(), 0);
deque.push_back(1);
assert_eq!(deque.len(), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1174)#### pub fn is\_empty(&self) -> bool
Returns `true` if the deque is empty.
##### Examples
```
use std::collections::VecDeque;
let mut deque = VecDeque::new();
assert!(deque.is_empty());
deque.push_front(1);
assert!(!deque.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1210-1212)1.51.0 · #### pub fn range<R>(&self, range: R) -> Iter<'\_, T>where R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<[usize](../primitive.usize)>,
Notable traits for [Iter](vec_deque/struct.iter "struct std::collections::vec_deque::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Creates an iterator that covers the specified range in the deque.
##### Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the deque.
##### Examples
```
use std::collections::VecDeque;
let deque: VecDeque<_> = [1, 2, 3].into();
let range = deque.range(2..).copied().collect::<VecDeque<_>>();
assert_eq!(range, [3]);
// A full range covers all contents
let all = deque.range(..);
assert_eq!(all.len(), 3);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1245-1247)1.51.0 · #### pub fn range\_mut<R>(&mut self, range: R) -> IterMut<'\_, T>where R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<[usize](../primitive.usize)>,
Notable traits for [IterMut](vec_deque/struct.itermut "struct std::collections::vec_deque::IterMut")<'a, T>
```
impl<'a, T> Iterator for IterMut<'a, T>
type Item = &'a mut T;
```
Creates an iterator that covers the specified mutable range in the deque.
##### Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the deque.
##### Examples
```
use std::collections::VecDeque;
let mut deque: VecDeque<_> = [1, 2, 3].into();
for v in deque.range_mut(2..) {
*v *= 2;
}
assert_eq!(deque, [1, 2, 6]);
// A full range covers all contents
for v in deque.range_mut(..) {
*v *= 2;
}
assert_eq!(deque, [2, 4, 12]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1293-1295)1.6.0 · #### pub fn drain<R>(&mut self, range: R) -> Drain<'\_, T, A>where R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<[usize](../primitive.usize)>,
Notable traits for [Drain](vec_deque/struct.drain "struct std::collections::vec_deque::Drain")<'\_, T, A>
```
impl<T, A> Iterator for Drain<'_, T, A>where
A: Allocator,
type Item = T;
```
Removes the specified range from the deque in bulk, returning all removed elements as an iterator. If the iterator is dropped before being fully consumed, it drops the remaining removed elements.
The returned iterator keeps a mutable borrow on the queue to optimize its implementation.
##### Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the deque.
##### Leaking
If the returned iterator goes out of scope without being dropped (due to [`mem::forget`](../mem/fn.forget "mem::forget"), for example), the deque may have lost and leaked elements arbitrarily, including elements outside the range.
##### Examples
```
use std::collections::VecDeque;
let mut deque: VecDeque<_> = [1, 2, 3].into();
let drained = deque.drain(2..).collect::<VecDeque<_>>();
assert_eq!(drained, [3]);
assert_eq!(deque, [1, 2]);
// A full range clears all contents, like `clear()` does
deque.drain(..);
assert!(deque.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1356)#### pub fn clear(&mut self)
Clears the deque, removing all values.
##### Examples
```
use std::collections::VecDeque;
let mut deque = VecDeque::new();
deque.push_back(1);
deque.clear();
assert!(deque.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1383-1385)1.12.0 · #### pub fn contains(&self, x: &T) -> boolwhere T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<T>,
Returns `true` if the deque contains an element equal to the given value.
This operation is *O*(*n*).
Note that if you have a sorted `VecDeque`, [`binary_search`](struct.vecdeque#method.binary_search) may be faster.
##### Examples
```
use std::collections::VecDeque;
let mut deque: VecDeque<u32> = VecDeque::new();
deque.push_back(0);
deque.push_back(1);
assert_eq!(deque.contains(&1), true);
assert_eq!(deque.contains(&10), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1407)#### pub fn front(&self) -> Option<&T>
Provides a reference to the front element, or `None` if the deque is empty.
##### Examples
```
use std::collections::VecDeque;
let mut d = VecDeque::new();
assert_eq!(d.front(), None);
d.push_back(1);
d.push_back(2);
assert_eq!(d.front(), Some(&1));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1431)#### pub fn front\_mut(&mut self) -> Option<&mut T>
Provides a mutable reference to the front element, or `None` if the deque is empty.
##### Examples
```
use std::collections::VecDeque;
let mut d = VecDeque::new();
assert_eq!(d.front_mut(), None);
d.push_back(1);
d.push_back(2);
match d.front_mut() {
Some(x) => *x = 9,
None => (),
}
assert_eq!(d.front(), Some(&9));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1451)#### pub fn back(&self) -> Option<&T>
Provides a reference to the back element, or `None` if the deque is empty.
##### Examples
```
use std::collections::VecDeque;
let mut d = VecDeque::new();
assert_eq!(d.back(), None);
d.push_back(1);
d.push_back(2);
assert_eq!(d.back(), Some(&2));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1475)#### pub fn back\_mut(&mut self) -> Option<&mut T>
Provides a mutable reference to the back element, or `None` if the deque is empty.
##### Examples
```
use std::collections::VecDeque;
let mut d = VecDeque::new();
assert_eq!(d.back(), None);
d.push_back(1);
d.push_back(2);
match d.back_mut() {
Some(x) => *x = 9,
None => (),
}
assert_eq!(d.back(), Some(&9));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1496)#### pub fn pop\_front(&mut self) -> Option<T>
Removes the first element and returns it, or `None` if the deque is empty.
##### Examples
```
use std::collections::VecDeque;
let mut d = VecDeque::new();
d.push_back(1);
d.push_back(2);
assert_eq!(d.pop_front(), Some(1));
assert_eq!(d.pop_front(), Some(2));
assert_eq!(d.pop_front(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1521)#### pub fn pop\_back(&mut self) -> Option<T>
Removes the last element from the deque and returns it, or `None` if it is empty.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
assert_eq!(buf.pop_back(), None);
buf.push_back(1);
buf.push_back(3);
assert_eq!(buf.pop_back(), Some(3));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1544)#### pub fn push\_front(&mut self, value: T)
Prepends an element to the deque.
##### Examples
```
use std::collections::VecDeque;
let mut d = VecDeque::new();
d.push_front(1);
d.push_front(2);
assert_eq!(d.front(), Some(&2));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1569)#### pub fn push\_back(&mut self, value: T)
Appends an element to the back of the deque.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(1);
buf.push_back(3);
assert_eq!(3, *buf.back().unwrap());
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1611)1.5.0 · #### pub fn swap\_remove\_front(&mut self, index: usize) -> Option<T>
Removes an element from anywhere in the deque and returns it, replacing it with the first element.
This does not preserve ordering, but is *O*(1).
Returns `None` if `index` is out of bounds.
Element at index 0 is the front of the queue.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
assert_eq!(buf.swap_remove_front(0), None);
buf.push_back(1);
buf.push_back(2);
buf.push_back(3);
assert_eq!(buf, [1, 2, 3]);
assert_eq!(buf.swap_remove_front(2), Some(3));
assert_eq!(buf, [2, 1]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1646)1.5.0 · #### pub fn swap\_remove\_back(&mut self, index: usize) -> Option<T>
Removes an element from anywhere in the deque and returns it, replacing it with the last element.
This does not preserve ordering, but is *O*(1).
Returns `None` if `index` is out of bounds.
Element at index 0 is the front of the queue.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
assert_eq!(buf.swap_remove_back(0), None);
buf.push_back(1);
buf.push_back(2);
buf.push_back(3);
assert_eq!(buf, [1, 2, 3]);
assert_eq!(buf.swap_remove_back(0), Some(1));
assert_eq!(buf, [3, 2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1680)1.5.0 · #### pub fn insert(&mut self, index: usize, value: T)
Inserts an element at `index` within the deque, shifting all elements with indices greater than or equal to `index` towards the back.
Element at index 0 is the front of the queue.
##### Panics
Panics if `index` is greater than deque’s length
##### Examples
```
use std::collections::VecDeque;
let mut vec_deque = VecDeque::new();
vec_deque.push_back('a');
vec_deque.push_back('b');
vec_deque.push_back('c');
assert_eq!(vec_deque, &['a', 'b', 'c']);
vec_deque.insert(1, 'd');
assert_eq!(vec_deque, &['a', 'd', 'b', 'c']);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#1902)#### pub fn remove(&mut self, index: usize) -> Option<T>
Removes and returns the element at `index` from the deque. Whichever end is closer to the removal point will be moved to make room, and all the affected elements will be moved to new positions. Returns `None` if `index` is out of bounds.
Element at index 0 is the front of the queue.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(1);
buf.push_back(2);
buf.push_back(3);
assert_eq!(buf, [1, 2, 3]);
assert_eq!(buf.remove(1), Some(2));
assert_eq!(buf, [1, 3]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2084-2086)1.4.0 · #### pub fn split\_off(&mut self, at: usize) -> VecDeque<T, A>where A: [Clone](../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Splits the deque into two at the given index.
Returns a newly allocated `VecDeque`. `self` contains elements `[0, at)`, and the returned deque contains elements `[at, len)`.
Note that the capacity of `self` does not change.
Element at index 0 is the front of the queue.
##### Panics
Panics if `at > len`.
##### Examples
```
use std::collections::VecDeque;
let mut buf: VecDeque<_> = [1, 2, 3].into();
let buf2 = buf.split_off(1);
assert_eq!(buf, [1]);
assert_eq!(buf2, [2, 3]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2150)1.4.0 · #### pub fn append(&mut self, other: &mut VecDeque<T, A>)
Moves all the elements of `other` into `self`, leaving `other` empty.
##### Panics
Panics if the new number of elements in self overflows a `usize`.
##### Examples
```
use std::collections::VecDeque;
let mut buf: VecDeque<_> = [1, 2].into();
let mut buf2: VecDeque<_> = [3, 4].into();
buf.append(&mut buf2);
assert_eq!(buf, [1, 2, 3, 4]);
assert_eq!(buf2, []);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2196-2198)1.4.0 · #### pub fn retain<F>(&mut self, f: F)where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all elements `e` for which `f(&e)` returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.extend(1..5);
buf.retain(|&x| x % 2 == 0);
assert_eq!(buf, [2, 4]);
```
Because the elements are visited exactly once in the original order, external state may be used to decide which elements to keep.
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.extend(1..6);
let keep = [false, true, true, false, true];
let mut iter = keep.iter();
buf.retain(|_| *iter.next().unwrap());
assert_eq!(buf, [2, 3, 5]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2225-2227)1.61.0 · #### pub fn retain\_mut<F>(&mut self, f: F)where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../primitive.reference) T) -> [bool](../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all elements `e` for which `f(&e)` returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.extend(1..5);
buf.retain_mut(|x| if *x % 2 == 0 {
*x += 1;
true
} else {
false
});
assert_eq!(buf, [3, 5]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2302)1.33.0 · #### pub fn resize\_with(&mut self, new\_len: usize, generator: impl FnMut() -> T)
Modifies the deque in-place so that `len()` is equal to `new_len`, either by removing excess elements from the back or by appending elements generated by calling `generator` to the back.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(5);
buf.push_back(10);
buf.push_back(15);
assert_eq!(buf, [5, 10, 15]);
buf.resize_with(5, Default::default);
assert_eq!(buf, [5, 10, 15, 0, 0]);
buf.resize_with(2, || unreachable!());
assert_eq!(buf, [5, 10]);
let mut state = 100;
buf.resize_with(5, || { state += 1; state });
assert_eq!(buf, [5, 10, 101, 102, 103]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2368)1.48.0 · #### pub fn make\_contiguous(&mut self) -> &mut [T]
Notable traits for &[[u8](../primitive.u8)]
```
impl Read for &[u8]
impl Write for &mut [u8]
```
Rearranges the internal storage of this deque so it is one contiguous slice, which is then returned.
This method does not allocate and does not change the order of the inserted elements. As it returns a mutable slice, this can be used to sort a deque.
Once the internal storage is contiguous, the [`as_slices`](struct.vecdeque#method.as_slices) and [`as_mut_slices`](struct.vecdeque#method.as_mut_slices) methods will return the entire contents of the deque in a single slice.
##### Examples
Sorting the content of a deque.
```
use std::collections::VecDeque;
let mut buf = VecDeque::with_capacity(15);
buf.push_back(2);
buf.push_back(1);
buf.push_front(3);
// sorting the deque
buf.make_contiguous().sort();
assert_eq!(buf.as_slices(), (&[1, 2, 3] as &[_], &[] as &[_]));
// sorting it in reverse order
buf.make_contiguous().sort_by(|a, b| b.cmp(a));
assert_eq!(buf.as_slices(), (&[3, 2, 1] as &[_], &[] as &[_]));
```
Getting immutable access to the contiguous slice.
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(2);
buf.push_back(1);
buf.push_front(3);
buf.make_contiguous();
if let (slice, &[]) = buf.as_slices() {
// we can now be sure that `slice` contains all elements of the deque,
// while still having immutable access to `buf`.
assert_eq!(buf.len(), slice.len());
assert_eq!(slice, &[3, 2, 1] as &[_]);
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2508)1.36.0 · #### pub fn rotate\_left(&mut self, mid: usize)
Rotates the double-ended queue `mid` places to the left.
Equivalently,
* Rotates item `mid` into the first position.
* Pops the first `mid` items and pushes them to the end.
* Rotates `len() - mid` places to the right.
##### Panics
If `mid` is greater than `len()`. Note that `mid == len()` does *not* panic and is a no-op rotation.
##### Complexity
Takes `*O*(min(mid, len() - mid))` time and no extra space.
##### Examples
```
use std::collections::VecDeque;
let mut buf: VecDeque<_> = (0..10).collect();
buf.rotate_left(3);
assert_eq!(buf, [3, 4, 5, 6, 7, 8, 9, 0, 1, 2]);
for i in 1..10 {
assert_eq!(i * 3 % 10, buf[0]);
buf.rotate_left(3);
}
assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2551)1.36.0 · #### pub fn rotate\_right(&mut self, k: usize)
Rotates the double-ended queue `k` places to the right.
Equivalently,
* Rotates the first item into position `k`.
* Pops the last `k` items and pushes them to the front.
* Rotates `len() - k` places to the left.
##### Panics
If `k` is greater than `len()`. Note that `k == len()` does *not* panic and is a no-op rotation.
##### Complexity
Takes `*O*(min(k, len() - k))` time and no extra space.
##### Examples
```
use std::collections::VecDeque;
let mut buf: VecDeque<_> = (0..10).collect();
buf.rotate_right(3);
assert_eq!(buf, [7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
for i in 1..10 {
assert_eq!(0, buf[i * 3 % 10]);
buf.rotate_right(3);
}
assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2636-2638)1.54.0 · #### pub fn binary\_search(&self, x: &T) -> Result<usize, usize>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Binary searches this `VecDeque` for a given element. This behaves similarly to [`contains`](struct.vecdeque#method.contains) if this `VecDeque` is sorted.
If the value is found then [`Result::Ok`](../result/enum.result#variant.Ok "Result::Ok") is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then [`Result::Err`](../result/enum.result#variant.Err "Result::Err") is returned, containing the index where a matching element could be inserted while maintaining sorted order.
See also [`binary_search_by`](struct.vecdeque#method.binary_search_by), [`binary_search_by_key`](struct.vecdeque#method.binary_search_by_key), and [`partition_point`](struct.vecdeque#method.partition_point).
##### Examples
Looks up a series of four elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in `[1, 4]`.
```
use std::collections::VecDeque;
let deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
assert_eq!(deque.binary_search(&13), Ok(9));
assert_eq!(deque.binary_search(&4), Err(7));
assert_eq!(deque.binary_search(&100), Err(13));
let r = deque.binary_search(&1);
assert!(matches!(r, Ok(1..=4)));
```
If you want to insert an item to a sorted deque, while maintaining sort order, consider using [`partition_point`](struct.vecdeque#method.partition_point):
```
use std::collections::VecDeque;
let mut deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
let num = 42;
let idx = deque.partition_point(|&x| x < num);
// The above is equivalent to `let idx = deque.binary_search(&num).unwrap_or_else(|x| x);`
deque.insert(idx, num);
assert_eq!(deque, &[0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2682-2684)1.54.0 · #### pub fn binary\_search\_by<'a, F>(&'a self, f: F) -> Result<usize, usize>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&'a](../primitive.reference) T) -> [Ordering](../cmp/enum.ordering "enum std::cmp::Ordering"),
Binary searches this `VecDeque` with a comparator function. This behaves similarly to [`contains`](struct.vecdeque#method.contains) if this `VecDeque` is sorted.
The comparator function should implement an order consistent with the sort order of the deque, returning an order code that indicates whether its argument is `Less`, `Equal` or `Greater` than the desired target.
If the value is found then [`Result::Ok`](../result/enum.result#variant.Ok "Result::Ok") is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then [`Result::Err`](../result/enum.result#variant.Err "Result::Err") is returned, containing the index where a matching element could be inserted while maintaining sorted order.
See also [`binary_search`](struct.vecdeque#method.binary_search), [`binary_search_by_key`](struct.vecdeque#method.binary_search_by_key), and [`partition_point`](struct.vecdeque#method.partition_point).
##### Examples
Looks up a series of four elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in `[1, 4]`.
```
use std::collections::VecDeque;
let deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
assert_eq!(deque.binary_search_by(|x| x.cmp(&13)), Ok(9));
assert_eq!(deque.binary_search_by(|x| x.cmp(&4)), Err(7));
assert_eq!(deque.binary_search_by(|x| x.cmp(&100)), Err(13));
let r = deque.binary_search_by(|x| x.cmp(&1));
assert!(matches!(r, Ok(1..=4)));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2740-2743)1.54.0 · #### pub fn binary\_search\_by\_key<'a, B, F>( &'a self, b: &B, f: F) -> Result<usize, usize>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&'a](../primitive.reference) T) -> B, B: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Binary searches this `VecDeque` with a key extraction function. This behaves similarly to [`contains`](struct.vecdeque#method.contains) if this `VecDeque` is sorted.
Assumes that the deque is sorted by the key, for instance with [`make_contiguous().sort_by_key()`](struct.vecdeque#method.make_contiguous) using the same key extraction function.
If the value is found then [`Result::Ok`](../result/enum.result#variant.Ok "Result::Ok") is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then [`Result::Err`](../result/enum.result#variant.Err "Result::Err") is returned, containing the index where a matching element could be inserted while maintaining sorted order.
See also [`binary_search`](struct.vecdeque#method.binary_search), [`binary_search_by`](struct.vecdeque#method.binary_search_by), and [`partition_point`](struct.vecdeque#method.partition_point).
##### Examples
Looks up a series of four elements in a slice of pairs sorted by their second elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in `[1, 4]`.
```
use std::collections::VecDeque;
let deque: VecDeque<_> = [(0, 0), (2, 1), (4, 1), (5, 1),
(3, 1), (1, 2), (2, 3), (4, 5), (5, 8), (3, 13),
(1, 21), (2, 34), (4, 55)].into();
assert_eq!(deque.binary_search_by_key(&13, |&(a, b)| b), Ok(9));
assert_eq!(deque.binary_search_by_key(&4, |&(a, b)| b), Err(7));
assert_eq!(deque.binary_search_by_key(&100, |&(a, b)| b), Err(13));
let r = deque.binary_search_by_key(&1, |&(a, b)| b);
assert!(matches!(r, Ok(1..=4)));
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2792-2794)1.54.0 · #### pub fn partition\_point<P>(&self, pred: P) -> usizewhere P: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)T) -> [bool](../primitive.bool),
Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).
The deque is assumed to be partitioned according to the given predicate. This means that all elements for which the predicate returns true are at the start of the deque and all elements for which the predicate returns false are at the end. For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0 (all odd numbers are at the start, all even at the end).
If the deque is not partitioned, the returned result is unspecified and meaningless, as this method performs a kind of binary search.
See also [`binary_search`](struct.vecdeque#method.binary_search), [`binary_search_by`](struct.vecdeque#method.binary_search_by), and [`binary_search_by_key`](struct.vecdeque#method.binary_search_by_key).
##### Examples
```
use std::collections::VecDeque;
let deque: VecDeque<_> = [1, 2, 3, 3, 5, 6, 7].into();
let i = deque.partition_point(|&x| x < 5);
assert_eq!(i, 4);
assert!(deque.iter().take(i).all(|&x| x < 5));
assert!(deque.iter().skip(i).all(|&x| !(x < 5)));
```
If you want to insert an item to a sorted deque, while maintaining sort order:
```
use std::collections::VecDeque;
let mut deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
let num = 42;
let idx = deque.partition_point(|&x| x < num);
deque.insert(idx, num);
assert_eq!(deque, &[0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2806)### impl<T, A> VecDeque<T, A>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2829)1.16.0 · #### pub fn resize(&mut self, new\_len: usize, value: T)
Modifies the deque in-place so that `len()` is equal to new\_len, either by removing excess elements from the back or by appending clones of `value` to the back.
##### Examples
```
use std::collections::VecDeque;
let mut buf = VecDeque::new();
buf.push_back(5);
buf.push_back(10);
buf.push_back(15);
assert_eq!(buf, [5, 10, 15]);
buf.resize(2, 0);
assert_eq!(buf, [5, 10]);
buf.resize(5, 20);
assert_eq!(buf, [5, 10, 20, 20, 20]);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#113)### impl<T, A> Clone for VecDeque<T, A>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#114)#### fn clone(&self) -> VecDeque<T, A>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#120)#### fn clone\_from(&mut self, other: &VecDeque<T, A>)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3023)### impl<T, A> Debug for VecDeque<T, A>where T: [Debug](../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3024)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#162)### impl<T> Default for VecDeque<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#165)#### fn default() -> VecDeque<T, Global>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Creates an empty deque.
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#137)### impl<T, A> Drop for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#138)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3006)1.2.0 · ### impl<'a, T, A> Extend<&'a T> for VecDeque<T, A>where T: 'a + [Copy](../marker/trait.copy "trait std::marker::Copy"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3007)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [&'a](../primitive.reference) T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3012)#### fn extend\_one(&mut self, &T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3017)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2989)### impl<T, A> Extend<T> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2990)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2995)#### fn extend\_one(&mut self, elem: T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3000)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3114)1.56.0 · ### impl<T, const N: usize> From<[T; N]> for VecDeque<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3124)#### fn from(arr: [T; N]) -> VecDeque<T, Global>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Converts a `[T; N]` into a `VecDeque<T>`.
```
use std::collections::VecDeque;
let deq1 = VecDeque::from([1, 2, 3, 4]);
let deq2: VecDeque<_> = [1, 2, 3, 4].into();
assert_eq!(deq1, deq2);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3030)1.10.0 · ### impl<T, A> From<Vec<T, A>> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3039)#### fn from(other: Vec<T, A>) -> VecDeque<T, A>
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Turn a [`Vec<T>`](../vec/struct.vec) into a [`VecDeque<T>`](struct.vecdeque).
This avoids reallocating where possible, but the conditions for that are strict, and subject to change, and so shouldn’t be relied upon unless the `Vec<T>` came from `From<VecDeque<T>>` and hasn’t been reallocated.
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3065)1.10.0 · ### impl<T, A> From<VecDeque<T, A>> for Vec<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#3095)#### fn from(other: VecDeque<T, A>) -> Vec<T, A>
Notable traits for [Vec](../vec/struct.vec "struct std::vec::Vec")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Write for Vec<u8, A>
```
Turn a [`VecDeque<T>`](struct.vecdeque) into a [`Vec<T>`](../vec/struct.vec).
This never needs to re-allocate, but does need to do *O*(*n*) data movement if the circular buffer doesn’t happen to be at the beginning of the allocation.
##### Examples
```
use std::collections::VecDeque;
// This one is *O*(1).
let deque: VecDeque<_> = (1..5).collect();
let ptr = deque.as_slices().0.as_ptr();
let vec = Vec::from(deque);
assert_eq!(vec, [1, 2, 3, 4]);
assert_eq!(vec.as_ptr(), ptr);
// This one needs data rearranging.
let mut deque: VecDeque<_> = (1..5).collect();
deque.push_front(9);
deque.push_front(8);
let ptr = deque.as_slices().1.as_ptr();
let vec = Vec::from(deque);
assert_eq!(vec, [8, 9, 1, 2, 3, 4]);
assert_eq!(vec.as_ptr(), ptr);
```
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2946)### impl<T> FromIterator<T> for VecDeque<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2947)#### fn from\_iter<I>(iter: I) -> VecDeque<T, Global>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Notable traits for [VecDeque](struct.vecdeque "struct std::collections::VecDeque")<[u8](../primitive.u8), A>
```
impl<A: Allocator> Read for VecDeque<u8, A>
impl<A: Allocator> Write for VecDeque<u8, A>
```
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2914)### impl<T, A> Hash for VecDeque<T, A>where T: [Hash](../hash/trait.hash "trait std::hash::Hash"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2915)#### fn hash<H>(&self, state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2928)### impl<T, A> Index<usize> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
#### type Output = T
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2932)#### fn index(&self, index: usize) -> &T
Performs the indexing (`container[index]`) operation. [Read more](../ops/trait.index#tymethod.index)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2938)### impl<T, A> IndexMut<usize> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2940)#### fn index\_mut(&mut self, index: usize) -> &mut T
Performs the mutable indexing (`container[index]`) operation. [Read more](../ops/trait.indexmut#tymethod.index_mut)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2969)### impl<'a, T, A> IntoIterator for &'a VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
#### type Item = &'a T
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2973)#### fn into\_iter(self) -> Iter<'a, T>
Notable traits for [Iter](vec_deque/struct.iter "struct std::collections::vec_deque::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2979)### impl<'a, T, A> IntoIterator for &'a mut VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
#### type Item = &'a mut T
The type of the elements being iterated over.
#### type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2983)#### fn into\_iter(self) -> IterMut<'a, T>
Notable traits for [IterMut](vec_deque/struct.itermut "struct std::collections::vec_deque::IterMut")<'a, T>
```
impl<'a, T> Iterator for IterMut<'a, T>
type Item = &'a mut T;
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2957)### impl<T, A> IntoIterator for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2963)#### fn into\_iter(self) -> IntoIter<T, A>
Notable traits for [IntoIter](vec_deque/struct.intoiter "struct std::collections::vec_deque::IntoIter")<T, A>
```
impl<T, A> Iterator for IntoIter<T, A>where
A: Allocator,
type Item = T;
```
Consumes the deque into a front-to-back iterator yielding elements by value.
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = IntoIter<T, A>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2906)### impl<T, A> Ord for VecDeque<T, A>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2908)#### fn cmp(&self, other: &VecDeque<T, A>) -> Ordering
This method returns an [`Ordering`](../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2895)1.17.0 · ### impl<T, U, A, const N: usize> PartialEq<&[U; N]> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"), T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<U>,
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2895)#### fn eq(&self, other: &&[U; N]) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2892)1.17.0 · ### impl<T, U, A> PartialEq<&[U]> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"), T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<U>,
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2892)#### fn eq(&self, other: &&[U]) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2896)1.17.0 · ### impl<T, U, A, const N: usize> PartialEq<&mut [U; N]> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"), T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<U>,
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2896)#### fn eq(&self, other: &&mut [U; N]) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2893)1.17.0 · ### impl<T, U, A> PartialEq<&mut [U]> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"), T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<U>,
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2893)#### fn eq(&self, other: &&mut [U]) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2894)1.17.0 · ### impl<T, U, A, const N: usize> PartialEq<[U; N]> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"), T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<U>,
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2894)#### fn eq(&self, other: &[U; N]) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2891)1.17.0 · ### impl<T, U, A> PartialEq<Vec<U, A>> for VecDeque<T, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"), T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<U>,
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2891)#### fn eq(&self, other: &Vec<U, A>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2850)### impl<T, A> PartialEq<VecDeque<T, A>> for VecDeque<T, A>where T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<T>, A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2851)#### fn eq(&self, other: &VecDeque<T, A>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2899)### impl<T, A> PartialOrd<VecDeque<T, A>> for VecDeque<T, A>where T: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<T>, A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2900)#### fn partial\_cmp(&self, other: &VecDeque<T, A>) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/std/io/impls.rs.html#417-437)1.63.0 · ### impl<A: Allocator> Read for VecDeque<u8, A>
Read is implemented for `VecDeque<u8>` by consuming bytes from the front of the `VecDeque`.
[source](https://doc.rust-lang.org/src/std/io/impls.rs.html#422-427)#### fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Fill `buf` with the contents of the “front” slice as returned by [`as_slices`](struct.vecdeque#method.as_slices "VecDeque::as_slices"). If the contained byte slices of the `VecDeque` are discontiguous, multiple calls to `read` will be needed to read the entire content.
[source](https://doc.rust-lang.org/src/std/io/impls.rs.html#430-436)#### fn read\_buf(&mut self, cursor: BorrowedCursor<'\_>) -> Result<()>
🔬This is a nightly-only experimental API. (`read_buf` [#78485](https://github.com/rust-lang/rust/issues/78485))
Pull some bytes from this source into the specified buffer. [Read more](../io/trait.read#method.read_buf)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#642-644)1.36.0 · #### fn read\_vectored(&mut self, bufs: &mut [IoSliceMut<'\_>]) -> Result<usize>
Like `read`, except that it reads into a slice of buffers. [Read more](../io/trait.read#method.read_vectored)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#655-657)#### fn is\_read\_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (`can_vector` [#69941](https://github.com/rust-lang/rust/issues/69941))
Determines if this `Read`er has an efficient `read_vectored` implementation. [Read more](../io/trait.read#method.is_read_vectored)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#706-708)#### fn read\_to\_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Read all bytes until EOF in this source, placing them into `buf`. [Read more](../io/trait.read#method.read_to_end)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#749-751)#### fn read\_to\_string(&mut self, buf: &mut String) -> Result<usize>
Read all bytes until EOF in this source, appending them to `buf`. [Read more](../io/trait.read#method.read_to_string)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#804-806)1.6.0 · #### fn read\_exact(&mut self, buf: &mut [u8]) -> Result<()>
Read the exact number of bytes required to fill `buf`. [Read more](../io/trait.read#method.read_exact)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#824-839)#### fn read\_buf\_exact(&mut self, cursor: BorrowedCursor<'\_>) -> Result<()>
🔬This is a nightly-only experimental API. (`read_buf` [#78485](https://github.com/rust-lang/rust/issues/78485))
Read the exact number of bytes required to fill `cursor`. [Read more](../io/trait.read#method.read_buf_exact)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#876-881)#### fn by\_ref(&mut self) -> &mut Selfwhere Self: [Sized](../marker/trait.sized "trait std::marker::Sized"),
Creates a “by reference” adaptor for this instance of `Read`. [Read more](../io/trait.read#method.by_ref)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#919-924)#### fn bytes(self) -> Bytes<Self>where Self: [Sized](../marker/trait.sized "trait std::marker::Sized"),
Notable traits for [Bytes](../io/struct.bytes "struct std::io::Bytes")<R>
```
impl<R: Read> Iterator for Bytes<R>
type Item = Result<u8>;
```
Transforms this `Read` instance to an [`Iterator`](../iter/trait.iterator "Iterator") over its bytes. [Read more](../io/trait.read#method.bytes)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#957-962)#### fn chain<R: Read>(self, next: R) -> Chain<Self, R>where Self: [Sized](../marker/trait.sized "trait std::marker::Sized"),
Notable traits for [Chain](../io/struct.chain "struct std::io::Chain")<T, U>
```
impl<T: Read, U: Read> Read for Chain<T, U>
```
Creates an adapter which will chain this stream with another. [Read more](../io/trait.read#method.chain)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#996-1001)#### fn take(self, limit: u64) -> Take<Self>where Self: [Sized](../marker/trait.sized "trait std::marker::Sized"),
Notable traits for [Take](../io/struct.take "struct std::io::Take")<T>
```
impl<T: Read> Read for Take<T>
```
Creates an adapter which will read at most `limit` bytes from it. [Read more](../io/trait.read#method.take)
[source](https://doc.rust-lang.org/src/std/io/impls.rs.html#441-458)1.63.0 · ### impl<A: Allocator> Write for VecDeque<u8, A>
Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed.
[source](https://doc.rust-lang.org/src/std/io/impls.rs.html#443-446)#### fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. [Read more](../io/trait.write#tymethod.write)
[source](https://doc.rust-lang.org/src/std/io/impls.rs.html#449-452)#### fn write\_all(&mut self, buf: &[u8]) -> Result<()>
Attempts to write an entire buffer into this writer. [Read more](../io/trait.write#method.write_all)
[source](https://doc.rust-lang.org/src/std/io/impls.rs.html#455-457)#### fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. [Read more](../io/trait.write#tymethod.flush)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1460-1462)1.36.0 · #### fn write\_vectored(&mut self, bufs: &[IoSlice<'\_>]) -> Result<usize>
Like [`write`](../io/trait.write#tymethod.write), except that it writes from a slice of buffers. [Read more](../io/trait.write#method.write_vectored)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1475-1477)#### fn is\_write\_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (`can_vector` [#69941](https://github.com/rust-lang/rust/issues/69941))
Determines if this `Write`r has an efficient [`write_vectored`](../io/trait.write#method.write_vectored) implementation. [Read more](../io/trait.write#method.is_write_vectored)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1602-1620)#### fn write\_all\_vectored(&mut self, bufs: &mut [IoSlice<'\_>]) -> Result<()>
🔬This is a nightly-only experimental API. (`write_all_vectored` [#70436](https://github.com/rust-lang/rust/issues/70436))
Attempts to write multiple buffers into this writer. [Read more](../io/trait.write#method.write_all_vectored)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1658-1690)#### fn write\_fmt(&mut self, fmt: Arguments<'\_>) -> Result<()>
Writes a formatted string into this writer, returning any error encountered. [Read more](../io/trait.write#method.write_fmt)
[source](https://doc.rust-lang.org/src/std/io/mod.rs.html#1714-1719)#### fn by\_ref(&mut self) -> &mut Selfwhere Self: [Sized](../marker/trait.sized "trait std::marker::Sized"),
Creates a “by reference” adapter for this instance of `Write`. [Read more](../io/trait.write#method.by_ref)
[source](https://doc.rust-lang.org/src/alloc/collections/vec_deque/mod.rs.html#2889)### impl<T, A> Eq for VecDeque<T, A>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator"),
Auto Trait Implementations
--------------------------
### impl<T, A> RefUnwindSafe for VecDeque<T, A>where A: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T, A> Send for VecDeque<T, A>where A: [Send](../marker/trait.send "trait std::marker::Send"), T: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<T, A> Sync for VecDeque<T, A>where A: [Sync](../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<T, A> Unpin for VecDeque<T, A>where A: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"), T: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T, A> UnwindSafe for VecDeque<T, A>where A: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::BTreeMap Struct std::collections::BTreeMap
=================================
```
pub struct BTreeMap<K, V, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An ordered map based on a [B-Tree](https://en.wikipedia.org/wiki/B-tree).
B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum amount of comparisons necessary to find an element (log2n). However, in practice the way this is done is *very* inefficient for modern computer architectures. In particular, every element is stored in its own individually heap-allocated node. This means that every single insertion triggers a heap-allocation, and every single comparison should be a cache-miss. Since these are both notably expensive things to do in practice, we are forced to at very least reconsider the BST strategy.
A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing this, we reduce the number of allocations by a factor of B, and improve cache efficiency in searches. However, this does mean that searches will have to do *more* comparisons on average. The precise number of comparisons depends on the node search strategy used. For optimal cache efficiency, one could search the nodes linearly. For optimal comparisons, one could search the node using binary search. As a compromise, one could also perform a linear search that initially only checks every ith element for some choice of i.
Currently, our implementation simply performs naive linear search. This provides excellent performance on *small* nodes of elements which are cheap to compare. However in the future we would like to further explore choosing the optimal search strategy based on the choice of B, and possibly other factors. Using linear search, searching for a random element is expected to take B \* log(n) comparisons, which is generally worse than a BST. In practice, however, performance is excellent.
It is a logic error for a key to be modified in such a way that the key’s ordering relative to any other key, as determined by the [`Ord`](../cmp/trait.ord "Ord") trait, changes while it is in the map. This is normally only possible through [`Cell`](../cell/struct.cell), [`RefCell`](../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `BTreeMap` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
Iterators obtained from functions such as [`BTreeMap::iter`](struct.btreemap#method.iter "BTreeMap::iter"), [`BTreeMap::values`](struct.btreemap#method.values "BTreeMap::values"), or [`BTreeMap::keys`](struct.btreemap#method.keys "BTreeMap::keys") produce their items in order by key, and take worst-case logarithmic and amortized constant time per item returned.
Examples
--------
```
use std::collections::BTreeMap;
// type inference lets us omit an explicit type signature (which
// would be `BTreeMap<&str, &str>` in this example).
let mut movie_reviews = BTreeMap::new();
// review some movies.
movie_reviews.insert("Office Space", "Deals with real issues in the workplace.");
movie_reviews.insert("Pulp Fiction", "Masterpiece.");
movie_reviews.insert("The Godfather", "Very enjoyable.");
movie_reviews.insert("The Blues Brothers", "Eye lyked it a lot.");
// check for a specific one.
if !movie_reviews.contains_key("Les Misérables") {
println!("We've got {} reviews, but Les Misérables ain't one.",
movie_reviews.len());
}
// oops, this review has a lot of spelling mistakes, let's delete it.
movie_reviews.remove("The Blues Brothers");
// look up the values associated with some keys.
let to_find = ["Up!", "Office Space"];
for movie in &to_find {
match movie_reviews.get(movie) {
Some(review) => println!("{movie}: {review}"),
None => println!("{movie} is unreviewed.")
}
}
// Look up the value for a key (will panic if the key is not found).
println!("Movie review: {}", movie_reviews["Office Space"]);
// iterate over everything.
for (movie, review) in &movie_reviews {
println!("{movie}: \"{review}\"");
}
```
A `BTreeMap` with a known list of items can be initialized from an array:
```
use std::collections::BTreeMap;
let solar_distance = BTreeMap::from([
("Mercury", 0.4),
("Venus", 0.7),
("Earth", 1.0),
("Mars", 1.5),
]);
```
`BTreeMap` implements an [`Entry API`](struct.btreemap#method.entry), which allows for complex methods of getting, setting, updating and removing keys and their values:
```
use std::collections::BTreeMap;
// type inference lets us omit an explicit type signature (which
// would be `BTreeMap<&str, u8>` in this example).
let mut player_stats = BTreeMap::new();
fn random_stat_buff() -> u8 {
// could actually return some random value here - let's just return
// some fixed value for now
42
}
// insert a key only if it doesn't already exist
player_stats.entry("health").or_insert(100);
// insert a key using a function that provides a new value only if it
// doesn't already exist
player_stats.entry("defence").or_insert_with(random_stat_buff);
// update a key, guarding against the key possibly not being set
let stat = player_stats.entry("attack").or_insert(100);
*stat += random_stat_buff();
// modify an entry before an insert with in-place mutation
player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#565)### impl<K, V> BTreeMap<K, V, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#585)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn new() -> BTreeMap<K, V, Global>
Makes a new, empty `BTreeMap`.
Does not allocate anything on its own.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
// entries can now be inserted into the empty map
map.insert(1, "a");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#590)### impl<K, V, A> BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#606)#### pub fn clear(&mut self)
Clears the map, removing all elements.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "a");
a.clear();
assert!(a.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#634)#### pub fn new\_in(alloc: A) -> BTreeMap<K, V, A>
🔬This is a nightly-only experimental API. (`btreemap_alloc` [#32838](https://github.com/rust-lang/rust/issues/32838))
Makes a new empty BTreeMap with a reasonable choice for B.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
use std::alloc::Global;
let mut map = BTreeMap::new_in(Global);
// entries can now be inserted into the empty map
map.insert(1, "a");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#639)### impl<K, V, A> BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#658-661)#### pub fn get<Q>(&self, key: &Q) -> Option<&V>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#686-689)1.40.0 · #### pub fn get\_key\_value<Q>(&self, k: &Q) -> Option<(&K, &V)>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#716-718)#### pub fn first\_key\_value(&self) -> Option<(&K, &V)>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the first key-value pair in the map. The key in this pair is the minimum key in the map.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
assert_eq!(map.first_key_value(), None);
map.insert(1, "b");
map.insert(2, "a");
assert_eq!(map.first_key_value(), Some((&1, &"b")));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#745-747)#### pub fn first\_entry(&mut self) -> Option<OccupiedEntry<'\_, K, V, A>>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the first entry in the map for in-place manipulation. The key of this entry is the minimum key in the map.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
if let Some(mut entry) = map.first_entry() {
if *entry.key() > 0 {
entry.insert("first");
}
}
assert_eq!(*map.get(&1).unwrap(), "first");
assert_eq!(*map.get(&2).unwrap(), "b");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#780-782)#### pub fn pop\_first(&mut self) -> Option<(K, V)>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes and returns the first element in the map. The key of this element is the minimum key that was in the map.
##### Examples
Draining elements in ascending order, while keeping a usable map each iteration.
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
while let Some((key, _val)) = map.pop_first() {
assert!(map.iter().all(|(k, _v)| *k > key));
}
assert!(map.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#804-806)#### pub fn last\_key\_value(&self) -> Option<(&K, &V)>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the last key-value pair in the map. The key in this pair is the maximum key in the map.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "b");
map.insert(2, "a");
assert_eq!(map.last_key_value(), Some((&2, &"a")));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#833-835)#### pub fn last\_entry(&mut self) -> Option<OccupiedEntry<'\_, K, V, A>>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the last entry in the map for in-place manipulation. The key of this entry is the maximum key in the map.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
if let Some(mut entry) = map.last_entry() {
if *entry.key() > 0 {
entry.insert("last");
}
}
assert_eq!(*map.get(&1).unwrap(), "a");
assert_eq!(*map.get(&2).unwrap(), "last");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#868-870)#### pub fn pop\_last(&mut self) -> Option<(K, V)>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes and returns the last element in the map. The key of this element is the maximum key that was in the map.
##### Examples
Draining elements in descending order, while keeping a usable map each iteration.
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
while let Some((key, _val)) = map.pop_last() {
assert!(map.iter().all(|(k, _v)| *k < key));
}
assert!(map.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#893-896)#### pub fn contains\_key<Q>(&self, key: &Q) -> boolwhere K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Returns `true` if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#922-925)#### pub fn get\_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
if let Some(x) = map.get_mut(&1) {
*x = "b";
}
assert_eq!(map[&1], "b");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#961-963)#### pub fn insert(&mut self, key: K, value: V) -> Option<V>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Inserts a key-value pair into the map.
If 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 value is returned. The key is not updated, though; this matters for types that can be `==` without being identical. See the [module-level documentation](index#insert-and-complex-keys) for more.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);
map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#998-1000)#### pub fn try\_insert( &mut self, key: K, value: V) -> Result<&mut V, OccupiedError<'\_, K, V, A>>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
Tries to insert a key-value pair into the map, and returns a mutable reference to the value in the entry.
If the map already had this key present, nothing is updated, and an error containing the occupied entry and the value is returned.
##### Examples
Basic usage:
```
#![feature(map_try_insert)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
assert_eq!(map.try_insert(37, "a").unwrap(), &"a");
let err = map.try_insert(37, "b").unwrap_err();
assert_eq!(err.entry.key(), &37);
assert_eq!(err.entry.get(), &"a");
assert_eq!(err.value, "b");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1027-1030)#### pub fn remove<Q>(&mut self, key: &Q) -> Option<V>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1054-1057)1.45.0 · #### pub fn remove\_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.remove_entry(&1), Some((1, "a")));
assert_eq!(map.remove_entry(&1), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1092-1095)1.53.0 · #### pub fn retain<F>(&mut self, f: F)where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)K, [&mut](../primitive.reference) V) -> [bool](../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all pairs `(k, v)` for which `f(&k, &mut v)` returns `false`. The elements are visited in ascending key order.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();
// Keep only the elements with even-numbered keys.
map.retain(|&k, _| k % 2 == 0);
assert!(map.into_iter().eq(vec![(0, 0), (2, 20), (4, 40), (6, 60)]));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1129-1132)1.11.0 · #### pub fn append(&mut self, other: &mut BTreeMap<K, V, A>)where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../clone/trait.clone "trait std::clone::Clone"),
Moves all elements from `other` into `self`, leaving `other` empty.
##### Examples
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "a");
a.insert(2, "b");
a.insert(3, "c");
let mut b = BTreeMap::new();
b.insert(3, "d");
b.insert(4, "e");
b.insert(5, "f");
a.append(&mut b);
assert_eq!(a.len(), 5);
assert_eq!(b.len(), 0);
assert_eq!(a[&1], "a");
assert_eq!(a[&2], "b");
assert_eq!(a[&3], "d");
assert_eq!(a[&4], "e");
assert_eq!(a[&5], "f");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1186-1190)1.17.0 · #### pub fn range<T, R>(&self, range: R) -> Range<'\_, K, V>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<T> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<T>,
Notable traits for [Range](btree_map/struct.range "struct std::collections::btree_map::Range")<'a, K, V>
```
impl<'a, K, V> Iterator for Range<'a, K, V>
type Item = (&'a K, &'a V);
```
Constructs a double-ended iterator over a sub-range of elements in the map. The simplest way is to use the range syntax `min..max`, thus `range(min..max)` will yield elements from min (inclusive) to max (exclusive). The range may also be entered as `(Bound<T>, Bound<T>)`, so for example `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive range from 4 to 10.
##### Panics
Panics if range `start > end`. Panics if range `start == end` and both bounds are `Excluded`.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
use std::ops::Bound::Included;
let mut map = BTreeMap::new();
map.insert(3, "a");
map.insert(5, "b");
map.insert(8, "c");
for (&key, &value) in map.range((Included(&4), Included(&8))) {
println!("{key}: {value}");
}
assert_eq!(Some((&5, &"b")), map.range(4..).next());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1228-1232)1.17.0 · #### pub fn range\_mut<T, R>(&mut self, range: R) -> RangeMut<'\_, K, V>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<T> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), R: [RangeBounds](../ops/trait.rangebounds "trait std::ops::RangeBounds")<T>,
Notable traits for [RangeMut](btree_map/struct.rangemut "struct std::collections::btree_map::RangeMut")<'a, K, V>
```
impl<'a, K, V> Iterator for RangeMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Constructs a mutable double-ended iterator over a sub-range of elements in the map. The simplest way is to use the range syntax `min..max`, thus `range(min..max)` will yield elements from min (inclusive) to max (exclusive). The range may also be entered as `(Bound<T>, Bound<T>)`, so for example `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive range from 4 to 10.
##### Panics
Panics if range `start > end`. Panics if range `start == end` and both bounds are `Excluded`.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, i32> =
[("Alice", 0), ("Bob", 0), ("Carol", 0), ("Cheryl", 0)].into();
for (_, balance) in map.range_mut("B".."Cheryl") {
*balance += 100;
}
for (name, balance) in &map {
println!("{name} => {balance}");
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1262-1264)#### pub fn entry(&mut self, key: K) -> Entry<'\_, K, V, A>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
Gets the given key’s corresponding entry in the map for in-place manipulation.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut count: BTreeMap<&str, usize> = BTreeMap::new();
// count the number of occurrences of letters in the vec
for x in ["a", "b", "a", "c", "a", "b"] {
count.entry(x).and_modify(|curr| *curr += 1).or_insert(1);
}
assert_eq!(count["a"], 3);
assert_eq!(count["b"], 2);
assert_eq!(count["c"], 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1323-1326)1.11.0 · #### pub fn split\_off<Q>(&mut self, key: &Q) -> BTreeMap<K, V, A>where Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"), K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../clone/trait.clone "trait std::clone::Clone"),
Splits the collection into two at the given key. Returns everything after the given key, including the key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "a");
a.insert(2, "b");
a.insert(3, "c");
a.insert(17, "d");
a.insert(41, "e");
let b = a.split_off(&3);
assert_eq!(a.len(), 2);
assert_eq!(b.len(), 3);
assert_eq!(a[&1], "a");
assert_eq!(a[&2], "b");
assert_eq!(b[&3], "c");
assert_eq!(b[&17], "d");
assert_eq!(b[&41], "e");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1381-1384)#### pub fn drain\_filter<F>(&mut self, pred: F) -> DrainFilter<'\_, K, V, F, A>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)K, [&mut](../primitive.reference) V) -> [bool](../primitive.bool),
Notable traits for [DrainFilter](btree_map/struct.drainfilter "struct std::collections::btree_map::DrainFilter")<'\_, K, V, F, A>
```
impl<K, V, F, A> Iterator for DrainFilter<'_, K, V, F, A>where
A: Allocator + Clone,
F: FnMut(&K, &mut V) -> bool,
type Item = (K, V);
```
🔬This is a nightly-only experimental API. (`btree_drain_filter` [#70530](https://github.com/rust-lang/rust/issues/70530))
Creates an iterator that visits all elements (key-value pairs) in ascending key order and uses a closure to determine if an element should be removed. If the closure returns `true`, the element is removed from the map and yielded. If the closure returns `false`, or panics, the element remains in the map and will not be yielded.
The iterator also lets you mutate the value of each element in the closure, regardless of whether you choose to keep or remove it.
If the iterator is only partially consumed or not consumed at all, each of the remaining elements is still subjected to the closure, which may change its value and, by returning `true`, have the element removed and dropped.
It is unspecified how many more elements will be subjected to the closure if a panic occurs in the closure, or a panic occurs while dropping an element, or if the `DrainFilter` value is leaked.
##### Examples
Splitting a map into even and odd keys, reusing the original map:
```
#![feature(btree_drain_filter)]
use std::collections::BTreeMap;
let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
let evens: BTreeMap<_, _> = map.drain_filter(|k, _v| k % 2 == 0).collect();
let odds = map;
assert_eq!(evens.keys().copied().collect::<Vec<_>>(), [0, 2, 4, 6]);
assert_eq!(odds.keys().copied().collect::<Vec<_>>(), [1, 3, 5, 7]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1435)1.54.0 · #### pub fn into\_keys(self) -> IntoKeys<K, V, A>
Notable traits for [IntoKeys](btree_map/struct.intokeys "struct std::collections::btree_map::IntoKeys")<K, V, A>
```
impl<K, V, A> Iterator for IntoKeys<K, V, A>where
A: Allocator + Clone,
type Item = K;
```
Creates a consuming iterator visiting all the keys, in sorted order. The map cannot be used after calling this. The iterator element type is `K`.
##### Examples
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(2, "b");
a.insert(1, "a");
let keys: Vec<i32> = a.into_keys().collect();
assert_eq!(keys, [1, 2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1457)1.54.0 · #### pub fn into\_values(self) -> IntoValues<K, V, A>
Notable traits for [IntoValues](btree_map/struct.intovalues "struct std::collections::btree_map::IntoValues")<K, V, A>
```
impl<K, V, A> Iterator for IntoValues<K, V, A>where
A: Allocator + Clone,
type Item = V;
```
Creates a consuming iterator visiting all the values, in order by key. The map cannot be used after calling this. The iterator element type is `V`.
##### Examples
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "hello");
a.insert(2, "goodbye");
let values: Vec<&str> = a.into_values().collect();
assert_eq!(values, ["hello", "goodbye"]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2245)### impl<K, V, A> BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2268)#### pub fn iter(&self) -> Iter<'\_, K, V>
Notable traits for [Iter](btree_map/struct.iter "struct std::collections::btree_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>where
K: 'a,
V: 'a,
type Item = (&'a K, &'a V);
```
Gets an iterator over the entries of the map, sorted by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(3, "c");
map.insert(2, "b");
map.insert(1, "a");
for (key, value) in map.iter() {
println!("{key}: {value}");
}
let (first_key, first_value) = map.iter().next().unwrap();
assert_eq!((*first_key, *first_value), (1, "a"));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2301)#### pub fn iter\_mut(&mut self) -> IterMut<'\_, K, V>
Notable traits for [IterMut](btree_map/struct.itermut "struct std::collections::btree_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Gets a mutable iterator over the entries of the map, sorted by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
// add 10 to the value if the key isn't "a"
for (key, value) in map.iter_mut() {
if key != &"a" {
*value += 10;
}
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2328)#### pub fn keys(&self) -> Keys<'\_, K, V>
Notable traits for [Keys](btree_map/struct.keys "struct std::collections::btree_map::Keys")<'a, K, V>
```
impl<'a, K, V> Iterator for Keys<'a, K, V>
type Item = &'a K;
```
Gets an iterator over the keys of the map, in sorted order.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(2, "b");
a.insert(1, "a");
let keys: Vec<_> = a.keys().cloned().collect();
assert_eq!(keys, [1, 2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2349)#### pub fn values(&self) -> Values<'\_, K, V>
Notable traits for [Values](btree_map/struct.values "struct std::collections::btree_map::Values")<'a, K, V>
```
impl<'a, K, V> Iterator for Values<'a, K, V>
type Item = &'a V;
```
Gets an iterator over the values of the map, in order by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "hello");
a.insert(2, "goodbye");
let values: Vec<&str> = a.values().cloned().collect();
assert_eq!(values, ["hello", "goodbye"]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2375)1.10.0 · #### pub fn values\_mut(&mut self) -> ValuesMut<'\_, K, V>
Notable traits for [ValuesMut](btree_map/struct.valuesmut "struct std::collections::btree_map::ValuesMut")<'a, K, V>
```
impl<'a, K, V> Iterator for ValuesMut<'a, K, V>
type Item = &'a mut V;
```
Gets a mutable iterator over the values of the map, in order by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, String::from("hello"));
a.insert(2, String::from("goodbye"));
for value in a.values_mut() {
value.push_str("!");
}
let values: Vec<String> = a.values().cloned().collect();
assert_eq!(values, [String::from("hello!"),
String::from("goodbye!")]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2396)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn len(&self) -> usize
Returns the number of elements in the map.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2417)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn is\_empty(&self) -> bool
Returns `true` if the map contains no elements.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#206)### impl<K, V, A> Clone for BTreeMap<K, V, A>where K: [Clone](../clone/trait.clone "trait std::clone::Clone"), V: [Clone](../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#207)#### fn clone(&self) -> BTreeMap<K, V, A>
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2198)### impl<K, V, A> Debug for BTreeMap<K, V, A>where K: [Debug](../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2199)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2164)### impl<K, V> Default for BTreeMap<K, V, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2166)#### fn default() -> BTreeMap<K, V, Global>
Creates an empty `BTreeMap`.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#186)1.7.0 · ### impl<K, V, A> Drop for BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#187)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2140-2141)1.2.0 · ### impl<'a, K, V, A> Extend<(&'a K, &'a V)> for BTreeMap<K, V, A>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + [Copy](../marker/trait.copy "trait std::marker::Copy"), V: [Copy](../marker/trait.copy "trait std::marker::Copy"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2143)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = ([&'a](../primitive.reference) K, [&'a](../primitive.reference) V)>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2148)#### fn extend\_one(&mut self, (&'a K, &'a V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2125)### impl<K, V, A> Extend<(K, V)> for BTreeMap<K, V, A>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2127)#### fn extend<T>(&mut self, iter: T)where T: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [(K, V)](../primitive.tuple)>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2134)#### fn extend\_one(&mut self, (K, V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2224)1.56.0 · ### impl<K, V, const N: usize> From<[(K, V); N]> for BTreeMap<K, V, Global>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2234)#### fn from(arr: [(K, V); N]) -> BTreeMap<K, V, Global>
Converts a `[(K, V); N]` into a `BTreeMap<(K, V)>`.
```
use std::collections::BTreeMap;
let map1 = BTreeMap::from([(1, 2), (3, 4)]);
let map2: BTreeMap<_, _> = [(1, 2), (3, 4)].into();
assert_eq!(map1, map2);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2110)### impl<K, V> FromIterator<(K, V)> for BTreeMap<K, V, Global>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2111)#### fn from\_iter<T>(iter: T) -> BTreeMap<K, V, Global>where T: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [(K, V)](../primitive.tuple)>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2154)### impl<K, V, A> Hash for BTreeMap<K, V, A>where K: [Hash](../hash/trait.hash "trait std::hash::Hash"), V: [Hash](../hash/trait.hash "trait std::hash::Hash"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2155)#### fn hash<H>(&self, state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2205)### impl<K, Q, V, A> Index<&Q> for BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"), K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2218)#### fn index(&self, key: &Q) -> &V
Returns a reference to the value corresponding to the supplied key.
##### Panics
Panics if the key is not present in the `BTreeMap`.
#### type Output = V
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1475)### impl<'a, K, V, A> IntoIterator for &'a BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Item = (&'a K, &'a V)
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1479)#### fn into\_iter(self) -> Iter<'a, K, V>
Notable traits for [Iter](btree_map/struct.iter "struct std::collections::btree_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>where
K: 'a,
V: 'a,
type Item = (&'a K, &'a V);
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1544)### impl<'a, K, V, A> IntoIterator for &'a mut BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Item = (&'a K, &'a mut V)
The type of the elements being iterated over.
#### type IntoIter = IterMut<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1548)#### fn into\_iter(self) -> IterMut<'a, K, V>
Notable traits for [IterMut](btree_map/struct.itermut "struct std::collections::btree_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1614)### impl<K, V, A> IntoIterator for BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Item = (K, V)
The type of the elements being iterated over.
#### type IntoIter = IntoIter<K, V, A>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1618)#### fn into\_iter(self) -> IntoIter<K, V, A>
Notable traits for [IntoIter](btree_map/struct.intoiter "struct std::collections::btree_map::IntoIter")<K, V, A>
```
impl<K, V, A> Iterator for IntoIter<K, V, A>where
A: Allocator + Clone,
type Item = (K, V);
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2190)### impl<K, V, A> Ord for BTreeMap<K, V, A>where K: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), V: [Ord](../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2192)#### fn cmp(&self, other: &BTreeMap<K, V, A>) -> Ordering
This method returns an [`Ordering`](../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2172)### impl<K, V, A> PartialEq<BTreeMap<K, V, A>> for BTreeMap<K, V, A>where K: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<K>, V: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<V>, A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2173)#### fn eq(&self, other: &BTreeMap<K, V, A>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2182)### impl<K, V, A> PartialOrd<BTreeMap<K, V, A>> for BTreeMap<K, V, A>where K: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>, V: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<V>, A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2184)#### fn partial\_cmp(&self, other: &BTreeMap<K, V, A>) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2179)### impl<K, V, A> Eq for BTreeMap<K, V, A>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq"), V: [Eq](../cmp/trait.eq "trait std::cmp::Eq"), A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#197)1.64.0 · ### impl<K, V, A> UnwindSafe for BTreeMap<K, V, A>where A: [Allocator](../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../clone/trait.clone "trait std::clone::Clone") + [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), K: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Auto Trait Implementations
--------------------------
### impl<K, V, A> RefUnwindSafe for BTreeMap<K, V, A>where A: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V, A> Send for BTreeMap<K, V, A>where A: [Send](../marker/trait.send "trait std::marker::Send"), K: [Send](../marker/trait.send "trait std::marker::Send"), V: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<K, V, A> Sync for BTreeMap<K, V, A>where A: [Sync](../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Unpin for BTreeMap<K, V, A>where A: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::LinkedList Struct std::collections::LinkedList
===================================
```
pub struct LinkedList<T> { /* private fields */ }
```
A doubly-linked list with owned nodes.
The `LinkedList` allows pushing and popping elements at either end in constant time.
A `LinkedList` with a known list of items can be initialized from an array:
```
use std::collections::LinkedList;
let list = LinkedList::from([1, 2, 3]);
```
NOTE: It is almost always better to use [`Vec`](../vec/struct.vec) or [`VecDeque`](struct.vecdeque) because array-based containers are generally faster, more memory efficient, and make better use of CPU cache.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#409)### impl<T> LinkedList<T>
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#423)const: 1.39.0 · #### pub const fn new() -> LinkedList<T>
Creates an empty `LinkedList`.
##### Examples
```
use std::collections::LinkedList;
let list: LinkedList<u32> = LinkedList::new();
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#457)#### pub fn append(&mut self, other: &mut LinkedList<T>)
Moves all elements from `other` to the end of the list.
This reuses all the nodes from `other` and moves them into `self`. After this operation, `other` becomes empty.
This operation should compute in *O*(1) time and *O*(1) memory.
##### Examples
```
use std::collections::LinkedList;
let mut list1 = LinkedList::new();
list1.push_back('a');
let mut list2 = LinkedList::new();
list2.push_back('b');
list2.push_back('c');
list1.append(&mut list2);
let mut iter = list1.iter();
assert_eq!(iter.next(), Some(&'a'));
assert_eq!(iter.next(), Some(&'b'));
assert_eq!(iter.next(), Some(&'c'));
assert!(iter.next().is_none());
assert!(list2.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#497)#### pub fn iter(&self) -> Iter<'\_, T>
Notable traits for [Iter](linked_list/struct.iter "struct std::collections::linked_list::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Provides a forward iterator.
##### Examples
```
use std::collections::LinkedList;
let mut list: LinkedList<u32> = LinkedList::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
let mut iter = list.iter();
assert_eq!(iter.next(), Some(&0));
assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#526)#### pub fn iter\_mut(&mut self) -> IterMut<'\_, T>
Notable traits for [IterMut](linked_list/struct.itermut "struct std::collections::linked_list::IterMut")<'a, T>
```
impl<'a, T> Iterator for IterMut<'a, T>
type Item = &'a mut T;
```
Provides a forward iterator with mutable references.
##### Examples
```
use std::collections::LinkedList;
let mut list: LinkedList<u32> = LinkedList::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
for element in list.iter_mut() {
*element += 10;
}
let mut iter = list.iter();
assert_eq!(iter.next(), Some(&10));
assert_eq!(iter.next(), Some(&11));
assert_eq!(iter.next(), Some(&12));
assert_eq!(iter.next(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#536)#### pub fn cursor\_front(&self) -> Cursor<'\_, T>
🔬This is a nightly-only experimental API. (`linked_list_cursors` [#58533](https://github.com/rust-lang/rust/issues/58533))
Provides a cursor at the front element.
The cursor is pointing to the “ghost” non-element if the list is empty.
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#546)#### pub fn cursor\_front\_mut(&mut self) -> CursorMut<'\_, T>
🔬This is a nightly-only experimental API. (`linked_list_cursors` [#58533](https://github.com/rust-lang/rust/issues/58533))
Provides a cursor with editing operations at the front element.
The cursor is pointing to the “ghost” non-element if the list is empty.
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#556)#### pub fn cursor\_back(&self) -> Cursor<'\_, T>
🔬This is a nightly-only experimental API. (`linked_list_cursors` [#58533](https://github.com/rust-lang/rust/issues/58533))
Provides a cursor at the back element.
The cursor is pointing to the “ghost” non-element if the list is empty.
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#566)#### pub fn cursor\_back\_mut(&mut self) -> CursorMut<'\_, T>
🔬This is a nightly-only experimental API. (`linked_list_cursors` [#58533](https://github.com/rust-lang/rust/issues/58533))
Provides a cursor with editing operations at the back element.
The cursor is pointing to the “ghost” non-element if the list is empty.
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#588)#### pub fn is\_empty(&self) -> bool
Returns `true` if the `LinkedList` is empty.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
assert!(dl.is_empty());
dl.push_front("foo");
assert!(!dl.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#615)#### pub fn len(&self) -> usize
Returns the length of the `LinkedList`.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
dl.push_front(2);
assert_eq!(dl.len(), 1);
dl.push_front(1);
assert_eq!(dl.len(), 2);
dl.push_back(3);
assert_eq!(dl.len(), 3);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#641)#### pub fn clear(&mut self)
Removes all elements from the `LinkedList`.
This operation should compute in *O*(*n*) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
dl.push_front(2);
dl.push_front(1);
assert_eq!(dl.len(), 2);
assert_eq!(dl.front(), Some(&1));
dl.clear();
assert_eq!(dl.len(), 0);
assert_eq!(dl.front(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#665-667)1.12.0 · #### pub fn contains(&self, x: &T) -> boolwhere T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<T>,
Returns `true` if the `LinkedList` contains an element equal to the given value.
This operation should compute linearly in *O*(*n*) time.
##### Examples
```
use std::collections::LinkedList;
let mut list: LinkedList<u32> = LinkedList::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
assert_eq!(list.contains(&0), true);
assert_eq!(list.contains(&10), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#691)#### pub fn front(&self) -> Option<&T>
Provides a reference to the front element, or `None` if the list is empty.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
assert_eq!(dl.front(), None);
dl.push_front(1);
assert_eq!(dl.front(), Some(&1));
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#720)#### pub fn front\_mut(&mut self) -> Option<&mut T>
Provides a mutable reference to the front element, or `None` if the list is empty.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
assert_eq!(dl.front(), None);
dl.push_front(1);
assert_eq!(dl.front(), Some(&1));
match dl.front_mut() {
None => {},
Some(x) => *x = 5,
}
assert_eq!(dl.front(), Some(&5));
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#743)#### pub fn back(&self) -> Option<&T>
Provides a reference to the back element, or `None` if the list is empty.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
assert_eq!(dl.back(), None);
dl.push_back(1);
assert_eq!(dl.back(), Some(&1));
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#771)#### pub fn back\_mut(&mut self) -> Option<&mut T>
Provides a mutable reference to the back element, or `None` if the list is empty.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
assert_eq!(dl.back(), None);
dl.push_back(1);
assert_eq!(dl.back(), Some(&1));
match dl.back_mut() {
None => {},
Some(x) => *x = 5,
}
assert_eq!(dl.back(), Some(&5));
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#793)#### pub fn push\_front(&mut self, elt: T)
Adds an element first in the list.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut dl = LinkedList::new();
dl.push_front(2);
assert_eq!(dl.front().unwrap(), &2);
dl.push_front(1);
assert_eq!(dl.front().unwrap(), &1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#817)#### pub fn pop\_front(&mut self) -> Option<T>
Removes the first element and returns it, or `None` if the list is empty.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut d = LinkedList::new();
assert_eq!(d.pop_front(), None);
d.push_front(1);
d.push_front(3);
assert_eq!(d.pop_front(), Some(3));
assert_eq!(d.pop_front(), Some(1));
assert_eq!(d.pop_front(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#836)#### pub fn push\_back(&mut self, elt: T)
Appends an element to the back of a list.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut d = LinkedList::new();
d.push_back(1);
d.push_back(3);
assert_eq!(3, *d.back().unwrap());
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#857)#### pub fn pop\_back(&mut self) -> Option<T>
Removes the last element from a list and returns it, or `None` if it is empty.
This operation should compute in *O*(1) time.
##### Examples
```
use std::collections::LinkedList;
let mut d = LinkedList::new();
assert_eq!(d.pop_back(), None);
d.push_back(1);
d.push_back(3);
assert_eq!(d.pop_back(), Some(3));
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#887)#### pub fn split\_off(&mut self, at: usize) -> LinkedList<T>
Splits the list into two at the given index. Returns everything after the given index, including the index.
This operation should compute in *O*(*n*) time.
##### Panics
Panics if `at > len`.
##### Examples
```
use std::collections::LinkedList;
let mut d = LinkedList::new();
d.push_front(1);
d.push_front(2);
d.push_front(3);
let mut split = d.split_off(2);
assert_eq!(split.pop_front(), Some(1));
assert_eq!(split.pop_front(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#942)#### pub fn remove(&mut self, at: usize) -> T
🔬This is a nightly-only experimental API. (`linked_list_remove` [#69210](https://github.com/rust-lang/rust/issues/69210))
Removes the element at the given index and returns it.
This operation should compute in *O*(*n*) time.
##### Panics
Panics if at >= len
##### Examples
```
#![feature(linked_list_remove)]
use std::collections::LinkedList;
let mut d = LinkedList::new();
d.push_front(1);
d.push_front(2);
d.push_front(3);
assert_eq!(d.remove(1), 2);
assert_eq!(d.remove(0), 3);
assert_eq!(d.remove(0), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#991-993)#### pub fn drain\_filter<F>(&mut self, filter: F) -> DrainFilter<'\_, T, F>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../primitive.reference) T) -> [bool](../primitive.bool),
Notable traits for [DrainFilter](linked_list/struct.drainfilter "struct std::collections::linked_list::DrainFilter")<'\_, T, F>
```
impl<T, F> Iterator for DrainFilter<'_, T, F>where
F: FnMut(&mut T) -> bool,
type Item = T;
```
🔬This is a nightly-only experimental API. (`drain_filter` [#43244](https://github.com/rust-lang/rust/issues/43244))
Creates an iterator which uses a closure to determine if an element should be removed.
If the closure returns true, then the element is removed and yielded. If the closure returns false, the element will remain in the list and will not be yielded by the iterator.
Note that `drain_filter` lets you mutate every element in the filter closure, regardless of whether you choose to keep or remove it.
##### Examples
Splitting a list into evens and odds, reusing the original list:
```
#![feature(drain_filter)]
use std::collections::LinkedList;
let mut numbers: LinkedList<u32> = LinkedList::new();
numbers.extend(&[1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]);
let evens = numbers.drain_filter(|x| *x % 2 == 0).collect::<LinkedList<_>>();
let odds = numbers;
assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![2, 4, 6, 8, 14]);
assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 9, 11, 13, 15]);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1918)### impl<T> Clone for LinkedList<T>where T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1919)#### fn clone(&self) -> LinkedList<T>
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1923)#### fn clone\_from(&mut self, other: &LinkedList<T>)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1938)### impl<T> Debug for LinkedList<T>where T: [Debug](../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1939)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#401)### impl<T> Default for LinkedList<T>
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#404)#### fn default() -> LinkedList<T>
Creates an empty `LinkedList<T>`.
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1004)### impl<T> Drop for LinkedList<T>
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1005)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1877)1.2.0 · ### impl<'a, T> Extend<&'a T> for LinkedList<T>where T: 'a + [Copy](../marker/trait.copy "trait std::marker::Copy"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1878)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [&'a](../primitive.reference) T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1883)#### fn extend\_one(&mut self, &'a T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1853)### impl<T> Extend<T> for LinkedList<T>
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1854)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1859)#### fn extend\_one(&mut self, elem: T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1955)1.56.0 · ### impl<T, const N: usize> From<[T; N]> for LinkedList<T>
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1965)#### fn from(arr: [T; N]) -> LinkedList<T>
Converts a `[T; N]` into a `LinkedList<T>`.
```
use std::collections::LinkedList;
let list1 = LinkedList::from([1, 2, 3, 4]);
let list2: LinkedList<_> = [1, 2, 3, 4].into();
assert_eq!(list1, list2);
```
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1812)### impl<T> FromIterator<T> for LinkedList<T>
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1813)#### fn from\_iter<I>(iter: I) -> LinkedList<T>where I: [IntoIterator](../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1945)### impl<T> Hash for LinkedList<T>where T: [Hash](../hash/trait.hash "trait std::hash::Hash"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1946)#### fn hash<H>(&self, state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../hash/trait.hasher "Hasher"). [Read more](../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1833)### impl<'a, T> IntoIterator for &'a LinkedList<T>
#### type Item = &'a T
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1837)#### fn into\_iter(self) -> Iter<'a, T>
Notable traits for [Iter](linked_list/struct.iter "struct std::collections::linked_list::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1843)### impl<'a, T> IntoIterator for &'a mut LinkedList<T>
#### type Item = &'a mut T
The type of the elements being iterated over.
#### type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1847)#### fn into\_iter(self) -> IterMut<'a, T>
Notable traits for [IterMut](linked_list/struct.itermut "struct std::collections::linked_list::IterMut")<'a, T>
```
impl<'a, T> Iterator for IterMut<'a, T>
type Item = &'a mut T;
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1821)### impl<T> IntoIterator for LinkedList<T>
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1827)#### fn into\_iter(self) -> IntoIter<T>
Notable traits for [IntoIter](linked_list/struct.intoiter "struct std::collections::linked_list::IntoIter")<T>
```
impl<T> Iterator for IntoIter<T>
type Item = T;
```
Consumes the list into an iterator yielding elements by value.
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1910)### impl<T> Ord for LinkedList<T>where T: [Ord](../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1912)#### fn cmp(&self, other: &LinkedList<T>) -> Ordering
This method returns an [`Ordering`](../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1889)### impl<T> PartialEq<LinkedList<T>> for LinkedList<T>where T: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq")<T>,
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1890)#### fn eq(&self, other: &LinkedList<T>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1894)#### fn ne(&self, other: &LinkedList<T>) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1903)### impl<T> PartialOrd<LinkedList<T>> for LinkedList<T>where T: [PartialOrd](../cmp/trait.partialord "trait std::cmp::PartialOrd")<T>,
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1904)#### fn partial\_cmp(&self, other: &LinkedList<T>) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1900)### impl<T> Eq for LinkedList<T>where T: [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1985)### impl<T> Send for LinkedList<T>where T: [Send](../marker/trait.send "trait std::marker::Send"),
[source](https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#1988)### impl<T> Sync for LinkedList<T>where T: [Sync](../marker/trait.sync "trait std::marker::Sync"),
Auto Trait Implementations
--------------------------
### impl<T> RefUnwindSafe for LinkedList<T>where T: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T> Unpin for LinkedList<T>
### impl<T> UnwindSafe for LinkedList<T>where T: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::HashMap Struct std::collections::HashMap
================================
```
pub struct HashMap<K, V, S = RandomState> { /* private fields */ }
```
A [hash map](index#use-a-hashmap-when) implemented with quadratic probing and SIMD lookup.
By default, `HashMap` uses a hashing algorithm selected to provide resistance against HashDoS attacks. The algorithm is randomly seeded, and a reasonable best-effort is made to generate this seed from a high quality, secure source of randomness provided by the host without blocking the program. Because of this, the randomness of the seed depends on the output quality of the system’s random number generator when the seed is created. In particular, seeds generated when the system’s entropy pool is abnormally low such as during system boot may be of a lower quality.
The default hashing algorithm is currently SipHash 1-3, though this is subject to change at any point in the future. While its performance is very competitive for medium sized keys, other hashing algorithms will outperform it for small keys such as integers as well as large keys such as long strings, though those algorithms will typically *not* protect against attacks such as HashDoS.
The hashing algorithm can be replaced on a per-`HashMap` basis using the [`default`](../default/trait.default#tymethod.default), [`with_hasher`](hash_map/struct.hashmap#method.with_hasher), and [`with_capacity_and_hasher`](hash_map/struct.hashmap#method.with_capacity_and_hasher) methods. There are many alternative [hashing algorithms available on crates.io](https://crates.io/keywords/hasher).
It is required that the keys implement the [`Eq`](../cmp/trait.eq "Eq") and [`Hash`](../hash/trait.hash "Hash") traits, although this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`. If you implement these yourself, it is important that the following property holds:
```
k1 == k2 -> hash(k1) == hash(k2)
```
In other words, if two keys are equal, their hashes must be equal.
It is a logic error for a key to be modified in such a way that the key’s hash, as determined by the [`Hash`](../hash/trait.hash "Hash") trait, or its equality, as determined by the [`Eq`](../cmp/trait.eq "Eq") trait, changes while it is in the map. This is normally only possible through [`Cell`](../cell/struct.cell), [`RefCell`](../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `HashMap` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
The hash table implementation is a Rust port of Google’s [SwissTable](https://abseil.io/blog/20180927-swisstables). The original C++ version of SwissTable can be found [here](https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h), and this [CppCon talk](https://www.youtube.com/watch?v=ncHmEUmJZf4) gives an overview of how the algorithm works.
Examples
--------
```
use std::collections::HashMap;
// Type inference lets us omit an explicit type signature (which
// would be `HashMap<String, String>` in this example).
let mut book_reviews = HashMap::new();
// Review some books.
book_reviews.insert(
"Adventures of Huckleberry Finn".to_string(),
"My favorite book.".to_string(),
);
book_reviews.insert(
"Grimms' Fairy Tales".to_string(),
"Masterpiece.".to_string(),
);
book_reviews.insert(
"Pride and Prejudice".to_string(),
"Very enjoyable.".to_string(),
);
book_reviews.insert(
"The Adventures of Sherlock Holmes".to_string(),
"Eye lyked it alot.".to_string(),
);
// Check for a specific one.
// When collections store owned values (String), they can still be
// queried using references (&str).
if !book_reviews.contains_key("Les Misérables") {
println!("We've got {} reviews, but Les Misérables ain't one.",
book_reviews.len());
}
// oops, this review has a lot of spelling mistakes, let's delete it.
book_reviews.remove("The Adventures of Sherlock Holmes");
// Look up the values associated with some keys.
let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
for &book in &to_find {
match book_reviews.get(book) {
Some(review) => println!("{book}: {review}"),
None => println!("{book} is unreviewed.")
}
}
// Look up the value for a key (will panic if the key is not found).
println!("Review for Jane: {}", book_reviews["Pride and Prejudice"]);
// Iterate over everything.
for (book, review) in &book_reviews {
println!("{book}: \"{review}\"");
}
```
A `HashMap` with a known list of items can be initialized from an array:
```
use std::collections::HashMap;
let solar_distance = HashMap::from([
("Mercury", 0.4),
("Venus", 0.7),
("Earth", 1.0),
("Mars", 1.5),
]);
```
`HashMap` implements an [`Entry` API](#method.entry), which allows for complex methods of getting, setting, updating and removing keys and their values:
```
use std::collections::HashMap;
// type inference lets us omit an explicit type signature (which
// would be `HashMap<&str, u8>` in this example).
let mut player_stats = HashMap::new();
fn random_stat_buff() -> u8 {
// could actually return some random value here - let's just return
// some fixed value for now
42
}
// insert a key only if it doesn't already exist
player_stats.entry("health").or_insert(100);
// insert a key using a function that provides a new value only if it
// doesn't already exist
player_stats.entry("defence").or_insert_with(random_stat_buff);
// update a key, guarding against the key possibly not being set
let stat = player_stats.entry("attack").or_insert(100);
*stat += random_stat_buff();
// modify an entry before an insert with in-place mutation
player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100);
```
The easiest way to use `HashMap` with a custom key type is to derive [`Eq`](../cmp/trait.eq "Eq") and [`Hash`](../hash/trait.hash "Hash"). We must also derive [`PartialEq`](../cmp/trait.partialeq "PartialEq").
```
use std::collections::HashMap;
#[derive(Hash, Eq, PartialEq, Debug)]
struct Viking {
name: String,
country: String,
}
impl Viking {
/// Creates a new Viking.
fn new(name: &str, country: &str) -> Viking {
Viking { name: name.to_string(), country: country.to_string() }
}
}
// Use a HashMap to store the vikings' health points.
let vikings = HashMap::from([
(Viking::new("Einar", "Norway"), 25),
(Viking::new("Olaf", "Denmark"), 24),
(Viking::new("Harald", "Iceland"), 12),
]);
// Use derived implementation to print the status of the vikings.
for (viking, health) in &vikings {
println!("{viking:?} has {health} hp");
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#219-256)### impl<K, V> HashMap<K, V, RandomState>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#234-236)#### pub fn new() -> HashMap<K, V, RandomState>
Creates an empty `HashMap`.
The hash map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, i32> = HashMap::new();
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#253-255)#### pub fn with\_capacity(capacity: usize) -> HashMap<K, V, RandomState>
Creates an empty `HashMap` with at least the specified capacity.
The hash map will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is 0, the hash set will not allocate.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#258-730)### impl<K, V, S> HashMap<K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#284-286)1.7.0 · #### pub fn with\_hasher(hash\_builder: S) -> HashMap<K, V, S>
Creates an empty `HashMap` which will use the given hash builder to hash keys.
The created map has the default initial capacity.
Warning: `hash_builder` is normally randomly generated, and is designed to allow HashMaps to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.
The `hash_builder` passed should implement the [`BuildHasher`](../hash/trait.buildhasher "BuildHasher") trait for the HashMap to be useful, see its documentation for details.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
let s = RandomState::new();
let mut map = HashMap::with_hasher(s);
map.insert(1, 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#315-317)1.7.0 · #### pub fn with\_capacity\_and\_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty `HashMap` with at least the specified capacity, using `hasher` to hash the keys.
The hash map will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is 0, the hash map will not allocate.
Warning: `hasher` is normally randomly generated, and is designed to allow HashMaps to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.
The `hasher` passed should implement the [`BuildHasher`](../hash/trait.buildhasher "BuildHasher") trait for the HashMap to be useful, see its documentation for details.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
let s = RandomState::new();
let mut map = HashMap::with_capacity_and_hasher(10, s);
map.insert(1, 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#333-335)#### pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the `HashMap<K, V>` might be able to hold more, but is guaranteed to be able to hold at least this many.
##### Examples
```
use std::collections::HashMap;
let map: HashMap<i32, i32> = HashMap::with_capacity(100);
assert!(map.capacity() >= 100);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#361-363)#### pub fn keys(&self) -> Keys<'\_, K, V>
Notable traits for [Keys](hash_map/struct.keys "struct std::collections::hash_map::Keys")<'a, K, V>
```
impl<'a, K, V> Iterator for Keys<'a, K, V>
type Item = &'a K;
```
An iterator visiting all keys in arbitrary order. The iterator element type is `&'a K`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for key in map.keys() {
println!("{key}");
}
```
##### Performance
In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#394-396)1.54.0 · #### pub fn into\_keys(self) -> IntoKeys<K, V>
Notable traits for [IntoKeys](hash_map/struct.intokeys "struct std::collections::hash_map::IntoKeys")<K, V>
```
impl<K, V> Iterator for IntoKeys<K, V>
type Item = K;
```
Creates a consuming iterator visiting all the keys in arbitrary order. The map cannot be used after calling this. The iterator element type is `K`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
let mut vec: Vec<&str> = map.into_keys().collect();
// The `IntoKeys` iterator produces keys in arbitrary order, so the
// keys must be sorted to test them against a sorted array.
vec.sort_unstable();
assert_eq!(vec, ["a", "b", "c"]);
```
##### Performance
In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#422-424)#### pub fn values(&self) -> Values<'\_, K, V>
Notable traits for [Values](hash_map/struct.values "struct std::collections::hash_map::Values")<'a, K, V>
```
impl<'a, K, V> Iterator for Values<'a, K, V>
type Item = &'a V;
```
An iterator visiting all values in arbitrary order. The iterator element type is `&'a V`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for val in map.values() {
println!("{val}");
}
```
##### Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#454-456)1.10.0 · #### pub fn values\_mut(&mut self) -> ValuesMut<'\_, K, V>
Notable traits for [ValuesMut](hash_map/struct.valuesmut "struct std::collections::hash_map::ValuesMut")<'a, K, V>
```
impl<'a, K, V> Iterator for ValuesMut<'a, K, V>
type Item = &'a mut V;
```
An iterator visiting all values mutably in arbitrary order. The iterator element type is `&'a mut V`.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for val in map.values_mut() {
*val = *val + 10;
}
for val in map.values() {
println!("{val}");
}
```
##### Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#487-489)1.54.0 · #### pub fn into\_values(self) -> IntoValues<K, V>
Notable traits for [IntoValues](hash_map/struct.intovalues "struct std::collections::hash_map::IntoValues")<K, V>
```
impl<K, V> Iterator for IntoValues<K, V>
type Item = V;
```
Creates a consuming iterator visiting all the values in arbitrary order. The map cannot be used after calling this. The iterator element type is `V`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
let mut vec: Vec<i32> = map.into_values().collect();
// The `IntoValues` iterator produces values in arbitrary order, so
// the values must be sorted to test them against a sorted array.
vec.sort_unstable();
assert_eq!(vec, [1, 2, 3]);
```
##### Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#516-518)#### pub fn iter(&self) -> Iter<'\_, K, V>
Notable traits for [Iter](hash_map/struct.iter "struct std::collections::hash_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>
type Item = (&'a K, &'a V);
```
An iterator visiting all key-value pairs in arbitrary order. The iterator element type is `(&'a K, &'a V)`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for (key, val) in map.iter() {
println!("key: {key} val: {val}");
}
```
##### Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#551-553)#### pub fn iter\_mut(&mut self) -> IterMut<'\_, K, V>
Notable traits for [IterMut](hash_map/struct.itermut "struct std::collections::hash_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values. The iterator element type is `(&'a K, &'a mut V)`.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
// Update all values
for (_, val) in map.iter_mut() {
*val *= 2;
}
for (key, val) in &map {
println!("key: {key} val: {val}");
}
```
##### Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#568-570)#### pub fn len(&self) -> usize
Returns the number of elements in the map.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#586-588)#### pub fn is\_empty(&self) -> bool
Returns `true` if the map contains no elements.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#616-618)1.6.0 · #### pub fn drain(&mut self) -> Drain<'\_, K, V>
Notable traits for [Drain](hash_map/struct.drain "struct std::collections::hash_map::Drain")<'a, K, V>
```
impl<'a, K, V> Iterator for Drain<'a, K, V>
type Item = (K, V);
```
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
If the returned iterator is dropped before being fully consumed, it drops the remaining key-value pairs. The returned iterator keeps a mutable borrow on the map to optimize its implementation.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
a.insert(1, "a");
a.insert(2, "b");
for (k, v) in a.drain().take(1) {
assert!(k == 1 || k == 2);
assert!(v == "a" || v == "b");
}
assert!(a.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#658-663)#### pub fn drain\_filter<F>(&mut self, pred: F) -> DrainFilter<'\_, K, V, F>where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)K, [&mut](../primitive.reference) V) -> [bool](../primitive.bool),
Notable traits for [DrainFilter](hash_map/struct.drainfilter "struct std::collections::hash_map::DrainFilter")<'\_, K, V, F>
```
impl<K, V, F> Iterator for DrainFilter<'_, K, V, F>where
F: FnMut(&K, &mut V) -> bool,
type Item = (K, V);
```
🔬This is a nightly-only experimental API. (`hash_drain_filter` [#59618](https://github.com/rust-lang/rust/issues/59618))
Creates an iterator which uses a closure to determine if an element should be removed.
If the closure returns true, the element is removed from the map and yielded. If the closure returns false, or panics, the element remains in the map and will not be yielded.
Note that `drain_filter` lets you mutate every value in the filter closure, regardless of whether you choose to keep or remove it.
If the iterator is only partially consumed or not consumed at all, each of the remaining elements will still be subjected to the closure and removed and dropped if it returns true.
It is unspecified how many more elements will be subjected to the closure if a panic occurs in the closure, or a panic occurs while dropping an element, or if the `DrainFilter` value is leaked.
##### Examples
Splitting a map into even and odd keys, reusing the original map:
```
#![feature(hash_drain_filter)]
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
let drained: HashMap<i32, i32> = map.drain_filter(|k, _v| k % 2 == 0).collect();
let mut evens = drained.keys().copied().collect::<Vec<_>>();
let mut odds = map.keys().copied().collect::<Vec<_>>();
evens.sort();
odds.sort();
assert_eq!(evens, vec![0, 2, 4, 6]);
assert_eq!(odds, vec![1, 3, 5, 7]);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#687-692)1.18.0 · #### pub fn retain<F>(&mut self, f: F)where F: [FnMut](../ops/trait.fnmut "trait std::ops::FnMut")([&](../primitive.reference)K, [&mut](../primitive.reference) V) -> [bool](../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all pairs `(k, v)` for which `f(&k, &mut v)` returns `false`. The elements are visited in unsorted (and unspecified) order.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();
map.retain(|&k, _| k % 2 == 0);
assert_eq!(map.len(), 4);
```
##### Performance
In the current implementation, this operation takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#709-711)#### pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
a.insert(1, "a");
a.clear();
assert!(a.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#727-729)1.9.0 · #### pub fn hasher(&self) -> &S
Returns a reference to the map’s [`BuildHasher`](../hash/trait.buildhasher "BuildHasher").
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
let hasher = RandomState::new();
let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
let hasher: &RandomState = map.hasher();
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#732-1193)### impl<K, V, S> HashMap<K, V, S>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#756-758)#### pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least `additional` more elements to be inserted in the `HashMap`. The collection may reserve more space to speculatively avoid frequent reallocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional`. Does nothing if capacity is already sufficient.
##### Panics
Panics if the new allocation size overflows [`usize`](../primitive.usize "usize").
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, i32> = HashMap::new();
map.reserve(10);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#782-784)1.57.0 · #### pub fn try\_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least `additional` more elements to be inserted in the `HashMap`. The collection may reserve more space to speculatively avoid frequent reallocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if capacity is already sufficient.
##### Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, isize> = HashMap::new();
map.try_reserve(10).expect("why is the test harness OOMing on a handful of bytes?");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#804-806)#### pub fn shrink\_to\_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
map.insert(1, 2);
map.insert(3, 4);
assert!(map.capacity() >= 100);
map.shrink_to_fit();
assert!(map.capacity() >= 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#830-832)1.56.0 · #### pub fn shrink\_to(&mut self, min\_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop down no lower than the supplied limit while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
If the current capacity is less than the lower limit, this is a no-op.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
map.insert(1, 2);
map.insert(3, 4);
assert!(map.capacity() >= 100);
map.shrink_to(10);
assert!(map.capacity() >= 10);
map.shrink_to(0);
assert!(map.capacity() >= 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#854-856)#### pub fn entry(&mut self, key: K) -> Entry<'\_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
##### Examples
```
use std::collections::HashMap;
let mut letters = HashMap::new();
for ch in "a short treatise on fungi".chars() {
letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);
}
assert_eq!(letters[&'s'], 2);
assert_eq!(letters[&'t'], 3);
assert_eq!(letters[&'u'], 1);
assert_eq!(letters.get(&'y'), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#876-882)#### pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#902-908)1.40.0 · #### pub fn get\_key\_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#956-962)#### pub fn get\_many\_mut<Q: ?Sized, const N: usize>( &mut self, ks: [&Q; N]) -> Option<[&mut V; N]>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`map_many_mut` [#97601](https://github.com/rust-lang/rust/issues/97601))
Attempts to get mutable references to `N` values in the map at once.
Returns an array of length `N` with the results of each query. For soundness, at most one mutable reference will be returned to any value. `None` will be returned if any of the keys are duplicates or missing.
##### Examples
```
#![feature(map_many_mut)]
use std::collections::HashMap;
let mut libraries = HashMap::new();
libraries.insert("Bodleian Library".to_string(), 1602);
libraries.insert("Athenæum".to_string(), 1807);
libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
libraries.insert("Library of Congress".to_string(), 1800);
let got = libraries.get_many_mut([
"Athenæum",
"Library of Congress",
]);
assert_eq!(
got,
Some([
&mut 1807,
&mut 1800,
]),
);
// Missing keys result in None
let got = libraries.get_many_mut([
"Athenæum",
"New York Public Library",
]);
assert_eq!(got, None);
// Duplicate keys result in None
let got = libraries.get_many_mut([
"Athenæum",
"Athenæum",
]);
assert_eq!(got, None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1012-1021)#### pub unsafe fn get\_many\_unchecked\_mut<Q: ?Sized, const N: usize>( &mut self, ks: [&Q; N]) -> Option<[&mut V; N]>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`map_many_mut` [#97601](https://github.com/rust-lang/rust/issues/97601))
Attempts to get mutable references to `N` values in the map at once, without validating that the values are unique.
Returns an array of length `N` with the results of each query. `None` will be returned if any of the keys are missing.
For a safe alternative see [`get_many_mut`](hash_map/struct.hashmap#method.get_many_mut).
##### Safety
Calling this method with overlapping keys is *[undefined behavior](../../reference/behavior-considered-undefined)* even if the resulting references are not used.
##### Examples
```
#![feature(map_many_mut)]
use std::collections::HashMap;
let mut libraries = HashMap::new();
libraries.insert("Bodleian Library".to_string(), 1602);
libraries.insert("Athenæum".to_string(), 1807);
libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
libraries.insert("Library of Congress".to_string(), 1800);
let got = libraries.get_many_mut([
"Athenæum",
"Library of Congress",
]);
assert_eq!(
got,
Some([
&mut 1807,
&mut 1800,
]),
);
// Missing keys result in None
let got = libraries.get_many_mut([
"Athenæum",
"New York Public Library",
]);
assert_eq!(got, None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1041-1047)#### pub fn contains\_key<Q: ?Sized>(&self, k: &Q) -> boolwhere K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Returns `true` if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1069-1075)#### pub fn get\_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
if let Some(x) = map.get_mut(&1) {
*x = "b";
}
assert_eq!(map[&1], "b");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1103-1105)#### pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
If the map did not have this key present, [`None`](../option/enum.option#variant.None "None") is returned.
If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be `==` without being identical. See the [module-level documentation](index#insert-and-complex-keys) for more.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);
map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1131-1136)#### pub fn try\_insert( &mut self, key: K, value: V) -> Result<&mut V, OccupiedError<'\_, K, V>>
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
Tries to insert a key-value pair into the map, and returns a mutable reference to the value in the entry.
If the map already had this key present, nothing is updated, and an error containing the occupied entry and the value is returned.
##### Examples
Basic usage:
```
#![feature(map_try_insert)]
use std::collections::HashMap;
let mut map = HashMap::new();
assert_eq!(map.try_insert(37, "a").unwrap(), &"a");
let err = map.try_insert(37, "b").unwrap_err();
assert_eq!(err.entry.key(), &37);
assert_eq!(err.entry.get(), &"a");
assert_eq!(err.value, "b");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1157-1163)#### pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1186-1192)1.27.0 · #### pub fn remove\_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(K, V)>where K: [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../hash/trait.hash "trait std::hash::Hash") + [Eq](../cmp/trait.eq "trait std::cmp::Eq"),
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but [`Hash`](../hash/trait.hash "Hash") and [`Eq`](../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove_entry(&1), Some((1, "a")));
assert_eq!(map.remove(&1), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1195-1256)### impl<K, V, S> HashMap<K, V, S>where S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1232-1234)#### pub fn raw\_entry\_mut(&mut self) -> RawEntryBuilderMut<'\_, K, V, S>
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Creates a raw entry builder for the HashMap.
Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched. After this, insertions into a vacant entry still require an owned key to be provided.
Raw entries are useful for such exotic situations as:
* Hash memoization
* Deferring the creation of an owned key until it is known to be required
* Using a search key that doesn’t work with the Borrow trait
* Using custom comparison logic without newtype wrappers
Because raw entries provide much more low-level control, it’s much easier to put the HashMap into an inconsistent state which, while memory-safe, will cause the map to produce seemingly random results. Higher-level and more foolproof APIs like `entry` should be preferred when possible.
In particular, the hash used to initialized the raw entry must still be consistent with the hash of the key that is ultimately stored in the entry. This is because implementations of HashMap may need to recompute hashes when resizing, at which point only the keys are available.
Raw entries give mutable access to the keys. This must not be used to modify how the key would compare or hash, as the map will not re-evaluate where the key should go, meaning the keys may become “lost” if their location does not reflect their state. For instance, if you change a key so that the map now contains keys which compare equal, search may start acting erratically, with two keys randomly masking each other. Implementations are free to assume this doesn’t happen (within the limits of memory-safety).
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1253-1255)#### pub fn raw\_entry(&self) -> RawEntryBuilder<'\_, K, V, S>
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Creates a raw immutable entry builder for the HashMap.
Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched.
This is useful for
* Hash memoization
* Using a search key that doesn’t work with the Borrow trait
* Using custom comparison logic without newtype wrappers
Unless you are in such a situation, higher-level and more foolproof APIs like `get` should be preferred.
Immutable raw entries have very limited use; you might instead want `raw_entry_mut`.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1259-1274)### impl<K, V, S> Clone for HashMap<K, V, S>where K: [Clone](../clone/trait.clone "trait std::clone::Clone"), V: [Clone](../clone/trait.clone "trait std::clone::Clone"), S: [Clone](../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1266-1268)#### fn clone(&self) -> Self
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1271-1273)#### fn clone\_from(&mut self, other: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1302-1310)### impl<K, V, S> Debug for HashMap<K, V, S>where K: [Debug](../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1307-1309)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1313-1322)### impl<K, V, S> Default for HashMap<K, V, S>where S: [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1319-1321)#### fn default() -> HashMap<K, V, S>
Creates an empty `HashMap<K, V, S>`, with the `Default` value for the hasher.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3053-3073)1.4.0 · ### impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash") + [Copy](../marker/trait.copy "trait std::marker::Copy"), V: [Copy](../marker/trait.copy "trait std::marker::Copy"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3060-3062)#### fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3065-3067)#### fn extend\_one(&mut self, (k, v): (&'a K, &'a V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3070-3072)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3031-3050)### impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
Inserts all new key-values from the iterator and replaces values with existing keys with new values returned from the iterator.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3037-3039)#### fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. [Read more](../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3042-3044)#### fn extend\_one(&mut self, (k, v): (K, V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3047-3049)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1357-1373)1.56.0 · ### impl<K, V, const N: usize> From<[(K, V); N]> for HashMap<K, V, RandomState>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1370-1372)#### fn from(arr: [(K, V); N]) -> Self
##### Examples
```
use std::collections::HashMap;
let map1 = HashMap::from([(1, 2), (3, 4)]);
let map2: HashMap<_, _> = [(1, 2), (3, 4)].into();
assert_eq!(map1, map2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3016-3026)### impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher") + [Default](../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3021-3025)#### fn from\_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> HashMap<K, V, S>
Creates a value from an iterator. [Read more](../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1325-1342)### impl<K, Q: ?Sized, V, S> Index<&Q> for HashMap<K, V, S>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash") + [Borrow](../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1339-1341)#### fn index(&self, key: &Q) -> &V
Returns a reference to the value corresponding to the supplied key.
##### Panics
Panics if the key is not present in the `HashMap`.
#### type Output = V
The returned type after indexing.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2173-2182)### impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S>
#### type Item = (&'a K, &'a V)
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2179-2181)#### fn into\_iter(self) -> Iter<'a, K, V>
Notable traits for [Iter](hash_map/struct.iter "struct std::collections::hash_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>
type Item = (&'a K, &'a V);
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2185-2194)### impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S>
#### type Item = (&'a K, &'a mut V)
The type of the elements being iterated over.
#### type IntoIter = IterMut<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2191-2193)#### fn into\_iter(self) -> IterMut<'a, K, V>
Notable traits for [IterMut](hash_map/struct.itermut "struct std::collections::hash_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Creates an iterator from a value. [Read more](../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2197-2224)### impl<K, V, S> IntoIterator for HashMap<K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2221-2223)#### fn into\_iter(self) -> IntoIter<K, V>
Notable traits for [IntoIter](hash_map/struct.intoiter "struct std::collections::hash_map::IntoIter")<K, V>
```
impl<K, V> Iterator for IntoIter<K, V>
type Item = (K, V);
```
Creates a consuming iterator, that is, one that moves each key-value pair out of the map in arbitrary order. The map cannot be used after calling this.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
// Not possible with .iter()
let vec: Vec<(&str, i32)> = map.into_iter().collect();
```
#### type Item = (K, V)
The type of the elements being iterated over.
#### type IntoIter = IntoIter<K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1277-1290)### impl<K, V, S> PartialEq<HashMap<K, V, S>> for HashMap<K, V, S>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), V: [PartialEq](../cmp/trait.partialeq "trait std::cmp::PartialEq"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1283-1289)#### fn eq(&self, other: &HashMap<K, V, S>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1293-1299)### impl<K, V, S> Eq for HashMap<K, V, S>where K: [Eq](../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../hash/trait.hash "trait std::hash::Hash"), V: [Eq](../cmp/trait.eq "trait std::cmp::Eq"), S: [BuildHasher](../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/panic.rs.html#76-82)1.36.0 · ### impl<K, V, S> UnwindSafe for HashMap<K, V, S>where K: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), V: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), S: [UnwindSafe](../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Auto Trait Implementations
--------------------------
### impl<K, V, S> RefUnwindSafe for HashMap<K, V, S>where K: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V, S> Send for HashMap<K, V, S>where K: [Send](../marker/trait.send "trait std::marker::Send"), S: [Send](../marker/trait.send "trait std::marker::Send"), V: [Send](../marker/trait.send "trait std::marker::Send"),
### impl<K, V, S> Sync for HashMap<K, V, S>where K: [Sync](../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V, S> Unpin for HashMap<K, V, S>where K: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"), S: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::TryReserveError Struct std::collections::TryReserveError
========================================
```
pub struct TryReserveError { /* private fields */ }
```
The error type for `try_reserve` methods.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#65)### impl TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#74)#### pub fn kind(&self) -> TryReserveErrorKind
🔬This is a nightly-only experimental API. (`try_reserve_kind` [#48043](https://github.com/rust-lang/rust/issues/48043))
Details about the allocation that caused the error
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)### impl Clone for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)#### fn clone(&self) -> TryReserveError
Returns a copy of the value. [Read more](../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)### impl Debug for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#131)### impl Display for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#132-135)#### fn fmt(&self, fmt: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#158)### impl Error for TryReserveError
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#109)1.0.0 · #### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)1.0.0 · #### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../error/trait.error#method.provide)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#114)### impl From<TryReserveErrorKind> for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#116)#### fn from(kind: TryReserveErrorKind) -> TryReserveError
Converts to this type from the input type.
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)### impl PartialEq<TryReserveError> for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)#### fn eq(&self, other: &TryReserveError) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)1.0.0 · #### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)### impl Eq for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)### impl StructuralEq for TryReserveError
[source](https://doc.rust-lang.org/src/alloc/collections/mod.rs.html#59)### impl StructuralPartialEq for TryReserveError
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for TryReserveError
### impl Send for TryReserveError
### impl Sync for TryReserveError
### impl Unpin for TryReserveError
### impl UnwindSafe for TryReserveError
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../error/trait.error "trait std::error::Error") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::btree_map::Values Struct std::collections::btree\_map::Values
===========================================
```
pub struct Values<'a, K, V> { /* private fields */ }
```
An iterator over the values of a `BTreeMap`.
This `struct` is created by the [`values`](../struct.btreemap#method.values) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1809)### impl<K, V> Clone for Values<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1810)#### fn clone(&self) -> Values<'\_, K, V>
Notable traits for [Values](struct.values "struct std::collections::btree_map::Values")<'a, K, V>
```
impl<'a, K, V> Iterator for Values<'a, K, V>
type Item = &'a V;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#456)1.17.0 · ### impl<K, V> Debug for Values<'\_, K, V>where V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#457)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1792)### impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1793)#### fn next\_back(&mut self) -> Option<&'a V>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1799)### impl<K, V> ExactSizeIterator for Values<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1800)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1775)### impl<'a, K, V> Iterator for Values<'a, K, V>
#### type Item = &'a V
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1778)#### fn next(&mut self) -> Option<&'a V>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1782)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1786)#### fn last(self) -> Option<&'a V>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)#### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)#### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1806)1.26.0 · ### impl<K, V> FusedIterator for Values<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Values<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Values<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for Values<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Values<'a, K, V>
### impl<'a, K, V> UnwindSafe for Values<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Module std::collections::btree_map Module std::collections::btree\_map
===================================
An ordered map based on a B-Tree.
Structs
-------
[DrainFilter](struct.drainfilter "std::collections::btree_map::DrainFilter struct")Experimental
An iterator produced by calling `drain_filter` on BTreeMap.
[OccupiedError](struct.occupiederror "std::collections::btree_map::OccupiedError struct")Experimental
The error returned by [`try_insert`](../struct.btreemap#method.try_insert) when the key already exists.
[BTreeMap](struct.btreemap "std::collections::btree_map::BTreeMap struct")
An ordered map based on a [B-Tree](https://en.wikipedia.org/wiki/B-tree).
[IntoIter](struct.intoiter "std::collections::btree_map::IntoIter struct")
An owning iterator over the entries of a `BTreeMap`.
[IntoKeys](struct.intokeys "std::collections::btree_map::IntoKeys struct")
An owning iterator over the keys of a `BTreeMap`.
[IntoValues](struct.intovalues "std::collections::btree_map::IntoValues struct")
An owning iterator over the values of a `BTreeMap`.
[Iter](struct.iter "std::collections::btree_map::Iter struct")
An iterator over the entries of a `BTreeMap`.
[IterMut](struct.itermut "std::collections::btree_map::IterMut struct")
A mutable iterator over the entries of a `BTreeMap`.
[Keys](struct.keys "std::collections::btree_map::Keys struct")
An iterator over the keys of a `BTreeMap`.
[OccupiedEntry](struct.occupiedentry "std::collections::btree_map::OccupiedEntry struct")
A view into an occupied entry in a `BTreeMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
[Range](struct.range "std::collections::btree_map::Range struct")
An iterator over a sub-range of entries in a `BTreeMap`.
[RangeMut](struct.rangemut "std::collections::btree_map::RangeMut struct")
A mutable iterator over a sub-range of entries in a `BTreeMap`.
[VacantEntry](struct.vacantentry "std::collections::btree_map::VacantEntry struct")
A view into a vacant entry in a `BTreeMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
[Values](struct.values "std::collections::btree_map::Values struct")
An iterator over the values of a `BTreeMap`.
[ValuesMut](struct.valuesmut "std::collections::btree_map::ValuesMut struct")
A mutable iterator over the values of a `BTreeMap`.
Enums
-----
[Entry](enum.entry "std::collections::btree_map::Entry enum")
A view into a single entry in a map, which may either be vacant or occupied.
rust Struct std::collections::btree_map::RangeMut Struct std::collections::btree\_map::RangeMut
=============================================
```
pub struct RangeMut<'a, K, V>where K: 'a, V: 'a,{ /* private fields */ }
```
A mutable iterator over a sub-range of entries in a `BTreeMap`.
This `struct` is created by the [`range_mut`](../struct.btreemap#method.range_mut) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#558)### impl<K, V> Debug for RangeMut<'\_, K, V>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#559)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2100)### impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2101)#### fn next\_back(&mut self) -> Option<(&'a K, &'a mut V)>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2079)### impl<'a, K, V> Iterator for RangeMut<'a, K, V>
#### type Item = (&'a K, &'a mut V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2082)#### fn next(&mut self) -> Option<(&'a K, &'a mut V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2086)#### fn last(self) -> Option<(&'a K, &'a mut V)>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2090)#### fn min(self) -> Option<(&'a K, &'a mut V)>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2094)#### fn max(self) -> Option<(&'a K, &'a mut V)>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#215)1.0.0 · #### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)1.0.0 · #### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2107)1.26.0 · ### impl<K, V> FusedIterator for RangeMut<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for RangeMut<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for RangeMut<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for RangeMut<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for RangeMut<'a, K, V>
### impl<'a, K, V> !UnwindSafe for RangeMut<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::VacantEntry Struct std::collections::btree\_map::VacantEntry
================================================
```
pub struct VacantEntry<'a, K, V, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
A view into a vacant entry in a `BTreeMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#298)### impl<'a, K, V, A> VacantEntry<'a, K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#311)1.10.0 · #### pub fn key(&self) -> &K
Gets a reference to the key that would be used when inserting a value through the VacantEntry.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
assert_eq!(map.entry("poneyland").key(), &"poneyland");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#330)1.12.0 · #### pub fn into\_key(self) -> K
Take ownership of the key.
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
if let Entry::Vacant(v) = map.entry("poneyland") {
v.into_key();
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#351)#### pub fn insert(self, value: V) -> &'a mut V
Sets the value of the entry with the `VacantEntry`’s key, and returns a mutable reference to it.
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, u32> = BTreeMap::new();
if let Entry::Vacant(o) = map.entry("poneyland") {
o.insert(37);
}
assert_eq!(map["poneyland"], 37);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#67)1.12.0 · ### impl<K, V, A> Debug for VacantEntry<'\_, K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug") + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#68)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, A> RefUnwindSafe for VacantEntry<'a, K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, A> Send for VacantEntry<'a, K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Sync for VacantEntry<'a, K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Unpin for VacantEntry<'a, K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, A = Global> !UnwindSafe for VacantEntry<'a, K, V, A>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::btree_map::Keys Struct std::collections::btree\_map::Keys
=========================================
```
pub struct Keys<'a, K, V> { /* private fields */ }
```
An iterator over the keys of a `BTreeMap`.
This `struct` is created by the [`keys`](../struct.btreemap#method.keys) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1768)### impl<K, V> Clone for Keys<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1769)#### fn clone(&self) -> Keys<'\_, K, V>
Notable traits for [Keys](struct.keys "struct std::collections::btree_map::Keys")<'a, K, V>
```
impl<'a, K, V> Iterator for Keys<'a, K, V>
type Item = &'a K;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#437)1.17.0 · ### impl<K, V> Debug for Keys<'\_, K, V>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#438)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1751)### impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1752)#### fn next\_back(&mut self) -> Option<&'a K>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1758)### impl<K, V> ExactSizeIterator for Keys<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1759)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1726)### impl<'a, K, V> Iterator for Keys<'a, K, V>
#### type Item = &'a K
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1729)#### fn next(&mut self) -> Option<&'a K>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1733)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1737)#### fn last(self) -> Option<&'a K>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1741)#### fn min(self) -> Option<&'a K>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1745)#### fn max(self) -> Option<&'a K>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)#### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)#### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1765)1.26.0 · ### impl<K, V> FusedIterator for Keys<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Keys<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Keys<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for Keys<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Keys<'a, K, V>
### impl<'a, K, V> UnwindSafe for Keys<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Enum std::collections::btree_map::Entry Enum std::collections::btree\_map::Entry
========================================
```
pub enum Entry<'a, K, V, A = Global>where K: 'a, V: 'a, A: Allocator + Clone,{
Vacant(VacantEntry<'a, K, V, A>),
Occupied(OccupiedEntry<'a, K, V, A>),
}
```
A view into a single entry in a map, which may either be vacant or occupied.
This `enum` is constructed from the [`entry`](../struct.btreemap#method.entry) method on [`BTreeMap`](../struct.btreemap "BTreeMap").
Variants
--------
### `Vacant([VacantEntry](struct.vacantentry "struct std::collections::btree_map::VacantEntry")<'a, K, V, A>)`
A vacant entry.
### `Occupied([OccupiedEntry](struct.occupiedentry "struct std::collections::btree_map::OccupiedEntry")<'a, K, V, A>)`
An occupied entry.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#147)### impl<'a, K, V, A> Entry<'a, K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#162)#### pub fn or\_insert(self, default: V) -> &'a mut V
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map["poneyland"], 12);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#185)#### pub fn or\_insert\_with<F>(self, default: F) -> &'a mut Vwhere F: [FnOnce](../../ops/trait.fnonce "trait std::ops::FnOnce")() -> V,
Ensures a value is in the entry by inserting the result of the default function if empty, and returns a mutable reference to the value in the entry.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, String> = BTreeMap::new();
let s = "hoho".to_string();
map.entry("poneyland").or_insert_with(|| s);
assert_eq!(map["poneyland"], "hoho".to_string());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#212)1.50.0 · #### pub fn or\_insert\_with\_key<F>(self, default: F) -> &'a mut Vwhere F: [FnOnce](../../ops/trait.fnonce "trait std::ops::FnOnce")([&](../../primitive.reference)K) -> V,
Ensures a value is in the entry by inserting, if empty, the result of the default function. This method allows for generating key-derived values for insertion by providing the default function a reference to the key that was moved during the `.entry(key)` method call.
The reference to the moved key is provided so that cloning or copying the key is unnecessary, unlike with `.or_insert_with(|| ... )`.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert_with_key(|key| key.chars().count());
assert_eq!(map["poneyland"], 9);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#233)1.10.0 · #### pub fn key(&self) -> &K
Returns a reference to this entry’s key.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
assert_eq!(map.entry("poneyland").key(), &"poneyland");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#261-263)1.26.0 · #### pub fn and\_modify<F>(self, f: F) -> Entry<'a, K, V, A>where F: [FnOnce](../../ops/trait.fnonce "trait std::ops::FnOnce")([&mut](../../primitive.reference) V),
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland")
.and_modify(|e| { *e += 1 })
.or_insert(42);
assert_eq!(map["poneyland"], 42);
map.entry("poneyland")
.and_modify(|e| { *e += 1 })
.or_insert(42);
assert_eq!(map["poneyland"], 43);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#275)### impl<'a, K, V, A> Entry<'a, K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), V: [Default](../../default/trait.default "trait std::default::Default"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#290)1.28.0 · #### pub fn or\_default(self) -> &'a mut V
Ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, Option<usize>> = BTreeMap::new();
map.entry("poneyland").or_default();
assert_eq!(map["poneyland"], None);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#36)1.12.0 · ### impl<K, V, A> Debug for Entry<'\_, K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug") + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#37)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, A> RefUnwindSafe for Entry<'a, K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, A> Send for Entry<'a, K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Sync for Entry<'a, K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Unpin for Entry<'a, K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, A = Global> !UnwindSafe for Entry<'a, K, V, A>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::btree_map::IterMut Struct std::collections::btree\_map::IterMut
============================================
```
pub struct IterMut<'a, K, V>where K: 'a, V: 'a,{ /* private fields */ }
```
A mutable iterator over the entries of a `BTreeMap`.
This `struct` is created by the [`iter_mut`](../struct.btreemap#method.iter_mut) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#382)1.17.0 · ### impl<K, V> Debug for IterMut<'\_, K, V>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#383)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1584)### impl<'a, K, V> DoubleEndedIterator for IterMut<'a, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1585)#### fn next\_back(&mut self) -> Option<(&'a K, &'a mut V)>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1596)### impl<K, V> ExactSizeIterator for IterMut<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1597)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1554)### impl<'a, K, V> Iterator for IterMut<'a, K, V>
#### type Item = (&'a K, &'a mut V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1557)#### fn next(&mut self) -> Option<(&'a K, &'a mut V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1566)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1570)#### fn last(self) -> Option<(&'a K, &'a mut V)>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1574)#### fn min(self) -> Option<(&'a K, &'a mut V)>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1578)#### fn max(self) -> Option<(&'a K, &'a mut V)>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)#### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)#### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1603)1.26.0 · ### impl<K, V> FusedIterator for IterMut<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for IterMut<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for IterMut<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for IterMut<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for IterMut<'a, K, V>
### impl<'a, K, V> !UnwindSafe for IterMut<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::IntoIter Struct std::collections::btree\_map::IntoIter
=============================================
```
pub struct IntoIter<K, V, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An owning iterator over the entries of a `BTreeMap`.
This `struct` is created by the [`into_iter`](../../iter/trait.intoiterator#tymethod.into_iter) method on [`BTreeMap`](../struct.btreemap "BTreeMap") (provided by the [`IntoIterator`](../../iter/trait.intoiterator) trait). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#418)1.17.0 · ### impl<K, V, A> Debug for IntoIter<K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#419)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1708)### impl<K, V, A> DoubleEndedIterator for IntoIter<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1709)#### fn next\_back(&mut self) -> Option<(K, V)>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1639)1.7.0 · ### impl<K, V, A> Drop for IntoIter<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1640)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1716)### impl<K, V, A> ExactSizeIterator for IntoIter<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1717)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1694)### impl<K, V, A> Iterator for IntoIter<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = (K, V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1697)#### fn next(&mut self) -> Option<(K, V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1702)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)#### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)#### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1723)1.26.0 · ### impl<K, V, A> FusedIterator for IntoIter<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<K, V, A> RefUnwindSafe for IntoIter<K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V, A> Send for IntoIter<K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V, A> Sync for IntoIter<K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Unpin for IntoIter<K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<K, V, A> UnwindSafe for IntoIter<K, V, A>where A: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::BTreeMap Struct std::collections::btree\_map::BTreeMap
=============================================
```
pub struct BTreeMap<K, V, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An ordered map based on a [B-Tree](https://en.wikipedia.org/wiki/B-tree).
B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum amount of comparisons necessary to find an element (log2n). However, in practice the way this is done is *very* inefficient for modern computer architectures. In particular, every element is stored in its own individually heap-allocated node. This means that every single insertion triggers a heap-allocation, and every single comparison should be a cache-miss. Since these are both notably expensive things to do in practice, we are forced to at very least reconsider the BST strategy.
A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing this, we reduce the number of allocations by a factor of B, and improve cache efficiency in searches. However, this does mean that searches will have to do *more* comparisons on average. The precise number of comparisons depends on the node search strategy used. For optimal cache efficiency, one could search the nodes linearly. For optimal comparisons, one could search the node using binary search. As a compromise, one could also perform a linear search that initially only checks every ith element for some choice of i.
Currently, our implementation simply performs naive linear search. This provides excellent performance on *small* nodes of elements which are cheap to compare. However in the future we would like to further explore choosing the optimal search strategy based on the choice of B, and possibly other factors. Using linear search, searching for a random element is expected to take B \* log(n) comparisons, which is generally worse than a BST. In practice, however, performance is excellent.
It is a logic error for a key to be modified in such a way that the key’s ordering relative to any other key, as determined by the [`Ord`](../../cmp/trait.ord "Ord") trait, changes while it is in the map. This is normally only possible through [`Cell`](../../cell/struct.cell), [`RefCell`](../../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `BTreeMap` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
Iterators obtained from functions such as [`BTreeMap::iter`](../struct.btreemap#method.iter "BTreeMap::iter"), [`BTreeMap::values`](../struct.btreemap#method.values "BTreeMap::values"), or [`BTreeMap::keys`](../struct.btreemap#method.keys "BTreeMap::keys") produce their items in order by key, and take worst-case logarithmic and amortized constant time per item returned.
Examples
--------
```
use std::collections::BTreeMap;
// type inference lets us omit an explicit type signature (which
// would be `BTreeMap<&str, &str>` in this example).
let mut movie_reviews = BTreeMap::new();
// review some movies.
movie_reviews.insert("Office Space", "Deals with real issues in the workplace.");
movie_reviews.insert("Pulp Fiction", "Masterpiece.");
movie_reviews.insert("The Godfather", "Very enjoyable.");
movie_reviews.insert("The Blues Brothers", "Eye lyked it a lot.");
// check for a specific one.
if !movie_reviews.contains_key("Les Misérables") {
println!("We've got {} reviews, but Les Misérables ain't one.",
movie_reviews.len());
}
// oops, this review has a lot of spelling mistakes, let's delete it.
movie_reviews.remove("The Blues Brothers");
// look up the values associated with some keys.
let to_find = ["Up!", "Office Space"];
for movie in &to_find {
match movie_reviews.get(movie) {
Some(review) => println!("{movie}: {review}"),
None => println!("{movie} is unreviewed.")
}
}
// Look up the value for a key (will panic if the key is not found).
println!("Movie review: {}", movie_reviews["Office Space"]);
// iterate over everything.
for (movie, review) in &movie_reviews {
println!("{movie}: \"{review}\"");
}
```
A `BTreeMap` with a known list of items can be initialized from an array:
```
use std::collections::BTreeMap;
let solar_distance = BTreeMap::from([
("Mercury", 0.4),
("Venus", 0.7),
("Earth", 1.0),
("Mars", 1.5),
]);
```
`BTreeMap` implements an [`Entry API`](../struct.btreemap#method.entry), which allows for complex methods of getting, setting, updating and removing keys and their values:
```
use std::collections::BTreeMap;
// type inference lets us omit an explicit type signature (which
// would be `BTreeMap<&str, u8>` in this example).
let mut player_stats = BTreeMap::new();
fn random_stat_buff() -> u8 {
// could actually return some random value here - let's just return
// some fixed value for now
42
}
// insert a key only if it doesn't already exist
player_stats.entry("health").or_insert(100);
// insert a key using a function that provides a new value only if it
// doesn't already exist
player_stats.entry("defence").or_insert_with(random_stat_buff);
// update a key, guarding against the key possibly not being set
let stat = player_stats.entry("attack").or_insert(100);
*stat += random_stat_buff();
// modify an entry before an insert with in-place mutation
player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#565)### impl<K, V> BTreeMap<K, V, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#585)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn new() -> BTreeMap<K, V, Global>
Makes a new, empty `BTreeMap`.
Does not allocate anything on its own.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
// entries can now be inserted into the empty map
map.insert(1, "a");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#590)### impl<K, V, A> BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#606)#### pub fn clear(&mut self)
Clears the map, removing all elements.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "a");
a.clear();
assert!(a.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#634)#### pub fn new\_in(alloc: A) -> BTreeMap<K, V, A>
🔬This is a nightly-only experimental API. (`btreemap_alloc` [#32838](https://github.com/rust-lang/rust/issues/32838))
Makes a new empty BTreeMap with a reasonable choice for B.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
use std::alloc::Global;
let mut map = BTreeMap::new_in(Global);
// entries can now be inserted into the empty map
map.insert(1, "a");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#639)### impl<K, V, A> BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#658-661)#### pub fn get<Q>(&self, key: &Q) -> Option<&V>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#686-689)1.40.0 · #### pub fn get\_key\_value<Q>(&self, k: &Q) -> Option<(&K, &V)>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#716-718)#### pub fn first\_key\_value(&self) -> Option<(&K, &V)>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the first key-value pair in the map. The key in this pair is the minimum key in the map.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
assert_eq!(map.first_key_value(), None);
map.insert(1, "b");
map.insert(2, "a");
assert_eq!(map.first_key_value(), Some((&1, &"b")));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#745-747)#### pub fn first\_entry(&mut self) -> Option<OccupiedEntry<'\_, K, V, A>>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the first entry in the map for in-place manipulation. The key of this entry is the minimum key in the map.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
if let Some(mut entry) = map.first_entry() {
if *entry.key() > 0 {
entry.insert("first");
}
}
assert_eq!(*map.get(&1).unwrap(), "first");
assert_eq!(*map.get(&2).unwrap(), "b");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#780-782)#### pub fn pop\_first(&mut self) -> Option<(K, V)>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes and returns the first element in the map. The key of this element is the minimum key that was in the map.
##### Examples
Draining elements in ascending order, while keeping a usable map each iteration.
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
while let Some((key, _val)) = map.pop_first() {
assert!(map.iter().all(|(k, _v)| *k > key));
}
assert!(map.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#804-806)#### pub fn last\_key\_value(&self) -> Option<(&K, &V)>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the last key-value pair in the map. The key in this pair is the maximum key in the map.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "b");
map.insert(2, "a");
assert_eq!(map.last_key_value(), Some((&2, &"a")));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#833-835)#### pub fn last\_entry(&mut self) -> Option<OccupiedEntry<'\_, K, V, A>>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns the last entry in the map for in-place manipulation. The key of this entry is the maximum key in the map.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
if let Some(mut entry) = map.last_entry() {
if *entry.key() > 0 {
entry.insert("last");
}
}
assert_eq!(*map.get(&1).unwrap(), "a");
assert_eq!(*map.get(&2).unwrap(), "last");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#868-870)#### pub fn pop\_last(&mut self) -> Option<(K, V)>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes and returns the last element in the map. The key of this element is the maximum key that was in the map.
##### Examples
Draining elements in descending order, while keeping a usable map each iteration.
```
#![feature(map_first_last)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
map.insert(2, "b");
while let Some((key, _val)) = map.pop_last() {
assert!(map.iter().all(|(k, _v)| *k < key));
}
assert!(map.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#893-896)#### pub fn contains\_key<Q>(&self, key: &Q) -> boolwhere K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Returns `true` if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#922-925)#### pub fn get\_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
if let Some(x) = map.get_mut(&1) {
*x = "b";
}
assert_eq!(map[&1], "b");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#961-963)#### pub fn insert(&mut self, key: K, value: V) -> Option<V>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Inserts a key-value pair into the map.
If 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 value is returned. The key is not updated, though; this matters for types that can be `==` without being identical. See the [module-level documentation](index#insert-and-complex-keys) for more.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);
map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#998-1000)#### pub fn try\_insert( &mut self, key: K, value: V) -> Result<&mut V, OccupiedError<'\_, K, V, A>>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
Tries to insert a key-value pair into the map, and returns a mutable reference to the value in the entry.
If the map already had this key present, nothing is updated, and an error containing the occupied entry and the value is returned.
##### Examples
Basic usage:
```
#![feature(map_try_insert)]
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
assert_eq!(map.try_insert(37, "a").unwrap(), &"a");
let err = map.try_insert(37, "b").unwrap_err();
assert_eq!(err.entry.key(), &37);
assert_eq!(err.entry.get(), &"a");
assert_eq!(err.value, "b");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1027-1030)#### pub fn remove<Q>(&mut self, key: &Q) -> Option<V>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1054-1057)1.45.0 · #### pub fn remove\_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form *must* match the ordering on the key type.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.remove_entry(&1), Some((1, "a")));
assert_eq!(map.remove_entry(&1), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1092-1095)1.53.0 · #### pub fn retain<F>(&mut self, f: F)where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all pairs `(k, v)` for which `f(&k, &mut v)` returns `false`. The elements are visited in ascending key order.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();
// Keep only the elements with even-numbered keys.
map.retain(|&k, _| k % 2 == 0);
assert!(map.into_iter().eq(vec![(0, 0), (2, 20), (4, 40), (6, 60)]));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1129-1132)1.11.0 · #### pub fn append(&mut self, other: &mut BTreeMap<K, V, A>)where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Moves all elements from `other` into `self`, leaving `other` empty.
##### Examples
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "a");
a.insert(2, "b");
a.insert(3, "c");
let mut b = BTreeMap::new();
b.insert(3, "d");
b.insert(4, "e");
b.insert(5, "f");
a.append(&mut b);
assert_eq!(a.len(), 5);
assert_eq!(b.len(), 0);
assert_eq!(a[&1], "a");
assert_eq!(a[&2], "b");
assert_eq!(a[&3], "d");
assert_eq!(a[&4], "e");
assert_eq!(a[&5], "f");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1186-1190)1.17.0 · #### pub fn range<T, R>(&self, range: R) -> Range<'\_, K, V>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"), K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<T> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), R: [RangeBounds](../../ops/trait.rangebounds "trait std::ops::RangeBounds")<T>,
Notable traits for [Range](struct.range "struct std::collections::btree_map::Range")<'a, K, V>
```
impl<'a, K, V> Iterator for Range<'a, K, V>
type Item = (&'a K, &'a V);
```
Constructs a double-ended iterator over a sub-range of elements in the map. The simplest way is to use the range syntax `min..max`, thus `range(min..max)` will yield elements from min (inclusive) to max (exclusive). The range may also be entered as `(Bound<T>, Bound<T>)`, so for example `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive range from 4 to 10.
##### Panics
Panics if range `start > end`. Panics if range `start == end` and both bounds are `Excluded`.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
use std::ops::Bound::Included;
let mut map = BTreeMap::new();
map.insert(3, "a");
map.insert(5, "b");
map.insert(8, "c");
for (&key, &value) in map.range((Included(&4), Included(&8))) {
println!("{key}: {value}");
}
assert_eq!(Some((&5, &"b")), map.range(4..).next());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1228-1232)1.17.0 · #### pub fn range\_mut<T, R>(&mut self, range: R) -> RangeMut<'\_, K, V>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"), K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<T> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), R: [RangeBounds](../../ops/trait.rangebounds "trait std::ops::RangeBounds")<T>,
Notable traits for [RangeMut](struct.rangemut "struct std::collections::btree_map::RangeMut")<'a, K, V>
```
impl<'a, K, V> Iterator for RangeMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Constructs a mutable double-ended iterator over a sub-range of elements in the map. The simplest way is to use the range syntax `min..max`, thus `range(min..max)` will yield elements from min (inclusive) to max (exclusive). The range may also be entered as `(Bound<T>, Bound<T>)`, so for example `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive range from 4 to 10.
##### Panics
Panics if range `start > end`. Panics if range `start == end` and both bounds are `Excluded`.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, i32> =
[("Alice", 0), ("Bob", 0), ("Carol", 0), ("Cheryl", 0)].into();
for (_, balance) in map.range_mut("B".."Cheryl") {
*balance += 100;
}
for (name, balance) in &map {
println!("{name} => {balance}");
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1262-1264)#### pub fn entry(&mut self, key: K) -> Entry<'\_, K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Gets the given key’s corresponding entry in the map for in-place manipulation.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut count: BTreeMap<&str, usize> = BTreeMap::new();
// count the number of occurrences of letters in the vec
for x in ["a", "b", "a", "c", "a", "b"] {
count.entry(x).and_modify(|curr| *curr += 1).or_insert(1);
}
assert_eq!(count["a"], 3);
assert_eq!(count["b"], 2);
assert_eq!(count["c"], 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1323-1326)1.11.0 · #### pub fn split\_off<Q>(&mut self, key: &Q) -> BTreeMap<K, V, A>where Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"), K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Splits the collection into two at the given key. Returns everything after the given key, including the key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "a");
a.insert(2, "b");
a.insert(3, "c");
a.insert(17, "d");
a.insert(41, "e");
let b = a.split_off(&3);
assert_eq!(a.len(), 2);
assert_eq!(b.len(), 3);
assert_eq!(a[&1], "a");
assert_eq!(a[&2], "b");
assert_eq!(b[&3], "c");
assert_eq!(b[&17], "d");
assert_eq!(b[&41], "e");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1381-1384)#### pub fn drain\_filter<F>(&mut self, pred: F) -> DrainFilter<'\_, K, V, F, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
Notable traits for [DrainFilter](struct.drainfilter "struct std::collections::btree_map::DrainFilter")<'\_, K, V, F, A>
```
impl<K, V, F, A> Iterator for DrainFilter<'_, K, V, F, A>where
A: Allocator + Clone,
F: FnMut(&K, &mut V) -> bool,
type Item = (K, V);
```
🔬This is a nightly-only experimental API. (`btree_drain_filter` [#70530](https://github.com/rust-lang/rust/issues/70530))
Creates an iterator that visits all elements (key-value pairs) in ascending key order and uses a closure to determine if an element should be removed. If the closure returns `true`, the element is removed from the map and yielded. If the closure returns `false`, or panics, the element remains in the map and will not be yielded.
The iterator also lets you mutate the value of each element in the closure, regardless of whether you choose to keep or remove it.
If the iterator is only partially consumed or not consumed at all, each of the remaining elements is still subjected to the closure, which may change its value and, by returning `true`, have the element removed and dropped.
It is unspecified how many more elements will be subjected to the closure if a panic occurs in the closure, or a panic occurs while dropping an element, or if the `DrainFilter` value is leaked.
##### Examples
Splitting a map into even and odd keys, reusing the original map:
```
#![feature(btree_drain_filter)]
use std::collections::BTreeMap;
let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
let evens: BTreeMap<_, _> = map.drain_filter(|k, _v| k % 2 == 0).collect();
let odds = map;
assert_eq!(evens.keys().copied().collect::<Vec<_>>(), [0, 2, 4, 6]);
assert_eq!(odds.keys().copied().collect::<Vec<_>>(), [1, 3, 5, 7]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1435)1.54.0 · #### pub fn into\_keys(self) -> IntoKeys<K, V, A>
Notable traits for [IntoKeys](struct.intokeys "struct std::collections::btree_map::IntoKeys")<K, V, A>
```
impl<K, V, A> Iterator for IntoKeys<K, V, A>where
A: Allocator + Clone,
type Item = K;
```
Creates a consuming iterator visiting all the keys, in sorted order. The map cannot be used after calling this. The iterator element type is `K`.
##### Examples
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(2, "b");
a.insert(1, "a");
let keys: Vec<i32> = a.into_keys().collect();
assert_eq!(keys, [1, 2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1457)1.54.0 · #### pub fn into\_values(self) -> IntoValues<K, V, A>
Notable traits for [IntoValues](struct.intovalues "struct std::collections::btree_map::IntoValues")<K, V, A>
```
impl<K, V, A> Iterator for IntoValues<K, V, A>where
A: Allocator + Clone,
type Item = V;
```
Creates a consuming iterator visiting all the values, in order by key. The map cannot be used after calling this. The iterator element type is `V`.
##### Examples
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "hello");
a.insert(2, "goodbye");
let values: Vec<&str> = a.into_values().collect();
assert_eq!(values, ["hello", "goodbye"]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2245)### impl<K, V, A> BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2268)#### pub fn iter(&self) -> Iter<'\_, K, V>
Notable traits for [Iter](struct.iter "struct std::collections::btree_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>where
K: 'a,
V: 'a,
type Item = (&'a K, &'a V);
```
Gets an iterator over the entries of the map, sorted by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(3, "c");
map.insert(2, "b");
map.insert(1, "a");
for (key, value) in map.iter() {
println!("{key}: {value}");
}
let (first_key, first_value) = map.iter().next().unwrap();
assert_eq!((*first_key, *first_value), (1, "a"));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2301)#### pub fn iter\_mut(&mut self) -> IterMut<'\_, K, V>
Notable traits for [IterMut](struct.itermut "struct std::collections::btree_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Gets a mutable iterator over the entries of the map, sorted by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut map = BTreeMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
// add 10 to the value if the key isn't "a"
for (key, value) in map.iter_mut() {
if key != &"a" {
*value += 10;
}
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2328)#### pub fn keys(&self) -> Keys<'\_, K, V>
Notable traits for [Keys](struct.keys "struct std::collections::btree_map::Keys")<'a, K, V>
```
impl<'a, K, V> Iterator for Keys<'a, K, V>
type Item = &'a K;
```
Gets an iterator over the keys of the map, in sorted order.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(2, "b");
a.insert(1, "a");
let keys: Vec<_> = a.keys().cloned().collect();
assert_eq!(keys, [1, 2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2349)#### pub fn values(&self) -> Values<'\_, K, V>
Notable traits for [Values](struct.values "struct std::collections::btree_map::Values")<'a, K, V>
```
impl<'a, K, V> Iterator for Values<'a, K, V>
type Item = &'a V;
```
Gets an iterator over the values of the map, in order by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, "hello");
a.insert(2, "goodbye");
let values: Vec<&str> = a.values().cloned().collect();
assert_eq!(values, ["hello", "goodbye"]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2375)1.10.0 · #### pub fn values\_mut(&mut self) -> ValuesMut<'\_, K, V>
Notable traits for [ValuesMut](struct.valuesmut "struct std::collections::btree_map::ValuesMut")<'a, K, V>
```
impl<'a, K, V> Iterator for ValuesMut<'a, K, V>
type Item = &'a mut V;
```
Gets a mutable iterator over the values of the map, in order by key.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
a.insert(1, String::from("hello"));
a.insert(2, String::from("goodbye"));
for value in a.values_mut() {
value.push_str("!");
}
let values: Vec<String> = a.values().cloned().collect();
assert_eq!(values, [String::from("hello!"),
String::from("goodbye!")]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2396)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn len(&self) -> usize
Returns the number of elements in the map.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2417)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn is\_empty(&self) -> bool
Returns `true` if the map contains no elements.
##### Examples
Basic usage:
```
use std::collections::BTreeMap;
let mut a = BTreeMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#206)### impl<K, V, A> Clone for BTreeMap<K, V, A>where K: [Clone](../../clone/trait.clone "trait std::clone::Clone"), V: [Clone](../../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#207)#### fn clone(&self) -> BTreeMap<K, V, A>
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2198)### impl<K, V, A> Debug for BTreeMap<K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2199)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2164)### impl<K, V> Default for BTreeMap<K, V, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2166)#### fn default() -> BTreeMap<K, V, Global>
Creates an empty `BTreeMap`.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#186)1.7.0 · ### impl<K, V, A> Drop for BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#187)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2140-2141)1.2.0 · ### impl<'a, K, V, A> Extend<(&'a K, &'a V)> for BTreeMap<K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + [Copy](../../marker/trait.copy "trait std::marker::Copy"), V: [Copy](../../marker/trait.copy "trait std::marker::Copy"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2143)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = ([&'a](../../primitive.reference) K, [&'a](../../primitive.reference) V)>,
Extends a collection with the contents of an iterator. [Read more](../../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2148)#### fn extend\_one(&mut self, (&'a K, &'a V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2125)### impl<K, V, A> Extend<(K, V)> for BTreeMap<K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2127)#### fn extend<T>(&mut self, iter: T)where T: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [(K, V)](../../primitive.tuple)>,
Extends a collection with the contents of an iterator. [Read more](../../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2134)#### fn extend\_one(&mut self, (K, V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2224)1.56.0 · ### impl<K, V, const N: usize> From<[(K, V); N]> for BTreeMap<K, V, Global>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2234)#### fn from(arr: [(K, V); N]) -> BTreeMap<K, V, Global>
Converts a `[(K, V); N]` into a `BTreeMap<(K, V)>`.
```
use std::collections::BTreeMap;
let map1 = BTreeMap::from([(1, 2), (3, 4)]);
let map2: BTreeMap<_, _> = [(1, 2), (3, 4)].into();
assert_eq!(map1, map2);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2110)### impl<K, V> FromIterator<(K, V)> for BTreeMap<K, V, Global>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2111)#### fn from\_iter<T>(iter: T) -> BTreeMap<K, V, Global>where T: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [(K, V)](../../primitive.tuple)>,
Creates a value from an iterator. [Read more](../../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2154)### impl<K, V, A> Hash for BTreeMap<K, V, A>where K: [Hash](../../hash/trait.hash "trait std::hash::Hash"), V: [Hash](../../hash/trait.hash "trait std::hash::Hash"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2155)#### fn hash<H>(&self, state: &mut H)where H: [Hasher](../../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../../hash/trait.hasher "Hasher"). [Read more](../../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../../hash/trait.hasher "Hasher"). [Read more](../../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2205)### impl<K, Q, V, A> Index<&Q> for BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2218)#### fn index(&self, key: &Q) -> &V
Returns a reference to the value corresponding to the supplied key.
##### Panics
Panics if the key is not present in the `BTreeMap`.
#### type Output = V
The returned type after indexing.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1475)### impl<'a, K, V, A> IntoIterator for &'a BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = (&'a K, &'a V)
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1479)#### fn into\_iter(self) -> Iter<'a, K, V>
Notable traits for [Iter](struct.iter "struct std::collections::btree_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>where
K: 'a,
V: 'a,
type Item = (&'a K, &'a V);
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1544)### impl<'a, K, V, A> IntoIterator for &'a mut BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = (&'a K, &'a mut V)
The type of the elements being iterated over.
#### type IntoIter = IterMut<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1548)#### fn into\_iter(self) -> IterMut<'a, K, V>
Notable traits for [IterMut](struct.itermut "struct std::collections::btree_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1614)### impl<K, V, A> IntoIterator for BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = (K, V)
The type of the elements being iterated over.
#### type IntoIter = IntoIter<K, V, A>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1618)#### fn into\_iter(self) -> IntoIter<K, V, A>
Notable traits for [IntoIter](struct.intoiter "struct std::collections::btree_map::IntoIter")<K, V, A>
```
impl<K, V, A> Iterator for IntoIter<K, V, A>where
A: Allocator + Clone,
type Item = (K, V);
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2190)### impl<K, V, A> Ord for BTreeMap<K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), V: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2192)#### fn cmp(&self, other: &BTreeMap<K, V, A>) -> Ordering
This method returns an [`Ordering`](../../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2172)### impl<K, V, A> PartialEq<BTreeMap<K, V, A>> for BTreeMap<K, V, A>where K: [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<K>, V: [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<V>, A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2173)#### fn eq(&self, other: &BTreeMap<K, V, A>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2182)### impl<K, V, A> PartialOrd<BTreeMap<K, V, A>> for BTreeMap<K, V, A>where K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>, V: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<V>, A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2184)#### fn partial\_cmp(&self, other: &BTreeMap<K, V, A>) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2179)### impl<K, V, A> Eq for BTreeMap<K, V, A>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq"), V: [Eq](../../cmp/trait.eq "trait std::cmp::Eq"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#197)1.64.0 · ### impl<K, V, A> UnwindSafe for BTreeMap<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone") + [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Auto Trait Implementations
--------------------------
### impl<K, V, A> RefUnwindSafe for BTreeMap<K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V, A> Send for BTreeMap<K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V, A> Sync for BTreeMap<K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Unpin for BTreeMap<K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::DrainFilter Struct std::collections::btree\_map::DrainFilter
================================================
```
pub struct DrainFilter<'a, K, V, F, A = Global>where A: Allocator + Clone, F: 'a + FnMut(&K, &mut V) -> bool,{ /* private fields */ }
```
🔬This is a nightly-only experimental API. (`btree_drain_filter` [#70530](https://github.com/rust-lang/rust/issues/70530))
An iterator produced by calling `drain_filter` on BTreeMap.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1856)### impl<K, V, F> Debug for DrainFilter<'\_, K, V, F, Global>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1862)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1846)### impl<K, V, F, A> Drop for DrainFilter<'\_, K, V, F, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1850)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1868)### impl<K, V, F, A> Iterator for DrainFilter<'\_, K, V, F, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
#### type Item = (K, V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1874)#### fn next(&mut self) -> Option<(K, V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1878)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1928)### impl<K, V, F> FusedIterator for DrainFilter<'\_, K, V, F, Global>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
Auto Trait Implementations
--------------------------
### impl<'a, K, V, F, A> RefUnwindSafe for DrainFilter<'a, K, V, F, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), F: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, F, A> Send for DrainFilter<'a, K, V, F, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), F: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, F, A> Sync for DrainFilter<'a, K, V, F, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), F: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, F, A> Unpin for DrainFilter<'a, K, V, F, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), F: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, F, A = Global> !UnwindSafe for DrainFilter<'a, K, V, F, A>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::IntoKeys Struct std::collections::btree\_map::IntoKeys
=============================================
```
pub struct IntoKeys<K, V, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An owning iterator over the keys of a `BTreeMap`.
This `struct` is created by the [`into_keys`](../struct.btreemap#method.into_keys) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#494)### impl<K, V, A> Debug for IntoKeys<K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#495)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2011)### impl<K, V, A> DoubleEndedIterator for IntoKeys<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2012)#### fn next\_back(&mut self) -> Option<K>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2018)### impl<K, V, A> ExactSizeIterator for IntoKeys<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2019)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1986)### impl<K, V, A> Iterator for IntoKeys<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = K
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1989)#### fn next(&mut self) -> Option<K>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1993)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1997)#### fn last(self) -> Option<K>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2001)#### fn min(self) -> Option<K>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2005)#### fn max(self) -> Option<K>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)1.0.0 · #### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)1.0.0 · #### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2025)### impl<K, V, A> FusedIterator for IntoKeys<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<K, V, A> RefUnwindSafe for IntoKeys<K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V, A> Send for IntoKeys<K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V, A> Sync for IntoKeys<K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Unpin for IntoKeys<K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<K, V, A> UnwindSafe for IntoKeys<K, V, A>where A: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::OccupiedError Struct std::collections::btree\_map::OccupiedError
==================================================
```
pub struct OccupiedError<'a, K, V, A = Global>where K: 'a, V: 'a, A: Allocator + Clone,{
pub entry: OccupiedEntry<'a, K, V, A>,
pub value: V,
}
```
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
The error returned by [`try_insert`](../struct.btreemap#method.try_insert) when the key already exists.
Contains the occupied entry, and the value that was not inserted.
Fields
------
`entry: [OccupiedEntry](struct.occupiedentry "struct std::collections::btree_map::OccupiedEntry")<'a, K, V, A>`
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
The entry in the map that was already occupied.
`value: V`
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
The value which was not inserted, because the entry was already occupied.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#111)### impl<K, V, A> Debug for OccupiedError<'\_, K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug") + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#112)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#122-123)### impl<'a, K, V, A> Display for OccupiedError<'a, K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug") + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#125)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#138-139)### impl<'a, K, V> Error for OccupiedError<'a, K, V, Global>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug") + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#142)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)1.0.0 · #### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../error/trait.error#method.provide)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, A> RefUnwindSafe for OccupiedError<'a, K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, A> Send for OccupiedError<'a, K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Sync for OccupiedError<'a, K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Unpin for OccupiedError<'a, K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, A = Global> !UnwindSafe for OccupiedError<'a, K, V, A>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../error/trait.error "trait std::error::Error") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::btree_map::OccupiedEntry Struct std::collections::btree\_map::OccupiedEntry
==================================================
```
pub struct OccupiedEntry<'a, K, V, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
A view into an occupied entry in a `BTreeMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#387)### impl<'a, K, V, A> OccupiedEntry<'a, K, V, A>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#401)1.10.0 · #### pub fn key(&self) -> &K
Gets a reference to the key in the entry.
##### Examples
```
use std::collections::BTreeMap;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map.entry("poneyland").key(), &"poneyland");
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#425)1.12.0 · #### pub fn remove\_entry(self) -> (K, V)
Take ownership of the key and value from the map.
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(o) = map.entry("poneyland") {
// We delete the entry from the map.
o.remove_entry();
}
// If now try to get the value, it will panic:
// println!("{}", map["poneyland"]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#446)#### pub fn get(&self) -> &V
Gets a reference to the value in the entry.
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(o) = map.entry("poneyland") {
assert_eq!(o.get(), &12);
}
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#477)#### pub fn get\_mut(&mut self) -> &mut V
Gets a mutable reference to the value in the entry.
If you need a reference to the `OccupiedEntry` that may outlive the destruction of the `Entry` value, see [`into_mut`](struct.occupiedentry#method.into_mut).
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map["poneyland"], 12);
if let Entry::Occupied(mut o) = map.entry("poneyland") {
*o.get_mut() += 10;
assert_eq!(*o.get(), 22);
// We can use the same Entry multiple times.
*o.get_mut() += 2;
}
assert_eq!(map["poneyland"], 24);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#504)#### pub fn into\_mut(self) -> &'a mut V
Converts the entry into a mutable reference to its value.
If you need multiple references to the `OccupiedEntry`, see [`get_mut`](struct.occupiedentry#method.get_mut).
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map["poneyland"], 12);
if let Entry::Occupied(o) = map.entry("poneyland") {
*o.into_mut() += 10;
}
assert_eq!(map["poneyland"], 22);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#526)#### pub fn insert(&mut self, value: V) -> V
Sets the value of the entry with the `OccupiedEntry`’s key, and returns the entry’s old value.
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(mut o) = map.entry("poneyland") {
assert_eq!(o.insert(15), 12);
}
assert_eq!(map["poneyland"], 15);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#548)#### pub fn remove(self) -> V
Takes the value of the entry out of the map, and returns it.
##### Examples
```
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
let mut map: BTreeMap<&str, usize> = BTreeMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(o) = map.entry("poneyland") {
assert_eq!(o.remove(), 12);
}
// If we try to get "poneyland"'s value, it'll panic:
// println!("{}", map["poneyland"]);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#93)1.12.0 · ### impl<K, V, A> Debug for OccupiedEntry<'\_, K, V, A>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug") + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map/entry.rs.html#94)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, A> RefUnwindSafe for OccupiedEntry<'a, K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, A> Send for OccupiedEntry<'a, K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, A> Sync for OccupiedEntry<'a, K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, A> Unpin for OccupiedEntry<'a, K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, A = Global> !UnwindSafe for OccupiedEntry<'a, K, V, A>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::btree_map::Range Struct std::collections::btree\_map::Range
==========================================
```
pub struct Range<'a, K, V>where K: 'a, V: 'a,{ /* private fields */ }
```
An iterator over a sub-range of entries in a `BTreeMap`.
This `struct` is created by the [`range`](../struct.btreemap#method.range) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2072)### impl<K, V> Clone for Range<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2073)#### fn clone(&self) -> Range<'\_, K, V>
Notable traits for [Range](struct.range "struct std::collections::btree_map::Range")<'a, K, V>
```
impl<'a, K, V> Iterator for Range<'a, K, V>
type Item = (&'a K, &'a V);
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#536)### impl<K, V> Debug for Range<'\_, K, V>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#537)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2062)### impl<'a, K, V> DoubleEndedIterator for Range<'a, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2063)#### fn next\_back(&mut self) -> Option<(&'a K, &'a V)>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1931)### impl<'a, K, V> Iterator for Range<'a, K, V>
#### type Item = (&'a K, &'a V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1934)#### fn next(&mut self) -> Option<(&'a K, &'a V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1938)#### fn last(self) -> Option<(&'a K, &'a V)>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1942)#### fn min(self) -> Option<(&'a K, &'a V)>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1946)#### fn max(self) -> Option<(&'a K, &'a V)>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#215)1.0.0 · #### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)1.0.0 · #### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)1.0.0 · #### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2069)1.26.0 · ### impl<K, V> FusedIterator for Range<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Range<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Range<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for Range<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Range<'a, K, V>
### impl<'a, K, V> UnwindSafe for Range<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::IntoValues Struct std::collections::btree\_map::IntoValues
===============================================
```
pub struct IntoValues<K, V, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An owning iterator over the values of a `BTreeMap`.
This `struct` is created by the [`into_values`](../struct.btreemap#method.into_values) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#517)### impl<K, V, A> Debug for IntoValues<K, V, A>where V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#518)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2045)### impl<K, V, A> DoubleEndedIterator for IntoValues<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2046)#### fn next\_back(&mut self) -> Option<V>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2052)### impl<K, V, A> ExactSizeIterator for IntoValues<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2053)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2028)### impl<K, V, A> Iterator for IntoValues<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = V
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2031)#### fn next(&mut self) -> Option<V>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2035)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2039)#### fn last(self) -> Option<V>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)1.0.0 · #### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)1.0.0 · #### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#2059)### impl<K, V, A> FusedIterator for IntoValues<K, V, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<K, V, A> RefUnwindSafe for IntoValues<K, V, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V, A> Send for IntoValues<K, V, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V, A> Sync for IntoValues<K, V, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V, A> Unpin for IntoValues<K, V, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<K, V, A> UnwindSafe for IntoValues<K, V, A>where A: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::ValuesMut Struct std::collections::btree\_map::ValuesMut
==============================================
```
pub struct ValuesMut<'a, K, V> { /* private fields */ }
```
A mutable iterator over the values of a `BTreeMap`.
This `struct` is created by the [`values_mut`](../struct.btreemap#method.values_mut) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#475)### impl<K, V> Debug for ValuesMut<'\_, K, V>where V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#476)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1969)### impl<'a, K, V> DoubleEndedIterator for ValuesMut<'a, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1970)#### fn next\_back(&mut self) -> Option<&'a mut V>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1976)### impl<K, V> ExactSizeIterator for ValuesMut<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1977)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1952)### impl<'a, K, V> Iterator for ValuesMut<'a, K, V>
#### type Item = &'a mut V
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1955)#### fn next(&mut self) -> Option<&'a mut V>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1959)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1963)#### fn last(self) -> Option<&'a mut V>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)1.0.0 · #### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)1.0.0 · #### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1983)1.26.0 · ### impl<K, V> FusedIterator for ValuesMut<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for ValuesMut<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for ValuesMut<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for ValuesMut<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for ValuesMut<'a, K, V>
### impl<'a, K, V> !UnwindSafe for ValuesMut<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_map::Iter Struct std::collections::btree\_map::Iter
=========================================
```
pub struct Iter<'a, K, V>where K: 'a, V: 'a,{ /* private fields */ }
```
An iterator over the entries of a `BTreeMap`.
This `struct` is created by the [`iter`](../struct.btreemap#method.iter) method on [`BTreeMap`](../struct.btreemap "BTreeMap"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1537)### impl<K, V> Clone for Iter<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1538)#### fn clone(&self) -> Iter<'\_, K, V>
Notable traits for [Iter](struct.iter "struct std::collections::btree_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>where
K: 'a,
V: 'a,
type Item = (&'a K, &'a V);
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#359)1.17.0 · ### impl<K, V> Debug for Iter<'\_, K, V>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#360)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1518)### impl<'a, K, V> DoubleEndedIterator for Iter<'a, K, V>where K: 'a, V: 'a,
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1519)#### fn next\_back(&mut self) -> Option<(&'a K, &'a V)>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1530)### impl<K, V> ExactSizeIterator for Iter<'\_, K, V>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1531)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1485)### impl<'a, K, V> Iterator for Iter<'a, K, V>where K: 'a, V: 'a,
#### type Item = (&'a K, &'a V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1488)#### fn next(&mut self) -> Option<(&'a K, &'a V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1497)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1501)#### fn last(self) -> Option<(&'a K, &'a V)>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1505)#### fn min(self) -> Option<(&'a K, &'a V)>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1509)#### fn max(self) -> Option<(&'a K, &'a V)>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)#### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)#### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/map.rs.html#1515)1.26.0 · ### impl<K, V> FusedIterator for Iter<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Iter<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Iter<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for Iter<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Iter<'a, K, V>
### impl<'a, K, V> UnwindSafe for Iter<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::RawOccupiedEntryMut Struct std::collections::hash\_map::RawOccupiedEntryMut
=======================================================
```
pub struct RawOccupiedEntryMut<'a, K: 'a, V: 'a, S: 'a> { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
A view into an occupied entry in a `HashMap`. It is part of the [`RawEntryMut`](enum.rawentrymut "RawEntryMut") enum.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1899-2001)### impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1904-1906)#### pub fn key(&self) -> &K
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Gets a reference to the key in the entry.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1912-1914)#### pub fn key\_mut(&mut self) -> &mut K
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Gets a mutable reference to the key in the entry.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1921-1923)#### pub fn into\_key(self) -> &'a mut K
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Converts the entry into a mutable reference to the key in the entry with a lifetime bound to the map itself.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1929-1931)#### pub fn get(&self) -> &V
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Gets a reference to the value in the entry.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1938-1940)#### pub fn into\_mut(self) -> &'a mut V
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Converts the `OccupiedEntry` into a mutable reference to the value in the entry with a lifetime bound to the map itself.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1946-1948)#### pub fn get\_mut(&mut self) -> &mut V
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Gets a mutable reference to the value in the entry.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1954-1956)#### pub fn get\_key\_value(&mut self) -> (&K, &V)
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Gets a reference to the key and value in the entry.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1961-1963)#### pub fn get\_key\_value\_mut(&mut self) -> (&mut K, &mut V)
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Gets a mutable reference to the key and value in the entry.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1970-1972)#### pub fn into\_key\_value(self) -> (&'a mut K, &'a mut V)
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Converts the `OccupiedEntry` into a mutable reference to the key and value in the entry with a lifetime bound to the map itself.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1977-1979)#### pub fn insert(&mut self, value: V) -> V
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Sets the value of the entry, and returns the entry’s old value.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1984-1986)#### pub fn insert\_key(&mut self, key: K) -> K
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Sets the value of the entry, and returns the entry’s old value.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1991-1993)#### pub fn remove(self) -> V
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Takes the value out of the entry, and returns it.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1998-2000)#### pub fn remove\_entry(self) -> (K, V)
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Take the ownership of the key and value from the map.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2047-2054)### impl<K: Debug, V: Debug, S> Debug for RawOccupiedEntryMut<'\_, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2048-2053)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, S> RefUnwindSafe for RawOccupiedEntryMut<'a, K, V, S>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, S> Send for RawOccupiedEntryMut<'a, K, V, S>where K: [Send](../../marker/trait.send "trait std::marker::Send"), S: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Sync for RawOccupiedEntryMut<'a, K, V, S>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Unpin for RawOccupiedEntryMut<'a, K, V, S>
### impl<'a, K, V, S> !UnwindSafe for RawOccupiedEntryMut<'a, K, V, S>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::Values Struct std::collections::hash\_map::Values
==========================================
```
pub struct Values<'a, K: 'a, V: 'a> { /* private fields */ }
```
An iterator over the values of a `HashMap`.
This `struct` is created by the [`values`](struct.hashmap#method.values) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
]);
let iter_values = map.values();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1536-1541)### impl<K, V> Clone for Values<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1538-1540)#### fn clone(&self) -> Self
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1544-1548)1.16.0 · ### impl<K, V: Debug> Debug for Values<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1545-1547)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2351-2356)### impl<K, V> ExactSizeIterator for Values<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2353-2355)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2338-2349)### impl<'a, K, V> Iterator for Values<'a, K, V>
#### type Item = &'a V
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2342-2344)#### fn next(&mut self) -> Option<&'a V>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2346-2348)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2358)1.26.0 · ### impl<K, V> FusedIterator for Values<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Values<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Values<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for Values<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Values<'a, K, V>
### impl<'a, K, V> UnwindSafe for Values<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Enum std::collections::hash_map::RawEntryMut Enum std::collections::hash\_map::RawEntryMut
=============================================
```
pub enum RawEntryMut<'a, K: 'a, V: 'a, S: 'a> {
Occupied(RawOccupiedEntryMut<'a, K, V, S>),
Vacant(RawVacantEntryMut<'a, K, V, S>),
}
```
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
A view into a single entry in a map, which may either be vacant or occupied.
This is a lower-level version of [`Entry`](enum.entry "Entry").
This `enum` is constructed through the [`raw_entry_mut`](struct.hashmap#method.raw_entry_mut) method on [`HashMap`](struct.hashmap "HashMap"), then calling one of the methods of that [`RawEntryBuilderMut`](struct.rawentrybuildermut "RawEntryBuilderMut").
Variants
--------
### `Occupied([RawOccupiedEntryMut](struct.rawoccupiedentrymut "struct std::collections::hash_map::RawOccupiedEntryMut")<'a, K, V, S>)`
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
An occupied entry.
### `Vacant([RawVacantEntryMut](struct.rawvacantentrymut "struct std::collections::hash_map::RawVacantEntryMut")<'a, K, V, S>)`
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
A vacant entry.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1792-1897)### impl<'a, K, V, S> RawEntryMut<'a, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1812-1821)#### pub fn or\_insert(self, default\_key: K, default\_val: V) -> (&'a mut K, &'a mut V)where K: [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Ensures a value is in the entry by inserting the default if empty, and returns mutable references to the key and value in the entry.
##### Examples
```
#![feature(hash_raw_entry)]
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 3);
assert_eq!(map["poneyland"], 3);
*map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 10).1 *= 2;
assert_eq!(map["poneyland"], 6);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1842-1855)#### pub fn or\_insert\_with<F>(self, default: F) -> (&'a mut K, &'a mut V)where F: [FnOnce](../../ops/trait.fnonce "trait std::ops::FnOnce")() -> [(K, V)](../../primitive.tuple), K: [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Ensures a value is in the entry by inserting the result of the default function if empty, and returns mutable references to the key and value in the entry.
##### Examples
```
#![feature(hash_raw_entry)]
use std::collections::HashMap;
let mut map: HashMap<&str, String> = HashMap::new();
map.raw_entry_mut().from_key("poneyland").or_insert_with(|| {
("poneyland", "hoho".to_string())
});
assert_eq!(map["poneyland"], "hoho".to_string());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1882-1896)#### pub fn and\_modify<F>(self, f: F) -> Selfwhere F: [FnOnce](../../ops/trait.fnonce "trait std::ops::FnOnce")([&mut](../../primitive.reference) K, [&mut](../../primitive.reference) V),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
##### Examples
```
#![feature(hash_raw_entry)]
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
map.raw_entry_mut()
.from_key("poneyland")
.and_modify(|_k, v| { *v += 1 })
.or_insert("poneyland", 42);
assert_eq!(map["poneyland"], 42);
map.raw_entry_mut()
.from_key("poneyland")
.and_modify(|_k, v| { *v += 1 })
.or_insert("poneyland", 0);
assert_eq!(map["poneyland"], 43);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2037-2044)### impl<K: Debug, V: Debug, S> Debug for RawEntryMut<'\_, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2038-2043)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, S> RefUnwindSafe for RawEntryMut<'a, K, V, S>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, S> Send for RawEntryMut<'a, K, V, S>where K: [Send](../../marker/trait.send "trait std::marker::Send"), S: [Send](../../marker/trait.send "trait std::marker::Send") + [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Sync for RawEntryMut<'a, K, V, S>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Unpin for RawEntryMut<'a, K, V, S>
### impl<'a, K, V, S> !UnwindSafe for RawEntryMut<'a, K, V, S>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Module std::collections::hash_map Module std::collections::hash\_map
==================================
A hash map implemented with quadratic probing and SIMD lookup.
Structs
-------
[DrainFilter](struct.drainfilter "std::collections::hash_map::DrainFilter struct")Experimental
A draining, filtering iterator over the entries of a `HashMap`.
[OccupiedError](struct.occupiederror "std::collections::hash_map::OccupiedError struct")Experimental
The error returned by [`try_insert`](struct.hashmap#method.try_insert) when the key already exists.
[RawEntryBuilder](struct.rawentrybuilder "std::collections::hash_map::RawEntryBuilder struct")Experimental
A builder for computing where in a HashMap a key-value pair would be stored.
[RawEntryBuilderMut](struct.rawentrybuildermut "std::collections::hash_map::RawEntryBuilderMut struct")Experimental
A builder for computing where in a HashMap a key-value pair would be stored.
[RawOccupiedEntryMut](struct.rawoccupiedentrymut "std::collections::hash_map::RawOccupiedEntryMut struct")Experimental
A view into an occupied entry in a `HashMap`. It is part of the [`RawEntryMut`](enum.rawentrymut "RawEntryMut") enum.
[RawVacantEntryMut](struct.rawvacantentrymut "std::collections::hash_map::RawVacantEntryMut struct")Experimental
A view into a vacant entry in a `HashMap`. It is part of the [`RawEntryMut`](enum.rawentrymut "RawEntryMut") enum.
[DefaultHasher](struct.defaulthasher "std::collections::hash_map::DefaultHasher struct")
The default [`Hasher`](../../hash/trait.hasher "Hasher") used by [`RandomState`](struct.randomstate "RandomState").
[Drain](struct.drain "std::collections::hash_map::Drain struct")
A draining iterator over the entries of a `HashMap`.
[HashMap](struct.hashmap "std::collections::hash_map::HashMap struct")
A [hash map](../index#use-a-hashmap-when) implemented with quadratic probing and SIMD lookup.
[IntoIter](struct.intoiter "std::collections::hash_map::IntoIter struct")
An owning iterator over the entries of a `HashMap`.
[IntoKeys](struct.intokeys "std::collections::hash_map::IntoKeys struct")
An owning iterator over the keys of a `HashMap`.
[IntoValues](struct.intovalues "std::collections::hash_map::IntoValues struct")
An owning iterator over the values of a `HashMap`.
[Iter](struct.iter "std::collections::hash_map::Iter struct")
An iterator over the entries of a `HashMap`.
[IterMut](struct.itermut "std::collections::hash_map::IterMut struct")
A mutable iterator over the entries of a `HashMap`.
[Keys](struct.keys "std::collections::hash_map::Keys struct")
An iterator over the keys of a `HashMap`.
[OccupiedEntry](struct.occupiedentry "std::collections::hash_map::OccupiedEntry struct")
A view into an occupied entry in a `HashMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
[RandomState](struct.randomstate "std::collections::hash_map::RandomState struct")
`RandomState` is the default state for [`HashMap`](struct.hashmap "HashMap") types.
[VacantEntry](struct.vacantentry "std::collections::hash_map::VacantEntry struct")
A view into a vacant entry in a `HashMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
[Values](struct.values "std::collections::hash_map::Values struct")
An iterator over the values of a `HashMap`.
[ValuesMut](struct.valuesmut "std::collections::hash_map::ValuesMut struct")
A mutable iterator over the values of a `HashMap`.
Enums
-----
[RawEntryMut](enum.rawentrymut "std::collections::hash_map::RawEntryMut enum")Experimental
A view into a single entry in a map, which may either be vacant or occupied.
[Entry](enum.entry "std::collections::hash_map::Entry enum")
A view into a single entry in a map, which may either be vacant or occupied.
rust Struct std::collections::hash_map::VacantEntry Struct std::collections::hash\_map::VacantEntry
===============================================
```
pub struct VacantEntry<'a, K: 'a, V: 'a> { /* private fields */ }
```
A view into a vacant entry in a `HashMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2930-3013)### impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2944-2946)1.10.0 · #### pub fn key(&self) -> &K
Gets a reference to the key that would be used when inserting a value through the `VacantEntry`.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
assert_eq!(map.entry("poneyland").key(), &"poneyland");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2964-2966)1.12.0 · #### pub fn into\_key(self) -> K
Take ownership of the key.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
if let Entry::Vacant(v) = map.entry("poneyland") {
v.into_key();
}
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2986-2988)#### pub fn insert(self, value: V) -> &'a mut V
Sets the value of the entry with the `VacantEntry`’s key, and returns a mutable reference to it.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
if let Entry::Vacant(o) = map.entry("poneyland") {
o.insert(37);
}
assert_eq!(map["poneyland"], 37);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3009-3012)#### pub fn insert\_entry(self, value: V) -> OccupiedEntry<'a, K, V>
🔬This is a nightly-only experimental API. (`entry_insert` [#65225](https://github.com/rust-lang/rust/issues/65225))
Sets the value of the entry with the `VacantEntry`’s key, and returns an `OccupiedEntry`.
##### Examples
```
#![feature(entry_insert)]
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
if let Entry::Vacant(o) = map.entry("poneyland") {
o.insert_entry(37);
}
assert_eq!(map["poneyland"], 37);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2122-2126)1.12.0 · ### impl<K: Debug, V> Debug for VacantEntry<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2123-2125)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for VacantEntry<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for VacantEntry<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for VacantEntry<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for VacantEntry<'a, K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> !UnwindSafe for VacantEntry<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::Keys Struct std::collections::hash\_map::Keys
========================================
```
pub struct Keys<'a, K: 'a, V: 'a> { /* private fields */ }
```
An iterator over the keys of a `HashMap`.
This `struct` is created by the [`keys`](struct.hashmap#method.keys) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
]);
let iter_keys = map.keys();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1498-1503)### impl<K, V> Clone for Keys<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1500-1502)#### fn clone(&self) -> Self
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1506-1510)1.16.0 · ### impl<K: Debug, V> Debug for Keys<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1507-1509)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2328-2333)### impl<K, V> ExactSizeIterator for Keys<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2330-2332)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2315-2326)### impl<'a, K, V> Iterator for Keys<'a, K, V>
#### type Item = &'a K
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2319-2321)#### fn next(&mut self) -> Option<&'a K>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2323-2325)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2335)1.26.0 · ### impl<K, V> FusedIterator for Keys<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Keys<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Keys<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for Keys<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Keys<'a, K, V>
### impl<'a, K, V> UnwindSafe for Keys<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Enum std::collections::hash_map::Entry Enum std::collections::hash\_map::Entry
=======================================
```
pub enum Entry<'a, K: 'a, V: 'a> {
Occupied(OccupiedEntry<'a, K, V>),
Vacant(VacantEntry<'a, K, V>),
}
```
A view into a single entry in a map, which may either be vacant or occupied.
This `enum` is constructed from the [`entry`](struct.hashmap#method.entry) method on [`HashMap`](struct.hashmap "HashMap").
Variants
--------
### `Occupied([OccupiedEntry](struct.occupiedentry "struct std::collections::hash_map::OccupiedEntry")<'a, K, V>)`
An occupied entry.
### `Vacant([VacantEntry](struct.vacantentry "struct std::collections::hash_map::VacantEntry")<'a, K, V>)`
A vacant entry.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2514-2672)### impl<'a, K, V> Entry<'a, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2533-2538)#### pub fn or\_insert(self, default: V) -> &'a mut V
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(3);
assert_eq!(map["poneyland"], 3);
*map.entry("poneyland").or_insert(10) *= 2;
assert_eq!(map["poneyland"], 6);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2557-2562)#### pub 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, and returns a mutable reference to the value in the entry.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, String> = HashMap::new();
let s = "hoho".to_string();
map.entry("poneyland").or_insert_with(|| s);
assert_eq!(map["poneyland"], "hoho".to_string());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2584-2592)1.50.0 · #### pub 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. This method allows for generating key-derived values for insertion by providing the default function a reference to the key that was moved during the `.entry(key)` method call.
The reference to the moved key is provided so that cloning or copying the key is unnecessary, unlike with `.or_insert_with(|| ... )`.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, usize> = HashMap::new();
map.entry("poneyland").or_insert_with_key(|key| key.chars().count());
assert_eq!(map["poneyland"], 9);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2606-2611)1.10.0 · #### pub fn key(&self) -> &K
Returns a reference to this entry’s key.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
assert_eq!(map.entry("poneyland").key(), &"poneyland");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2635-2646)1.26.0 · #### pub fn and\_modify<F>(self, f: F) -> Selfwhere F: [FnOnce](../../ops/trait.fnonce "trait std::ops::FnOnce")([&mut](../../primitive.reference) V),
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland")
.and_modify(|e| { *e += 1 })
.or_insert(42);
assert_eq!(map["poneyland"], 42);
map.entry("poneyland")
.and_modify(|e| { *e += 1 })
.or_insert(42);
assert_eq!(map["poneyland"], 43);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2663-2671)#### pub fn insert\_entry(self, value: V) -> OccupiedEntry<'a, K, V>
🔬This is a nightly-only experimental API. (`entry_insert` [#65225](https://github.com/rust-lang/rust/issues/65225))
Sets the value of the entry, and returns an `OccupiedEntry`.
##### Examples
```
#![feature(entry_insert)]
use std::collections::HashMap;
let mut map: HashMap<&str, String> = HashMap::new();
let entry = map.entry("poneyland").insert_entry("hoho".to_string());
assert_eq!(entry.key(), &"poneyland");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2674-2698)### impl<'a, K, V: Default> Entry<'a, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2692-2697)1.28.0 · #### pub fn or\_default(self) -> &'a mut V
Ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, Option<u32>> = HashMap::new();
map.entry("poneyland").or_default();
assert_eq!(map["poneyland"], None);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2088-2095)1.12.0 · ### impl<K: Debug, V: Debug> Debug for Entry<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2089-2094)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Entry<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Entry<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for Entry<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Entry<'a, K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> !UnwindSafe for Entry<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::IterMut Struct std::collections::hash\_map::IterMut
===========================================
```
pub struct IterMut<'a, K: 'a, V: 'a> { /* private fields */ }
```
A mutable iterator over the entries of a `HashMap`.
This `struct` is created by the [`iter_mut`](struct.hashmap#method.iter_mut) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
]);
let iter = map.iter_mut();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2274-2282)1.16.0 · ### impl<K, V> Debug for IterMut<'\_, K, V>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2279-2281)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2264-2269)### impl<K, V> ExactSizeIterator for IterMut<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2266-2268)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2251-2262)### impl<'a, K, V> Iterator for IterMut<'a, K, V>
#### type Item = (&'a K, &'a mut V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2255-2257)#### fn next(&mut self) -> Option<(&'a K, &'a mut V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2259-2261)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2271)1.26.0 · ### impl<K, V> FusedIterator for IterMut<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for IterMut<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for IterMut<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for IterMut<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for IterMut<'a, K, V>
### impl<'a, K, V> !UnwindSafe for IterMut<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::IntoIter Struct std::collections::hash\_map::IntoIter
============================================
```
pub struct IntoIter<K, V> { /* private fields */ }
```
An owning iterator over the entries of a `HashMap`.
This `struct` is created by the [`into_iter`](../../iter/trait.intoiterator#tymethod.into_iter) method on [`HashMap`](struct.hashmap "HashMap") (provided by the [`IntoIterator`](../../iter/trait.intoiterator) trait). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
]);
let iter = map.into_iter();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2308-2312)1.16.0 · ### impl<K: Debug, V: Debug> Debug for IntoIter<K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2309-2311)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2298-2303)### impl<K, V> ExactSizeIterator for IntoIter<K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2300-2302)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2285-2296)### impl<K, V> Iterator for IntoIter<K, V>
#### type Item = (K, V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2289-2291)#### fn next(&mut self) -> Option<(K, V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2293-2295)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2305)1.26.0 · ### impl<K, V> FusedIterator for IntoIter<K, V>
Auto Trait Implementations
--------------------------
### impl<K, V> RefUnwindSafe for IntoIter<K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V> Send for IntoIter<K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V> Sync for IntoIter<K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V> Unpin for IntoIter<K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<K, V> UnwindSafe for IntoIter<K, V>where K: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::RawEntryBuilderMut Struct std::collections::hash\_map::RawEntryBuilderMut
======================================================
```
pub struct RawEntryBuilderMut<'a, K: 'a, V: 'a, S: 'a> { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
A builder for computing where in a HashMap a key-value pair would be stored.
See the [`HashMap::raw_entry_mut`](struct.hashmap#method.raw_entry_mut "HashMap::raw_entry_mut") docs for usage examples.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1718-1753)### impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S>where S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1725-1731)#### pub fn from\_key<Q: ?Sized>(self, k: &Q) -> RawEntryMut<'a, K, V, S>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Creates a `RawEntryMut` from the given key.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1736-1742)#### pub fn from\_key\_hashed\_nocheck<Q: ?Sized>( self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Creates a `RawEntryMut` from the given key and its hash.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1747-1752)#### pub fn from\_hash<F>(self, hash: u64, is\_match: F) -> RawEntryMut<'a, K, V, S>where for<'b> F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&'b](../../primitive.reference) K) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Creates a `RawEntryMut` from the given hash.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2030-2034)### impl<K, V, S> Debug for RawEntryBuilderMut<'\_, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2031-2033)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, S> RefUnwindSafe for RawEntryBuilderMut<'a, K, V, S>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, S> Send for RawEntryBuilderMut<'a, K, V, S>where K: [Send](../../marker/trait.send "trait std::marker::Send"), S: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Sync for RawEntryBuilderMut<'a, K, V, S>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Unpin for RawEntryBuilderMut<'a, K, V, S>
### impl<'a, K, V, S> !UnwindSafe for RawEntryBuilderMut<'a, K, V, S>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::RawVacantEntryMut Struct std::collections::hash\_map::RawVacantEntryMut
=====================================================
```
pub struct RawVacantEntryMut<'a, K: 'a, V: 'a, S: 'a> { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
A view into a vacant entry in a `HashMap`. It is part of the [`RawEntryMut`](enum.rawentrymut "RawEntryMut") enum.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2003-2027)### impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2008-2014)#### pub fn insert(self, key: K, value: V) -> (&'a mut K, &'a mut V)where K: [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Sets the value of the entry with the `VacantEntry`’s key, and returns a mutable reference to it.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2020-2026)#### pub fn insert\_hashed\_nocheck( self, hash: u64, key: K, value: V) -> (&'a mut K, &'a mut V)where K: [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Sets the value of the entry with the VacantEntry’s key, and returns a mutable reference to it.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2057-2061)### impl<K, V, S> Debug for RawVacantEntryMut<'\_, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2058-2060)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, S> RefUnwindSafe for RawVacantEntryMut<'a, K, V, S>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, S> Send for RawVacantEntryMut<'a, K, V, S>where K: [Send](../../marker/trait.send "trait std::marker::Send"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, S> Sync for RawVacantEntryMut<'a, K, V, S>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Unpin for RawVacantEntryMut<'a, K, V, S>
### impl<'a, K, V, S> !UnwindSafe for RawVacantEntryMut<'a, K, V, S>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::DrainFilter Struct std::collections::hash\_map::DrainFilter
===============================================
```
pub struct DrainFilter<'a, K, V, F>where F: FnMut(&K, &mut V) -> bool,{ /* private fields */ }
```
🔬This is a nightly-only experimental API. (`hash_drain_filter` [#59618](https://github.com/rust-lang/rust/issues/59618))
A draining, filtering iterator over the entries of a `HashMap`.
This `struct` is created by the [`drain_filter`](struct.hashmap#method.drain_filter) method on [`HashMap`](struct.hashmap "HashMap").
Example
-------
```
#![feature(hash_drain_filter)]
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
]);
let iter = map.drain_filter(|_k, v| *v % 2 == 0);
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2505-2512)### impl<'a, K, V, F> Debug for DrainFilter<'a, K, V, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2509-2511)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2485-2499)### impl<K, V, F> Iterator for DrainFilter<'\_, K, V, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
#### type Item = (K, V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2492-2494)#### fn next(&mut self) -> Option<(K, V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2496-2498)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2502)### impl<K, V, F> FusedIterator for DrainFilter<'\_, K, V, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
Auto Trait Implementations
--------------------------
### impl<'a, K, V, F> RefUnwindSafe for DrainFilter<'a, K, V, F>where F: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, F> Send for DrainFilter<'a, K, V, F>where F: [Send](../../marker/trait.send "trait std::marker::Send"), K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V, F> Sync for DrainFilter<'a, K, V, F>where F: [Sync](../../marker/trait.sync "trait std::marker::Sync"), K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, F> Unpin for DrainFilter<'a, K, V, F>where F: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V, F> !UnwindSafe for DrainFilter<'a, K, V, F>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::DefaultHasher Struct std::collections::hash\_map::DefaultHasher
=================================================
```
pub struct DefaultHasher(_);
```
The default [`Hasher`](../../hash/trait.hasher "Hasher") used by [`RandomState`](struct.randomstate "RandomState").
The internal algorithm is not specified, and so it and its hashes should not be relied upon over releases.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3156-3169)### impl DefaultHasher
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3166-3168)#### pub fn new() -> DefaultHasher
Creates a new `DefaultHasher`.
This hasher is not guaranteed to be the same as all other `DefaultHasher` instances, but is the same as all other `DefaultHasher` instances created through `new` or `default`.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3153)### impl Clone for DefaultHasher
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3153)#### fn clone(&self) -> DefaultHasher
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3153)### impl Debug for DefaultHasher
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3153)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3172-3181)### impl Default for DefaultHasher
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3178-3180)#### fn default() -> DefaultHasher
Creates a new `DefaultHasher` using [`new`](struct.defaulthasher#method.new). See its documentation for more.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3184-3202)### impl Hasher for DefaultHasher
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3189-3191)#### fn write(&mut self, msg: &[u8])
Writes some data into this `Hasher`. [Read more](../../hash/trait.hasher#tymethod.write)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3194-3196)#### fn write\_str(&mut self, s: &str)
🔬This is a nightly-only experimental API. (`hasher_prefixfree_extras` [#96762](https://github.com/rust-lang/rust/issues/96762))
Writes a single `str` into this hasher. [Read more](../../hash/trait.hasher#method.write_str)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3199-3201)#### fn finish(&self) -> u64
Returns the hash value for the values written so far. [Read more](../../hash/trait.hasher#tymethod.finish)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#367)1.3.0 · #### fn write\_u8(&mut self, i: u8)
Writes a single `u8` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#373)1.3.0 · #### fn write\_u16(&mut self, i: u16)
Writes a single `u16` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#379)1.3.0 · #### fn write\_u32(&mut self, i: u32)
Writes a single `u32` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#385)1.3.0 · #### fn write\_u64(&mut self, i: u64)
Writes a single `u64` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#391)1.26.0 · #### fn write\_u128(&mut self, i: u128)
Writes a single `u128` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#397)1.3.0 · #### fn write\_usize(&mut self, i: usize)
Writes a single `usize` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#404)1.3.0 · #### fn write\_i8(&mut self, i: i8)
Writes a single `i8` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#410)1.3.0 · #### fn write\_i16(&mut self, i: i16)
Writes a single `i16` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#416)1.3.0 · #### fn write\_i32(&mut self, i: i32)
Writes a single `i32` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#422)1.3.0 · #### fn write\_i64(&mut self, i: i64)
Writes a single `i64` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#428)1.26.0 · #### fn write\_i128(&mut self, i: i128)
Writes a single `i128` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#434)1.3.0 · #### fn write\_isize(&mut self, i: isize)
Writes a single `isize` into this hasher.
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#487)#### fn write\_length\_prefix(&mut self, len: usize)
🔬This is a nightly-only experimental API. (`hasher_prefixfree_extras` [#96762](https://github.com/rust-lang/rust/issues/96762))
Writes a length prefix into this hasher, as part of being prefix-free. [Read more](../../hash/trait.hasher#method.write_length_prefix)
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for DefaultHasher
### impl Send for DefaultHasher
### impl Sync for DefaultHasher
### impl Unpin for DefaultHasher
### impl UnwindSafe for DefaultHasher
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::IntoKeys Struct std::collections::hash\_map::IntoKeys
============================================
```
pub struct IntoKeys<K, V> { /* private fields */ }
```
An owning iterator over the keys of a `HashMap`.
This `struct` is created by the [`into_keys`](struct.hashmap#method.into_keys) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
]);
let iter_keys = map.into_keys();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2414-2418)### impl<K: Debug, V> Debug for IntoKeys<K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2415-2417)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2404-2409)### impl<K, V> ExactSizeIterator for IntoKeys<K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2406-2408)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2391-2402)### impl<K, V> Iterator for IntoKeys<K, V>
#### type Item = K
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2395-2397)#### fn next(&mut self) -> Option<K>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2399-2401)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2411)### impl<K, V> FusedIterator for IntoKeys<K, V>
Auto Trait Implementations
--------------------------
### impl<K, V> RefUnwindSafe for IntoKeys<K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V> Send for IntoKeys<K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V> Sync for IntoKeys<K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V> Unpin for IntoKeys<K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<K, V> UnwindSafe for IntoKeys<K, V>where K: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::OccupiedError Struct std::collections::hash\_map::OccupiedError
=================================================
```
pub struct OccupiedError<'a, K: 'a, V: 'a> {
pub entry: OccupiedEntry<'a, K, V>,
pub value: V,
}
```
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
The error returned by [`try_insert`](struct.hashmap#method.try_insert) when the key already exists.
Contains the occupied entry, and the value that was not inserted.
Fields
------
`entry: [OccupiedEntry](struct.occupiedentry "struct std::collections::hash_map::OccupiedEntry")<'a, K, V>`
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
The entry in the map that was already occupied.
`value: V`
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
The value which was not inserted, because the entry was already occupied.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2140-2148)### impl<K: Debug, V: Debug> Debug for OccupiedError<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2141-2147)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2151-2161)### impl<'a, K: Debug, V: Debug> Display for OccupiedError<'a, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2152-2160)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.display#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2165-2170)### impl<'a, K: Debug, V: Debug> Error for OccupiedError<'a, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2167-2169)#### fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to\_string()
[Read more](../../error/trait.error#method.description)
[source](https://doc.rust-lang.org/src/core/error.rs.html#83)1.30.0 · #### fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. [Read more](../../error/trait.error#method.source)
[source](https://doc.rust-lang.org/src/core/error.rs.html#119)1.0.0 · #### fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
[source](https://doc.rust-lang.org/src/core/error.rs.html#193)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`error_generic_member_access` [#99301](https://github.com/rust-lang/rust/issues/99301))
Provides type based access to context intended for error reports. [Read more](../../error/trait.error#method.provide)
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for OccupiedError<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for OccupiedError<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for OccupiedError<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for OccupiedError<'a, K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> !UnwindSafe for OccupiedError<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/error.rs.html#197)### impl<E> Provider for Ewhere E: [Error](../../error/trait.error "trait std::error::Error") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/error.rs.html#201)#### fn provide(&'a self, demand: &mut Demand<'a>)
🔬This is a nightly-only experimental API. (`provide_any` [#96024](https://github.com/rust-lang/rust/issues/96024))
Data providers should implement this method to provide *all* values they are able to provide by using `demand`. [Read more](../../any/trait.provider#tymethod.provide)
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2500)### impl<T> ToString for Twhere T: [Display](../../fmt/trait.display "trait std::fmt::Display") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/alloc/string.rs.html#2506)#### default fn to\_string(&self) -> String
Converts the given value to a `String`. [Read more](../../string/trait.tostring#tymethod.to_string)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::RawEntryBuilder Struct std::collections::hash\_map::RawEntryBuilder
===================================================
```
pub struct RawEntryBuilder<'a, K: 'a, V: 'a, S: 'a> { /* private fields */ }
```
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
A builder for computing where in a HashMap a key-value pair would be stored.
See the [`HashMap::raw_entry`](struct.hashmap#method.raw_entry "HashMap::raw_entry") docs for usage examples.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1755-1790)### impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S>where S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1762-1768)#### pub fn from\_key<Q: ?Sized>(self, k: &Q) -> Option<(&'a K, &'a V)>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Access an entry by key.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1773-1779)#### pub fn from\_key\_hashed\_nocheck<Q: ?Sized>( self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Access an entry by a key and its hash.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1784-1789)#### pub fn from\_hash<F>(self, hash: u64, is\_match: F) -> Option<(&'a K, &'a V)>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Access an entry by hash.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2064-2068)### impl<K, V, S> Debug for RawEntryBuilder<'\_, K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2065-2067)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V, S> RefUnwindSafe for RawEntryBuilder<'a, K, V, S>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V, S> Send for RawEntryBuilder<'a, K, V, S>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Sync for RawEntryBuilder<'a, K, V, S>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V, S> Unpin for RawEntryBuilder<'a, K, V, S>
### impl<'a, K, V, S> UnwindSafe for RawEntryBuilder<'a, K, V, S>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Struct std::collections::hash_map::OccupiedEntry Struct std::collections::hash\_map::OccupiedEntry
=================================================
```
pub struct OccupiedEntry<'a, K: 'a, V: 'a> { /* private fields */ }
```
A view into an occupied entry in a `HashMap`. It is part of the [`Entry`](enum.entry "Entry") enum.
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2700-2928)### impl<'a, K, V> OccupiedEntry<'a, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2714-2716)1.10.0 · #### pub fn key(&self) -> &K
Gets a reference to the key in the entry.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map.entry("poneyland").key(), &"poneyland");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2738-2740)1.12.0 · #### pub fn remove\_entry(self) -> (K, V)
Take the ownership of the key and value from the map.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(o) = map.entry("poneyland") {
// We delete the entry from the map.
o.remove_entry();
}
assert_eq!(map.contains_key("poneyland"), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2759-2761)#### pub fn get(&self) -> &V
Gets a reference to the value in the entry.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(o) = map.entry("poneyland") {
assert_eq!(o.get(), &12);
}
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2792-2794)#### pub fn get\_mut(&mut self) -> &mut V
Gets a mutable reference to the value in the entry.
If you need a reference to the `OccupiedEntry` which may outlive the destruction of the `Entry` value, see [`into_mut`](struct.occupiedentry#method.into_mut).
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map["poneyland"], 12);
if let Entry::Occupied(mut o) = map.entry("poneyland") {
*o.get_mut() += 10;
assert_eq!(*o.get(), 22);
// We can use the same Entry multiple times.
*o.get_mut() += 2;
}
assert_eq!(map["poneyland"], 24);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2821-2823)#### pub fn into\_mut(self) -> &'a mut V
Converts the `OccupiedEntry` into a mutable reference to the value in the entry with a lifetime bound to the map itself.
If you need multiple references to the `OccupiedEntry`, see [`get_mut`](struct.occupiedentry#method.get_mut).
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(12);
assert_eq!(map["poneyland"], 12);
if let Entry::Occupied(o) = map.entry("poneyland") {
*o.into_mut() += 10;
}
assert_eq!(map["poneyland"], 22);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2844-2846)#### pub fn insert(&mut self, value: V) -> V
Sets the value of the entry, and returns the entry’s old value.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(mut o) = map.entry("poneyland") {
assert_eq!(o.insert(15), 12);
}
assert_eq!(map["poneyland"], 15);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2867-2869)#### pub fn remove(self) -> V
Takes the value out of the entry, and returns it.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::Entry;
let mut map: HashMap<&str, u32> = HashMap::new();
map.entry("poneyland").or_insert(12);
if let Entry::Occupied(o) = map.entry("poneyland") {
assert_eq!(o.remove(), 12);
}
assert_eq!(map.contains_key("poneyland"), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2894-2896)#### pub fn replace\_entry(self, value: V) -> (K, V)
🔬This is a nightly-only experimental API. (`map_entry_replace` [#44286](https://github.com/rust-lang/rust/issues/44286))
Replaces the entry, returning the old key and value. The new key in the hash map will be the key used to create this entry.
##### Examples
```
#![feature(map_entry_replace)]
use std::collections::hash_map::{Entry, HashMap};
use std::rc::Rc;
let mut map: HashMap<Rc<String>, u32> = HashMap::new();
map.insert(Rc::new("Stringthing".to_string()), 15);
let my_key = Rc::new("Stringthing".to_string());
if let Entry::Occupied(entry) = map.entry(my_key) {
// Also replace the key with a handle to our other key.
let (old_key, old_value): (Rc<String>, u32) = entry.replace_entry(16);
}
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2925-2927)#### pub fn replace\_key(self) -> K
🔬This is a nightly-only experimental API. (`map_entry_replace` [#44286](https://github.com/rust-lang/rust/issues/44286))
Replaces the key in the hash map with the key used to create this entry.
##### Examples
```
#![feature(map_entry_replace)]
use std::collections::hash_map::{Entry, HashMap};
use std::rc::Rc;
let mut map: HashMap<Rc<String>, u32> = HashMap::new();
let known_strings: Vec<Rc<String>> = Vec::new();
// Initialise known strings, run program, etc.
reclaim_memory(&mut map, &known_strings);
fn reclaim_memory(map: &mut HashMap<Rc<String>, u32>, known_strings: &[Rc<String>] ) {
for s in known_strings {
if let Entry::Occupied(entry) = map.entry(Rc::clone(s)) {
// Replaces the entry's key with our version of it in `known_strings`.
entry.replace_key();
}
}
}
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2105-2112)1.12.0 · ### impl<K: Debug, V: Debug> Debug for OccupiedEntry<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2106-2111)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for OccupiedEntry<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for OccupiedEntry<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for OccupiedEntry<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for OccupiedEntry<'a, K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> !UnwindSafe for OccupiedEntry<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::Drain Struct std::collections::hash\_map::Drain
=========================================
```
pub struct Drain<'a, K: 'a, V: 'a> { /* private fields */ }
```
A draining iterator over the entries of a `HashMap`.
This `struct` is created by the [`drain`](struct.hashmap#method.drain) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
]);
let iter = map.drain();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2474-2482)1.16.0 · ### impl<K, V> Debug for Drain<'\_, K, V>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2479-2481)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2464-2469)### impl<K, V> ExactSizeIterator for Drain<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2466-2468)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2451-2462)### impl<'a, K, V> Iterator for Drain<'a, K, V>
#### type Item = (K, V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2455-2457)#### fn next(&mut self) -> Option<(K, V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2459-2461)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)#### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)#### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2471)1.26.0 · ### impl<K, V> FusedIterator for Drain<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Drain<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Drain<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for Drain<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Drain<'a, K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, K, V> UnwindSafe for Drain<'a, K, V>where K: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::IntoValues Struct std::collections::hash\_map::IntoValues
==============================================
```
pub struct IntoValues<K, V> { /* private fields */ }
```
An owning iterator over the values of a `HashMap`.
This `struct` is created by the [`into_values`](struct.hashmap#method.into_values) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
]);
let iter_keys = map.into_values();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2444-2448)### impl<K, V: Debug> Debug for IntoValues<K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2445-2447)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2434-2439)### impl<K, V> ExactSizeIterator for IntoValues<K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2436-2438)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2421-2432)### impl<K, V> Iterator for IntoValues<K, V>
#### type Item = V
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2425-2427)#### fn next(&mut self) -> Option<V>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2429-2431)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2441)### impl<K, V> FusedIterator for IntoValues<K, V>
Auto Trait Implementations
--------------------------
### impl<K, V> RefUnwindSafe for IntoValues<K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V> Send for IntoValues<K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V> Sync for IntoValues<K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V> Unpin for IntoValues<K, V>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<K, V> UnwindSafe for IntoValues<K, V>where K: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe") + [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::HashMap Struct std::collections::hash\_map::HashMap
===========================================
```
pub struct HashMap<K, V, S = RandomState> { /* private fields */ }
```
A [hash map](../index#use-a-hashmap-when) implemented with quadratic probing and SIMD lookup.
By default, `HashMap` uses a hashing algorithm selected to provide resistance against HashDoS attacks. The algorithm is randomly seeded, and a reasonable best-effort is made to generate this seed from a high quality, secure source of randomness provided by the host without blocking the program. Because of this, the randomness of the seed depends on the output quality of the system’s random number generator when the seed is created. In particular, seeds generated when the system’s entropy pool is abnormally low such as during system boot may be of a lower quality.
The default hashing algorithm is currently SipHash 1-3, though this is subject to change at any point in the future. While its performance is very competitive for medium sized keys, other hashing algorithms will outperform it for small keys such as integers as well as large keys such as long strings, though those algorithms will typically *not* protect against attacks such as HashDoS.
The hashing algorithm can be replaced on a per-`HashMap` basis using the [`default`](../../default/trait.default#tymethod.default), [`with_hasher`](struct.hashmap#method.with_hasher), and [`with_capacity_and_hasher`](struct.hashmap#method.with_capacity_and_hasher) methods. There are many alternative [hashing algorithms available on crates.io](https://crates.io/keywords/hasher).
It is required that the keys implement the [`Eq`](../../cmp/trait.eq "Eq") and [`Hash`](../../hash/trait.hash "Hash") traits, although this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`. If you implement these yourself, it is important that the following property holds:
```
k1 == k2 -> hash(k1) == hash(k2)
```
In other words, if two keys are equal, their hashes must be equal.
It is a logic error for a key to be modified in such a way that the key’s hash, as determined by the [`Hash`](../../hash/trait.hash "Hash") trait, or its equality, as determined by the [`Eq`](../../cmp/trait.eq "Eq") trait, changes while it is in the map. This is normally only possible through [`Cell`](../../cell/struct.cell), [`RefCell`](../../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `HashMap` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
The hash table implementation is a Rust port of Google’s [SwissTable](https://abseil.io/blog/20180927-swisstables). The original C++ version of SwissTable can be found [here](https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h), and this [CppCon talk](https://www.youtube.com/watch?v=ncHmEUmJZf4) gives an overview of how the algorithm works.
Examples
--------
```
use std::collections::HashMap;
// Type inference lets us omit an explicit type signature (which
// would be `HashMap<String, String>` in this example).
let mut book_reviews = HashMap::new();
// Review some books.
book_reviews.insert(
"Adventures of Huckleberry Finn".to_string(),
"My favorite book.".to_string(),
);
book_reviews.insert(
"Grimms' Fairy Tales".to_string(),
"Masterpiece.".to_string(),
);
book_reviews.insert(
"Pride and Prejudice".to_string(),
"Very enjoyable.".to_string(),
);
book_reviews.insert(
"The Adventures of Sherlock Holmes".to_string(),
"Eye lyked it alot.".to_string(),
);
// Check for a specific one.
// When collections store owned values (String), they can still be
// queried using references (&str).
if !book_reviews.contains_key("Les Misérables") {
println!("We've got {} reviews, but Les Misérables ain't one.",
book_reviews.len());
}
// oops, this review has a lot of spelling mistakes, let's delete it.
book_reviews.remove("The Adventures of Sherlock Holmes");
// Look up the values associated with some keys.
let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
for &book in &to_find {
match book_reviews.get(book) {
Some(review) => println!("{book}: {review}"),
None => println!("{book} is unreviewed.")
}
}
// Look up the value for a key (will panic if the key is not found).
println!("Review for Jane: {}", book_reviews["Pride and Prejudice"]);
// Iterate over everything.
for (book, review) in &book_reviews {
println!("{book}: \"{review}\"");
}
```
A `HashMap` with a known list of items can be initialized from an array:
```
use std::collections::HashMap;
let solar_distance = HashMap::from([
("Mercury", 0.4),
("Venus", 0.7),
("Earth", 1.0),
("Mars", 1.5),
]);
```
`HashMap` implements an [`Entry` API](#method.entry), which allows for complex methods of getting, setting, updating and removing keys and their values:
```
use std::collections::HashMap;
// type inference lets us omit an explicit type signature (which
// would be `HashMap<&str, u8>` in this example).
let mut player_stats = HashMap::new();
fn random_stat_buff() -> u8 {
// could actually return some random value here - let's just return
// some fixed value for now
42
}
// insert a key only if it doesn't already exist
player_stats.entry("health").or_insert(100);
// insert a key using a function that provides a new value only if it
// doesn't already exist
player_stats.entry("defence").or_insert_with(random_stat_buff);
// update a key, guarding against the key possibly not being set
let stat = player_stats.entry("attack").or_insert(100);
*stat += random_stat_buff();
// modify an entry before an insert with in-place mutation
player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100);
```
The easiest way to use `HashMap` with a custom key type is to derive [`Eq`](../../cmp/trait.eq "Eq") and [`Hash`](../../hash/trait.hash "Hash"). We must also derive [`PartialEq`](../../cmp/trait.partialeq "PartialEq").
```
use std::collections::HashMap;
#[derive(Hash, Eq, PartialEq, Debug)]
struct Viking {
name: String,
country: String,
}
impl Viking {
/// Creates a new Viking.
fn new(name: &str, country: &str) -> Viking {
Viking { name: name.to_string(), country: country.to_string() }
}
}
// Use a HashMap to store the vikings' health points.
let vikings = HashMap::from([
(Viking::new("Einar", "Norway"), 25),
(Viking::new("Olaf", "Denmark"), 24),
(Viking::new("Harald", "Iceland"), 12),
]);
// Use derived implementation to print the status of the vikings.
for (viking, health) in &vikings {
println!("{viking:?} has {health} hp");
}
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#219-256)### impl<K, V> HashMap<K, V, RandomState>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#234-236)#### pub fn new() -> HashMap<K, V, RandomState>
Creates an empty `HashMap`.
The hash map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, i32> = HashMap::new();
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#253-255)#### pub fn with\_capacity(capacity: usize) -> HashMap<K, V, RandomState>
Creates an empty `HashMap` with at least the specified capacity.
The hash map will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is 0, the hash set will not allocate.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#258-730)### impl<K, V, S> HashMap<K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#284-286)1.7.0 · #### pub fn with\_hasher(hash\_builder: S) -> HashMap<K, V, S>
Creates an empty `HashMap` which will use the given hash builder to hash keys.
The created map has the default initial capacity.
Warning: `hash_builder` is normally randomly generated, and is designed to allow HashMaps to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.
The `hash_builder` passed should implement the [`BuildHasher`](../../hash/trait.buildhasher "BuildHasher") trait for the HashMap to be useful, see its documentation for details.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
let s = RandomState::new();
let mut map = HashMap::with_hasher(s);
map.insert(1, 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#315-317)1.7.0 · #### pub fn with\_capacity\_and\_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty `HashMap` with at least the specified capacity, using `hasher` to hash the keys.
The hash map will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is 0, the hash map will not allocate.
Warning: `hasher` is normally randomly generated, and is designed to allow HashMaps to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.
The `hasher` passed should implement the [`BuildHasher`](../../hash/trait.buildhasher "BuildHasher") trait for the HashMap to be useful, see its documentation for details.
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
let s = RandomState::new();
let mut map = HashMap::with_capacity_and_hasher(10, s);
map.insert(1, 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#333-335)#### pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the `HashMap<K, V>` might be able to hold more, but is guaranteed to be able to hold at least this many.
##### Examples
```
use std::collections::HashMap;
let map: HashMap<i32, i32> = HashMap::with_capacity(100);
assert!(map.capacity() >= 100);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#361-363)#### pub fn keys(&self) -> Keys<'\_, K, V>
Notable traits for [Keys](struct.keys "struct std::collections::hash_map::Keys")<'a, K, V>
```
impl<'a, K, V> Iterator for Keys<'a, K, V>
type Item = &'a K;
```
An iterator visiting all keys in arbitrary order. The iterator element type is `&'a K`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for key in map.keys() {
println!("{key}");
}
```
##### Performance
In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#394-396)1.54.0 · #### pub fn into\_keys(self) -> IntoKeys<K, V>
Notable traits for [IntoKeys](struct.intokeys "struct std::collections::hash_map::IntoKeys")<K, V>
```
impl<K, V> Iterator for IntoKeys<K, V>
type Item = K;
```
Creates a consuming iterator visiting all the keys in arbitrary order. The map cannot be used after calling this. The iterator element type is `K`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
let mut vec: Vec<&str> = map.into_keys().collect();
// The `IntoKeys` iterator produces keys in arbitrary order, so the
// keys must be sorted to test them against a sorted array.
vec.sort_unstable();
assert_eq!(vec, ["a", "b", "c"]);
```
##### Performance
In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#422-424)#### pub fn values(&self) -> Values<'\_, K, V>
Notable traits for [Values](struct.values "struct std::collections::hash_map::Values")<'a, K, V>
```
impl<'a, K, V> Iterator for Values<'a, K, V>
type Item = &'a V;
```
An iterator visiting all values in arbitrary order. The iterator element type is `&'a V`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for val in map.values() {
println!("{val}");
}
```
##### Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#454-456)1.10.0 · #### pub fn values\_mut(&mut self) -> ValuesMut<'\_, K, V>
Notable traits for [ValuesMut](struct.valuesmut "struct std::collections::hash_map::ValuesMut")<'a, K, V>
```
impl<'a, K, V> Iterator for ValuesMut<'a, K, V>
type Item = &'a mut V;
```
An iterator visiting all values mutably in arbitrary order. The iterator element type is `&'a mut V`.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for val in map.values_mut() {
*val = *val + 10;
}
for val in map.values() {
println!("{val}");
}
```
##### Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#487-489)1.54.0 · #### pub fn into\_values(self) -> IntoValues<K, V>
Notable traits for [IntoValues](struct.intovalues "struct std::collections::hash_map::IntoValues")<K, V>
```
impl<K, V> Iterator for IntoValues<K, V>
type Item = V;
```
Creates a consuming iterator visiting all the values in arbitrary order. The map cannot be used after calling this. The iterator element type is `V`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
let mut vec: Vec<i32> = map.into_values().collect();
// The `IntoValues` iterator produces values in arbitrary order, so
// the values must be sorted to test them against a sorted array.
vec.sort_unstable();
assert_eq!(vec, [1, 2, 3]);
```
##### Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#516-518)#### pub fn iter(&self) -> Iter<'\_, K, V>
Notable traits for [Iter](struct.iter "struct std::collections::hash_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>
type Item = (&'a K, &'a V);
```
An iterator visiting all key-value pairs in arbitrary order. The iterator element type is `(&'a K, &'a V)`.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for (key, val) in map.iter() {
println!("key: {key} val: {val}");
}
```
##### Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#551-553)#### pub fn iter\_mut(&mut self) -> IterMut<'\_, K, V>
Notable traits for [IterMut](struct.itermut "struct std::collections::hash_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values. The iterator element type is `(&'a K, &'a mut V)`.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
// Update all values
for (_, val) in map.iter_mut() {
*val *= 2;
}
for (key, val) in &map {
println!("key: {key} val: {val}");
}
```
##### Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#568-570)#### pub fn len(&self) -> usize
Returns the number of elements in the map.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#586-588)#### pub fn is\_empty(&self) -> bool
Returns `true` if the map contains no elements.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#616-618)1.6.0 · #### pub fn drain(&mut self) -> Drain<'\_, K, V>
Notable traits for [Drain](struct.drain "struct std::collections::hash_map::Drain")<'a, K, V>
```
impl<'a, K, V> Iterator for Drain<'a, K, V>
type Item = (K, V);
```
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
If the returned iterator is dropped before being fully consumed, it drops the remaining key-value pairs. The returned iterator keeps a mutable borrow on the map to optimize its implementation.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
a.insert(1, "a");
a.insert(2, "b");
for (k, v) in a.drain().take(1) {
assert!(k == 1 || k == 2);
assert!(v == "a" || v == "b");
}
assert!(a.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#658-663)#### pub fn drain\_filter<F>(&mut self, pred: F) -> DrainFilter<'\_, K, V, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
Notable traits for [DrainFilter](struct.drainfilter "struct std::collections::hash_map::DrainFilter")<'\_, K, V, F>
```
impl<K, V, F> Iterator for DrainFilter<'_, K, V, F>where
F: FnMut(&K, &mut V) -> bool,
type Item = (K, V);
```
🔬This is a nightly-only experimental API. (`hash_drain_filter` [#59618](https://github.com/rust-lang/rust/issues/59618))
Creates an iterator which uses a closure to determine if an element should be removed.
If the closure returns true, the element is removed from the map and yielded. If the closure returns false, or panics, the element remains in the map and will not be yielded.
Note that `drain_filter` lets you mutate every value in the filter closure, regardless of whether you choose to keep or remove it.
If the iterator is only partially consumed or not consumed at all, each of the remaining elements will still be subjected to the closure and removed and dropped if it returns true.
It is unspecified how many more elements will be subjected to the closure if a panic occurs in the closure, or a panic occurs while dropping an element, or if the `DrainFilter` value is leaked.
##### Examples
Splitting a map into even and odd keys, reusing the original map:
```
#![feature(hash_drain_filter)]
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
let drained: HashMap<i32, i32> = map.drain_filter(|k, _v| k % 2 == 0).collect();
let mut evens = drained.keys().copied().collect::<Vec<_>>();
let mut odds = map.keys().copied().collect::<Vec<_>>();
evens.sort();
odds.sort();
assert_eq!(evens, vec![0, 2, 4, 6]);
assert_eq!(odds, vec![1, 3, 5, 7]);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#687-692)1.18.0 · #### pub fn retain<F>(&mut self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)K, [&mut](../../primitive.reference) V) -> [bool](../../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all pairs `(k, v)` for which `f(&k, &mut v)` returns `false`. The elements are visited in unsorted (and unspecified) order.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();
map.retain(|&k, _| k % 2 == 0);
assert_eq!(map.len(), 4);
```
##### Performance
In the current implementation, this operation takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#709-711)#### pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
##### Examples
```
use std::collections::HashMap;
let mut a = HashMap::new();
a.insert(1, "a");
a.clear();
assert!(a.is_empty());
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#727-729)1.9.0 · #### pub fn hasher(&self) -> &S
Returns a reference to the map’s [`BuildHasher`](../../hash/trait.buildhasher "BuildHasher").
##### Examples
```
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
let hasher = RandomState::new();
let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
let hasher: &RandomState = map.hasher();
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#732-1193)### impl<K, V, S> HashMap<K, V, S>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#756-758)#### pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least `additional` more elements to be inserted in the `HashMap`. The collection may reserve more space to speculatively avoid frequent reallocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional`. Does nothing if capacity is already sufficient.
##### Panics
Panics if the new allocation size overflows [`usize`](../../primitive.usize "usize").
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, i32> = HashMap::new();
map.reserve(10);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#782-784)1.57.0 · #### pub fn try\_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least `additional` more elements to be inserted in the `HashMap`. The collection may reserve more space to speculatively avoid frequent reallocations. After calling `reserve`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if capacity is already sufficient.
##### Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<&str, isize> = HashMap::new();
map.try_reserve(10).expect("why is the test harness OOMing on a handful of bytes?");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#804-806)#### pub fn shrink\_to\_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
map.insert(1, 2);
map.insert(3, 4);
assert!(map.capacity() >= 100);
map.shrink_to_fit();
assert!(map.capacity() >= 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#830-832)1.56.0 · #### pub fn shrink\_to(&mut self, min\_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop down no lower than the supplied limit while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
If the current capacity is less than the lower limit, this is a no-op.
##### Examples
```
use std::collections::HashMap;
let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
map.insert(1, 2);
map.insert(3, 4);
assert!(map.capacity() >= 100);
map.shrink_to(10);
assert!(map.capacity() >= 10);
map.shrink_to(0);
assert!(map.capacity() >= 2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#854-856)#### pub fn entry(&mut self, key: K) -> Entry<'\_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
##### Examples
```
use std::collections::HashMap;
let mut letters = HashMap::new();
for ch in "a short treatise on fungi".chars() {
letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);
}
assert_eq!(letters[&'s'], 2);
assert_eq!(letters[&'t'], 3);
assert_eq!(letters[&'u'], 1);
assert_eq!(letters.get(&'y'), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#876-882)#### pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but [`Hash`](../../hash/trait.hash "Hash") and [`Eq`](../../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#902-908)1.40.0 · #### pub fn get\_key\_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but [`Hash`](../../hash/trait.hash "Hash") and [`Eq`](../../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#956-962)#### pub fn get\_many\_mut<Q: ?Sized, const N: usize>( &mut self, ks: [&Q; N]) -> Option<[&mut V; N]>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`map_many_mut` [#97601](https://github.com/rust-lang/rust/issues/97601))
Attempts to get mutable references to `N` values in the map at once.
Returns an array of length `N` with the results of each query. For soundness, at most one mutable reference will be returned to any value. `None` will be returned if any of the keys are duplicates or missing.
##### Examples
```
#![feature(map_many_mut)]
use std::collections::HashMap;
let mut libraries = HashMap::new();
libraries.insert("Bodleian Library".to_string(), 1602);
libraries.insert("Athenæum".to_string(), 1807);
libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
libraries.insert("Library of Congress".to_string(), 1800);
let got = libraries.get_many_mut([
"Athenæum",
"Library of Congress",
]);
assert_eq!(
got,
Some([
&mut 1807,
&mut 1800,
]),
);
// Missing keys result in None
let got = libraries.get_many_mut([
"Athenæum",
"New York Public Library",
]);
assert_eq!(got, None);
// Duplicate keys result in None
let got = libraries.get_many_mut([
"Athenæum",
"Athenæum",
]);
assert_eq!(got, None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1012-1021)#### pub unsafe fn get\_many\_unchecked\_mut<Q: ?Sized, const N: usize>( &mut self, ks: [&Q; N]) -> Option<[&mut V; N]>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
🔬This is a nightly-only experimental API. (`map_many_mut` [#97601](https://github.com/rust-lang/rust/issues/97601))
Attempts to get mutable references to `N` values in the map at once, without validating that the values are unique.
Returns an array of length `N` with the results of each query. `None` will be returned if any of the keys are missing.
For a safe alternative see [`get_many_mut`](struct.hashmap#method.get_many_mut).
##### Safety
Calling this method with overlapping keys is *[undefined behavior](../../../reference/behavior-considered-undefined)* even if the resulting references are not used.
##### Examples
```
#![feature(map_many_mut)]
use std::collections::HashMap;
let mut libraries = HashMap::new();
libraries.insert("Bodleian Library".to_string(), 1602);
libraries.insert("Athenæum".to_string(), 1807);
libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
libraries.insert("Library of Congress".to_string(), 1800);
let got = libraries.get_many_mut([
"Athenæum",
"Library of Congress",
]);
assert_eq!(
got,
Some([
&mut 1807,
&mut 1800,
]),
);
// Missing keys result in None
let got = libraries.get_many_mut([
"Athenæum",
"New York Public Library",
]);
assert_eq!(got, None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1041-1047)#### pub fn contains\_key<Q: ?Sized>(&self, k: &Q) -> boolwhere K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
Returns `true` if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but [`Hash`](../../hash/trait.hash "Hash") and [`Eq`](../../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1069-1075)#### pub fn get\_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but [`Hash`](../../hash/trait.hash "Hash") and [`Eq`](../../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
if let Some(x) = map.get_mut(&1) {
*x = "b";
}
assert_eq!(map[&1], "b");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1103-1105)#### pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
If the map did not have this key present, [`None`](../../option/enum.option#variant.None "None") is returned.
If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be `==` without being identical. See the [module-level documentation](../index#insert-and-complex-keys) for more.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);
map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1131-1136)#### pub fn try\_insert( &mut self, key: K, value: V) -> Result<&mut V, OccupiedError<'\_, K, V>>
🔬This is a nightly-only experimental API. (`map_try_insert` [#82766](https://github.com/rust-lang/rust/issues/82766))
Tries to insert a key-value pair into the map, and returns a mutable reference to the value in the entry.
If the map already had this key present, nothing is updated, and an error containing the occupied entry and the value is returned.
##### Examples
Basic usage:
```
#![feature(map_try_insert)]
use std::collections::HashMap;
let mut map = HashMap::new();
assert_eq!(map.try_insert(37, "a").unwrap(), &"a");
let err = map.try_insert(37, "b").unwrap_err();
assert_eq!(err.entry.key(), &37);
assert_eq!(err.entry.get(), &"a");
assert_eq!(err.value, "b");
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1157-1163)#### pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but [`Hash`](../../hash/trait.hash "Hash") and [`Eq`](../../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1186-1192)1.27.0 · #### pub fn remove\_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(K, V)>where K: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Eq](../../cmp/trait.eq "trait std::cmp::Eq"),
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but [`Hash`](../../hash/trait.hash "Hash") and [`Eq`](../../cmp/trait.eq "Eq") on the borrowed form *must* match those for the key type.
##### Examples
```
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove_entry(&1), Some((1, "a")));
assert_eq!(map.remove(&1), None);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1195-1256)### impl<K, V, S> HashMap<K, V, S>where S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1232-1234)#### pub fn raw\_entry\_mut(&mut self) -> RawEntryBuilderMut<'\_, K, V, S>
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Creates a raw entry builder for the HashMap.
Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched. After this, insertions into a vacant entry still require an owned key to be provided.
Raw entries are useful for such exotic situations as:
* Hash memoization
* Deferring the creation of an owned key until it is known to be required
* Using a search key that doesn’t work with the Borrow trait
* Using custom comparison logic without newtype wrappers
Because raw entries provide much more low-level control, it’s much easier to put the HashMap into an inconsistent state which, while memory-safe, will cause the map to produce seemingly random results. Higher-level and more foolproof APIs like `entry` should be preferred when possible.
In particular, the hash used to initialized the raw entry must still be consistent with the hash of the key that is ultimately stored in the entry. This is because implementations of HashMap may need to recompute hashes when resizing, at which point only the keys are available.
Raw entries give mutable access to the keys. This must not be used to modify how the key would compare or hash, as the map will not re-evaluate where the key should go, meaning the keys may become “lost” if their location does not reflect their state. For instance, if you change a key so that the map now contains keys which compare equal, search may start acting erratically, with two keys randomly masking each other. Implementations are free to assume this doesn’t happen (within the limits of memory-safety).
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1253-1255)#### pub fn raw\_entry(&self) -> RawEntryBuilder<'\_, K, V, S>
🔬This is a nightly-only experimental API. (`hash_raw_entry` [#56167](https://github.com/rust-lang/rust/issues/56167))
Creates a raw immutable entry builder for the HashMap.
Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched.
This is useful for
* Hash memoization
* Using a search key that doesn’t work with the Borrow trait
* Using custom comparison logic without newtype wrappers
Unless you are in such a situation, higher-level and more foolproof APIs like `get` should be preferred.
Immutable raw entries have very limited use; you might instead want `raw_entry_mut`.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1259-1274)### impl<K, V, S> Clone for HashMap<K, V, S>where K: [Clone](../../clone/trait.clone "trait std::clone::Clone"), V: [Clone](../../clone/trait.clone "trait std::clone::Clone"), S: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1266-1268)#### fn clone(&self) -> Self
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1271-1273)#### fn clone\_from(&mut self, other: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1302-1310)### impl<K, V, S> Debug for HashMap<K, V, S>where K: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), V: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1307-1309)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1313-1322)### impl<K, V, S> Default for HashMap<K, V, S>where S: [Default](../../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1319-1321)#### fn default() -> HashMap<K, V, S>
Creates an empty `HashMap<K, V, S>`, with the `Default` value for the hasher.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3053-3073)1.4.0 · ### impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Copy](../../marker/trait.copy "trait std::marker::Copy"), V: [Copy](../../marker/trait.copy "trait std::marker::Copy"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3060-3062)#### fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. [Read more](../../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3065-3067)#### fn extend\_one(&mut self, (k, v): (&'a K, &'a V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3070-3072)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3031-3050)### impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
Inserts all new key-values from the iterator and replaces values with existing keys with new values returned from the iterator.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3037-3039)#### fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. [Read more](../../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3042-3044)#### fn extend\_one(&mut self, (k, v): (K, V))
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3047-3049)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1357-1373)1.56.0 · ### impl<K, V, const N: usize> From<[(K, V); N]> for HashMap<K, V, RandomState>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1370-1372)#### fn from(arr: [(K, V); N]) -> Self
##### Examples
```
use std::collections::HashMap;
let map1 = HashMap::from([(1, 2), (3, 4)]);
let map2: HashMap<_, _> = [(1, 2), (3, 4)].into();
assert_eq!(map1, map2);
```
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3016-3026)### impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher") + [Default](../../default/trait.default "trait std::default::Default"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3021-3025)#### fn from\_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> HashMap<K, V, S>
Creates a value from an iterator. [Read more](../../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1325-1342)### impl<K, Q: ?Sized, V, S> Index<&Q> for HashMap<K, V, S>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash") + [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q>, Q: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1339-1341)#### fn index(&self, key: &Q) -> &V
Returns a reference to the value corresponding to the supplied key.
##### Panics
Panics if the key is not present in the `HashMap`.
#### type Output = V
The returned type after indexing.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2173-2182)### impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S>
#### type Item = (&'a K, &'a V)
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2179-2181)#### fn into\_iter(self) -> Iter<'a, K, V>
Notable traits for [Iter](struct.iter "struct std::collections::hash_map::Iter")<'a, K, V>
```
impl<'a, K, V> Iterator for Iter<'a, K, V>
type Item = (&'a K, &'a V);
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2185-2194)### impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S>
#### type Item = (&'a K, &'a mut V)
The type of the elements being iterated over.
#### type IntoIter = IterMut<'a, K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2191-2193)#### fn into\_iter(self) -> IterMut<'a, K, V>
Notable traits for [IterMut](struct.itermut "struct std::collections::hash_map::IterMut")<'a, K, V>
```
impl<'a, K, V> Iterator for IterMut<'a, K, V>
type Item = (&'a K, &'a mut V);
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2197-2224)### impl<K, V, S> IntoIterator for HashMap<K, V, S>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2221-2223)#### fn into\_iter(self) -> IntoIter<K, V>
Notable traits for [IntoIter](struct.intoiter "struct std::collections::hash_map::IntoIter")<K, V>
```
impl<K, V> Iterator for IntoIter<K, V>
type Item = (K, V);
```
Creates a consuming iterator, that is, one that moves each key-value pair out of the map in arbitrary order. The map cannot be used after calling this.
##### Examples
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
// Not possible with .iter()
let vec: Vec<(&str, i32)> = map.into_iter().collect();
```
#### type Item = (K, V)
The type of the elements being iterated over.
#### type IntoIter = IntoIter<K, V>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1277-1290)### impl<K, V, S> PartialEq<HashMap<K, V, S>> for HashMap<K, V, S>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash"), V: [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1283-1289)#### fn eq(&self, other: &HashMap<K, V, S>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1293-1299)### impl<K, V, S> Eq for HashMap<K, V, S>where K: [Eq](../../cmp/trait.eq "trait std::cmp::Eq") + [Hash](../../hash/trait.hash "trait std::hash::Hash"), V: [Eq](../../cmp/trait.eq "trait std::cmp::Eq"), S: [BuildHasher](../../hash/trait.buildhasher "trait std::hash::BuildHasher"),
[source](https://doc.rust-lang.org/src/std/panic.rs.html#76-82)1.36.0 · ### impl<K, V, S> UnwindSafe for HashMap<K, V, S>where K: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), V: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), S: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"),
Auto Trait Implementations
--------------------------
### impl<K, V, S> RefUnwindSafe for HashMap<K, V, S>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), S: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<K, V, S> Send for HashMap<K, V, S>where K: [Send](../../marker/trait.send "trait std::marker::Send"), S: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<K, V, S> Sync for HashMap<K, V, S>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), S: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<K, V, S> Unpin for HashMap<K, V, S>where K: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), S: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), V: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::ValuesMut Struct std::collections::hash\_map::ValuesMut
=============================================
```
pub struct ValuesMut<'a, K: 'a, V: 'a> { /* private fields */ }
```
A mutable iterator over the values of a `HashMap`.
This `struct` is created by the [`values_mut`](struct.hashmap#method.values_mut) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let mut map = HashMap::from([
("a", 1),
]);
let iter_values = map.values_mut();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2384-2388)1.16.0 · ### impl<K, V: Debug> Debug for ValuesMut<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2385-2387)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2374-2379)### impl<K, V> ExactSizeIterator for ValuesMut<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2376-2378)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2361-2372)### impl<'a, K, V> Iterator for ValuesMut<'a, K, V>
#### type Item = &'a mut V
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2365-2367)#### fn next(&mut self) -> Option<&'a mut V>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2369-2371)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2381)1.26.0 · ### impl<K, V> FusedIterator for ValuesMut<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for ValuesMut<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for ValuesMut<'a, K, V>where K: [Send](../../marker/trait.send "trait std::marker::Send"), V: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, K, V> Sync for ValuesMut<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for ValuesMut<'a, K, V>
### impl<'a, K, V> !UnwindSafe for ValuesMut<'a, K, V>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::Iter Struct std::collections::hash\_map::Iter
========================================
```
pub struct Iter<'a, K: 'a, V: 'a> { /* private fields */ }
```
An iterator over the entries of a `HashMap`.
This `struct` is created by the [`iter`](struct.hashmap#method.iter) method on [`HashMap`](struct.hashmap "HashMap"). See its documentation for more.
Example
-------
```
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
]);
let iter = map.iter();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1399-1404)### impl<K, V> Clone for Iter<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1401-1403)#### fn clone(&self) -> Self
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1407-1411)1.16.0 · ### impl<K: Debug, V: Debug> Debug for Iter<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#1408-1410)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2240-2245)### impl<K, V> ExactSizeIterator for Iter<'\_, K, V>
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2242-2244)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2227-2238)### impl<'a, K, V> Iterator for Iter<'a, K, V>
#### type Item = (&'a K, &'a V)
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2231-2233)#### fn next(&mut self) -> Option<(&'a K, &'a V)>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2235-2237)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#2248)1.26.0 · ### impl<K, V> FusedIterator for Iter<'\_, K, V>
Auto Trait Implementations
--------------------------
### impl<'a, K, V> RefUnwindSafe for Iter<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, K, V> Send for Iter<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Sync for Iter<'a, K, V>where K: [Sync](../../marker/trait.sync "trait std::marker::Sync"), V: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, K, V> Unpin for Iter<'a, K, V>
### impl<'a, K, V> UnwindSafe for Iter<'a, K, V>where K: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), V: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::hash_map::RandomState Struct std::collections::hash\_map::RandomState
===============================================
```
pub struct RandomState { /* private fields */ }
```
`RandomState` is the default state for [`HashMap`](struct.hashmap "HashMap") types.
A particular instance `RandomState` will create the same instances of [`Hasher`](../../hash/trait.hasher "Hasher"), but the hashers created by two different `RandomState` instances are unlikely to produce the same result for the same values.
Examples
--------
```
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
let s = RandomState::new();
let mut map = HashMap::with_hasher(s);
map.insert(1, 2);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3098-3135)### impl RandomState
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3113-3134)#### pub fn new() -> RandomState
Constructs a new `RandomState` that is initialized with random keys.
##### Examples
```
use std::collections::hash_map::RandomState;
let s = RandomState::new();
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3138-3145)### impl BuildHasher for RandomState
#### type Hasher = DefaultHasher
Type of the hasher that will be created.
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3142-3144)#### fn build\_hasher(&self) -> DefaultHasher
Creates a new hasher. [Read more](../../hash/trait.buildhasher#tymethod.build_hasher)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#701-703)#### fn hash\_one<T>(&self, x: T) -> u64where T: [Hash](../../hash/trait.hash "trait std::hash::Hash"),
🔬This is a nightly-only experimental API. (`build_hasher_simple_hash_one` [#86161](https://github.com/rust-lang/rust/issues/86161))
Calculates the hash of a single value. [Read more](../../hash/trait.buildhasher#method.hash_one)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3091)### impl Clone for RandomState
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3091)#### fn clone(&self) -> RandomState
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3214-3218)1.16.0 · ### impl Debug for RandomState
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3215-3217)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3205-3211)### impl Default for RandomState
[source](https://doc.rust-lang.org/src/std/collections/hash/map.rs.html#3208-3210)#### fn default() -> RandomState
Constructs a new `RandomState`.
Auto Trait Implementations
--------------------------
### impl RefUnwindSafe for RandomState
### impl Send for RandomState
### impl Sync for RandomState
### impl Unpin for RandomState
### impl UnwindSafe for RandomState
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
rust Module std::collections::btree_set Module std::collections::btree\_set
===================================
An ordered set based on a B-Tree.
Structs
-------
[DrainFilter](struct.drainfilter "std::collections::btree_set::DrainFilter struct")Experimental
An iterator produced by calling `drain_filter` on BTreeSet.
[BTreeSet](struct.btreeset "std::collections::btree_set::BTreeSet struct")
An ordered set based on a B-Tree.
[Difference](struct.difference "std::collections::btree_set::Difference struct")
A lazy iterator producing elements in the difference of `BTreeSet`s.
[Intersection](struct.intersection "std::collections::btree_set::Intersection struct")
A lazy iterator producing elements in the intersection of `BTreeSet`s.
[IntoIter](struct.intoiter "std::collections::btree_set::IntoIter struct")
An owning iterator over the items of a `BTreeSet`.
[Iter](struct.iter "std::collections::btree_set::Iter struct")
An iterator over the items of a `BTreeSet`.
[Range](struct.range "std::collections::btree_set::Range struct")
An iterator over a sub-range of items in a `BTreeSet`.
[SymmetricDifference](struct.symmetricdifference "std::collections::btree_set::SymmetricDifference struct")
A lazy iterator producing elements in the symmetric difference of `BTreeSet`s.
[Union](struct.union "std::collections::btree_set::Union struct")
A lazy iterator producing elements in the union of `BTreeSet`s.
rust Struct std::collections::btree_set::Union Struct std::collections::btree\_set::Union
==========================================
```
pub struct Union<'a, T>(_)where T: 'a;
```
A lazy iterator producing elements in the union of `BTreeSet`s.
This `struct` is created by the [`union`](../struct.btreeset#method.union) method on [`BTreeSet`](../struct.btreeset "BTreeSet"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1760)### impl<T> Clone for Union<'\_, T>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1761)#### fn clone(&self) -> Union<'\_, T>
Notable traits for [Union](struct.union "struct std::collections::btree_set::Union")<'a, T>
```
impl<'a, T> Iterator for Union<'a, T>where
T: Ord,
type Item = &'a T;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#318)1.17.0 · ### impl<T> Debug for Union<'\_, T>where T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#319)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1766)### impl<'a, T> Iterator for Union<'a, T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
#### type Item = &'a T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1769)#### fn next(&mut self) -> Option<&'a T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1774)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1780)#### fn min(self) -> Option<&'a T>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1786)1.26.0 · ### impl<T> FusedIterator for Union<'\_, T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Auto Trait Implementations
--------------------------
### impl<'a, T> RefUnwindSafe for Union<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T> Send for Union<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for Union<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Unpin for Union<'a, T>
### impl<'a, T> UnwindSafe for Union<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::BTreeSet Struct std::collections::btree\_set::BTreeSet
=============================================
```
pub struct BTreeSet<T, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An ordered set based on a B-Tree.
See [`BTreeMap`](../struct.btreemap "BTreeMap")’s documentation for a detailed discussion of this collection’s performance benefits and drawbacks.
It is a logic error for an item to be modified in such a way that the item’s ordering relative to any other item, as determined by the [`Ord`](../../cmp/trait.ord) trait, changes while it is in the set. This is normally only possible through [`Cell`](../../cell/struct.cell), [`RefCell`](../../cell/struct.refcell), global state, I/O, or unsafe code. The behavior resulting from such a logic error is not specified, but will be encapsulated to the `BTreeSet` that observed the logic error and not result in undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and non-termination.
Iterators returned by [`BTreeSet::iter`](../struct.btreeset#method.iter "BTreeSet::iter") produce their items in order, and take worst-case logarithmic and amortized constant time per item returned.
Examples
--------
```
use std::collections::BTreeSet;
// Type inference lets us omit an explicit type signature (which
// would be `BTreeSet<&str>` in this example).
let mut books = BTreeSet::new();
// Add some books.
books.insert("A Dance With Dragons");
books.insert("To Kill a Mockingbird");
books.insert("The Odyssey");
books.insert("The Great Gatsby");
// Check for a specific one.
if !books.contains("The Winds of Winter") {
println!("We have {} books, but The Winds of Winter ain't one.",
books.len());
}
// Remove a book.
books.remove("The Odyssey");
// Iterate over everything.
for book in &books {
println!("{book}");
}
```
A `BTreeSet` with a known list of items can be initialized from an array:
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
```
Implementations
---------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#332)### impl<T> BTreeSet<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#348)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn new() -> BTreeSet<T, Global>
Makes a new, empty `BTreeSet`.
Does not allocate anything on its own.
##### Examples
```
use std::collections::BTreeSet;
let mut set: BTreeSet<i32> = BTreeSet::new();
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#353)### impl<T, A> BTreeSet<T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#368)#### pub fn new\_in(alloc: A) -> BTreeSet<T, A>
🔬This is a nightly-only experimental API. (`btreemap_alloc` [#32838](https://github.com/rust-lang/rust/issues/32838))
Makes a new `BTreeSet` with a reasonable choice of B.
##### Examples
```
use std::collections::BTreeSet;
use std::alloc::Global;
let mut set: BTreeSet<i32> = BTreeSet::new_in(Global);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#400-404)1.17.0 · #### pub fn range<K, R>(&self, range: R) -> Range<'\_, T>where K: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"), T: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<K> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), R: [RangeBounds](../../ops/trait.rangebounds "trait std::ops::RangeBounds")<K>,
Notable traits for [Range](struct.range "struct std::collections::btree_set::Range")<'a, T>
```
impl<'a, T> Iterator for Range<'a, T>
type Item = &'a T;
```
Constructs a double-ended iterator over a sub-range of elements in the set. The simplest way is to use the range syntax `min..max`, thus `range(min..max)` will yield elements from min (inclusive) to max (exclusive). The range may also be entered as `(Bound<T>, Bound<T>)`, so for example `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive range from 4 to 10.
##### Panics
Panics if range `start > end`. Panics if range `start == end` and both bounds are `Excluded`.
##### Examples
```
use std::collections::BTreeSet;
use std::ops::Bound::Included;
let mut set = BTreeSet::new();
set.insert(3);
set.insert(5);
set.insert(8);
for &elem in set.range((Included(&4), Included(&8))) {
println!("{elem}");
}
assert_eq!(Some(&5), set.range(4..).next());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#430-432)#### pub fn difference(&'a self, other: &'a BTreeSet<T, A>) -> Difference<'a, T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [Difference](struct.difference "struct std::collections::btree_set::Difference")<'a, T, A>
```
impl<'a, T, A> Iterator for Difference<'a, T, A>where
T: Ord,
A: Allocator + Clone,
type Item = &'a T;
```
Visits the elements representing the difference, i.e., the elements that are in `self` but not in `other`, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let diff: Vec<_> = a.difference(&b).cloned().collect();
assert_eq!(diff, [1]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#491-496)#### pub fn symmetric\_difference( &'a self, other: &'a BTreeSet<T, A>) -> SymmetricDifference<'a, T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [SymmetricDifference](struct.symmetricdifference "struct std::collections::btree_set::SymmetricDifference")<'a, T>
```
impl<'a, T> Iterator for SymmetricDifference<'a, T>where
T: Ord,
type Item = &'a T;
```
Visits the elements representing the symmetric difference, i.e., the elements that are in `self` or in `other` but not in both, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let sym_diff: Vec<_> = a.symmetric_difference(&b).cloned().collect();
assert_eq!(sym_diff, [1, 3]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#522-524)#### pub fn intersection( &'a self, other: &'a BTreeSet<T, A>) -> Intersection<'a, T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [Intersection](struct.intersection "struct std::collections::btree_set::Intersection")<'a, T, A>
```
impl<'a, T, A> Iterator for Intersection<'a, T, A>where
T: Ord,
A: Allocator + Clone,
type Item = &'a T;
```
Visits the elements representing the intersection, i.e., the elements that are both in `self` and `other`, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
let mut b = BTreeSet::new();
b.insert(2);
b.insert(3);
let intersection: Vec<_> = a.intersection(&b).cloned().collect();
assert_eq!(intersection, [2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#573-575)#### pub fn union(&'a self, other: &'a BTreeSet<T, A>) -> Union<'a, T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Notable traits for [Union](struct.union "struct std::collections::btree_set::Union")<'a, T>
```
impl<'a, T> Iterator for Union<'a, T>where
T: Ord,
type Item = &'a T;
```
Visits the elements representing the union, i.e., all the elements in `self` or `other`, without duplicates, in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
let mut b = BTreeSet::new();
b.insert(2);
let union: Vec<_> = a.union(&b).cloned().collect();
assert_eq!(union, [1, 2]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#593-595)#### pub fn clear(&mut self)where A: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Clears the set, removing all elements.
##### Examples
```
use std::collections::BTreeSet;
let mut v = BTreeSet::new();
v.insert(1);
v.clear();
assert!(v.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#616-619)#### pub fn contains<Q>(&self, value: &Q) -> boolwhere T: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Returns `true` if the set contains an element equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#641-644)1.9.0 · #### pub fn get<Q>(&self, value: &Q) -> Option<&T>where T: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Returns a reference to the element in the set, if any, that is equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.get(&2), Some(&2));
assert_eq!(set.get(&4), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#668-670)#### pub fn is\_disjoint(&self, other: &BTreeSet<T, A>) -> boolwhere T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Returns `true` if `self` has no elements in common with `other`. This is equivalent to checking for an empty intersection.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let mut b = BTreeSet::new();
assert_eq!(a.is_disjoint(&b), true);
b.insert(4);
assert_eq!(a.is_disjoint(&b), true);
b.insert(1);
assert_eq!(a.is_disjoint(&b), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#694-696)#### pub fn is\_subset(&self, other: &BTreeSet<T, A>) -> boolwhere T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Returns `true` if the set is a subset of another, i.e., `other` contains at least all the elements in `self`.
##### Examples
```
use std::collections::BTreeSet;
let sup = BTreeSet::from([1, 2, 3]);
let mut set = BTreeSet::new();
assert_eq!(set.is_subset(&sup), true);
set.insert(2);
assert_eq!(set.is_subset(&sup), true);
set.insert(4);
assert_eq!(set.is_subset(&sup), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#774-776)#### pub fn is\_superset(&self, other: &BTreeSet<T, A>) -> boolwhere T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Returns `true` if the set is a superset of another, i.e., `self` contains at least all the elements in `other`.
##### Examples
```
use std::collections::BTreeSet;
let sub = BTreeSet::from([1, 2]);
let mut set = BTreeSet::new();
assert_eq!(set.is_superset(&sub), false);
set.insert(0);
set.insert(1);
assert_eq!(set.is_superset(&sub), false);
set.insert(2);
assert_eq!(set.is_superset(&sub), true);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#801-803)#### pub fn first(&self) -> Option<&T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns a reference to the first element in the set, if any. This element is always the minimum of all elements in the set.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.first(), None);
set.insert(1);
assert_eq!(set.first(), Some(&1));
set.insert(2);
assert_eq!(set.first(), Some(&1));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#828-830)#### pub fn last(&self) -> Option<&T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Returns a reference to the last element in the set, if any. This element is always the maximum of all elements in the set.
##### Examples
Basic usage:
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.last(), None);
set.insert(1);
assert_eq!(set.last(), Some(&1));
set.insert(2);
assert_eq!(set.last(), Some(&2));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#853-855)#### pub fn pop\_first(&mut self) -> Option<T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes the first element from the set and returns it, if any. The first element is always the minimum element in the set.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(1);
while let Some(n) = set.pop_first() {
assert_eq!(n, 1);
}
assert!(set.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#878-880)#### pub fn pop\_last(&mut self) -> Option<T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
🔬This is a nightly-only experimental API. (`map_first_last` [#62924](https://github.com/rust-lang/rust/issues/62924))
Removes the last element from the set and returns it, if any. The last element is always the maximum element in the set.
##### Examples
```
#![feature(map_first_last)]
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(1);
while let Some(n) = set.pop_last() {
assert_eq!(n, 1);
}
assert!(set.is_empty());
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#910-912)#### pub fn insert(&mut self, value: T) -> boolwhere T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Adds a value to the set.
Returns whether the value was newly inserted. That is:
* If the set did not previously contain an equal value, `true` is returned.
* If the set already contained an equal value, `false` is returned, and the entry is not updated.
See the [module-level documentation](index#insert-and-complex-keys) for more.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
assert_eq!(set.insert(2), true);
assert_eq!(set.insert(2), false);
assert_eq!(set.len(), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#933-935)1.9.0 · #### pub fn replace(&mut self, value: T) -> Option<T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Adds a value to the set, replacing the existing element, if any, that is equal to the value. Returns the replaced element.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(Vec::<i32>::new());
assert_eq!(set.get(&[][..]).unwrap().capacity(), 0);
set.replace(Vec::with_capacity(10));
assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#959-962)#### pub fn remove<Q>(&mut self, value: &Q) -> boolwhere T: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
If the set contains an element equal to the value, removes it from the set and drops it. Returns whether such an element was present.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::new();
set.insert(2);
assert_eq!(set.remove(&2), true);
assert_eq!(set.remove(&2), false);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#984-987)1.9.0 · #### pub fn take<Q>(&mut self, value: &Q) -> Option<T>where T: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
Removes and returns the element in the set, if any, that is equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form *must* match the ordering on the element type.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.take(&2), Some(2));
assert_eq!(set.take(&2), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1008-1011)1.53.0 · #### pub fn retain<F>(&mut self, f: F)where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
Retains only the elements specified by the predicate.
In other words, remove all elements `e` for which `f(&e)` returns `false`. The elements are visited in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let mut set = BTreeSet::from([1, 2, 3, 4, 5, 6]);
// Keep only the even numbers.
set.retain(|&k| k % 2 == 0);
assert!(set.iter().eq([2, 4, 6].iter()));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1045-1048)1.11.0 · #### pub fn append(&mut self, other: &mut BTreeSet<T, A>)where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Moves all elements from `other` into `self`, leaving `other` empty.
##### Examples
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
let mut b = BTreeSet::new();
b.insert(3);
b.insert(4);
b.insert(5);
a.append(&mut b);
assert_eq!(a.len(), 5);
assert_eq!(b.len(), 0);
assert!(a.contains(&1));
assert!(a.contains(&2));
assert!(a.contains(&3));
assert!(a.contains(&4));
assert!(a.contains(&5));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1083-1086)1.11.0 · #### pub fn split\_off<Q>(&mut self, value: &Q) -> BTreeSet<T, A>where Q: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"), T: [Borrow](../../borrow/trait.borrow "trait std::borrow::Borrow")<Q> + [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Splits the collection into two at the value. Returns a new collection with all elements greater than or equal to the value.
##### Examples
Basic usage:
```
use std::collections::BTreeSet;
let mut a = BTreeSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(17);
a.insert(41);
let b = a.split_off(&3);
assert_eq!(a.len(), 2);
assert_eq!(b.len(), 3);
assert!(a.contains(&1));
assert!(a.contains(&2));
assert!(b.contains(&3));
assert!(b.contains(&17));
assert!(b.contains(&41));
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1121-1124)#### pub fn drain\_filter<'a, F>(&'a mut self, pred: F) -> DrainFilter<'a, T, F, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: 'a + [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
Notable traits for [DrainFilter](struct.drainfilter "struct std::collections::btree_set::DrainFilter")<'\_, T, F, A>
```
impl<'a, T, F, A> Iterator for DrainFilter<'_, T, F, A>where
A: Allocator + Clone,
F: 'a + FnMut(&T) -> bool,
type Item = T;
```
🔬This is a nightly-only experimental API. (`btree_drain_filter` [#70530](https://github.com/rust-lang/rust/issues/70530))
Creates an iterator that visits all elements in ascending order and uses a closure to determine if an element should be removed.
If the closure returns `true`, the element is removed from the set and yielded. If the closure returns `false`, or panics, the element remains in the set and will not be yielded.
If the iterator is only partially consumed or not consumed at all, each of the remaining elements is still subjected to the closure and removed and dropped if it returns `true`.
It is unspecified how many more elements will be subjected to the closure if a panic occurs in the closure, or if a panic occurs while dropping an element, or if the `DrainFilter` itself is leaked.
##### Examples
Splitting a set into even and odd values, reusing the original set:
```
#![feature(btree_drain_filter)]
use std::collections::BTreeSet;
let mut set: BTreeSet<i32> = (0..8).collect();
let evens: BTreeSet<_> = set.drain_filter(|v| v % 2 == 0).collect();
let odds = set;
assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![0, 2, 4, 6]);
assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 7]);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1159)#### pub fn iter(&self) -> Iter<'\_, T>
Notable traits for [Iter](struct.iter "struct std::collections::btree_set::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Gets an iterator that visits the elements in the `BTreeSet` in ascending order.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(&1));
assert_eq!(set_iter.next(), Some(&2));
assert_eq!(set_iter.next(), Some(&3));
assert_eq!(set_iter.next(), None);
```
Values returned by the iterator are returned in ascending order:
```
use std::collections::BTreeSet;
let set = BTreeSet::from([3, 1, 2]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(&1));
assert_eq!(set_iter.next(), Some(&2));
assert_eq!(set_iter.next(), Some(&3));
assert_eq!(set_iter.next(), None);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1178)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn len(&self) -> usize
Returns the number of elements in the set.
##### Examples
```
use std::collections::BTreeSet;
let mut v = BTreeSet::new();
assert_eq!(v.len(), 0);
v.insert(1);
assert_eq!(v.len(), 1);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1197)const: [unstable](https://github.com/rust-lang/rust/issues/71835 "Tracking issue for const_btree_new") · #### pub fn is\_empty(&self) -> bool
Returns `true` if the set contains no elements.
##### Examples
```
use std::collections::BTreeSet;
let mut v = BTreeSet::new();
assert!(v.is_empty());
v.insert(1);
assert!(!v.is_empty());
```
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1429)### impl<T, A> BitAnd<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1445)#### fn bitand(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the intersection of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([2, 3, 4]);
let result = &a & &b;
assert_eq!(result, BTreeSet::from([2, 3]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `&` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1454)### impl<T, A> BitOr<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1470)#### fn bitor(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the union of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([3, 4, 5]);
let result = &a | &b;
assert_eq!(result, BTreeSet::from([1, 2, 3, 4, 5]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `|` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1404)### impl<T, A> BitXor<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1420)#### fn bitxor(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([2, 3, 4]);
let result = &a ^ &b;
assert_eq!(result, BTreeSet::from([1, 4]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `^` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#120)### impl<T, A> Clone for BTreeSet<T, A>where T: [Clone](../../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#121)#### fn clone(&self) -> BTreeSet<T, A>
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#125)#### fn clone\_from(&mut self, other: &BTreeSet<T, A>)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1479)### impl<T, A> Debug for BTreeSet<T, A>where T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1480)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1371)### impl<T> Default for BTreeSet<T, Global>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1373)#### fn default() -> BTreeSet<T, Global>
Creates an empty `BTreeSet`.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1359)1.2.0 · ### impl<'a, T, A> Extend<&'a T> for BTreeSet<T, A>where T: 'a + [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + [Copy](../../marker/trait.copy "trait std::marker::Copy"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1360)#### fn extend<I>(&mut self, iter: I)where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = [&'a](../../primitive.reference) T>,
Extends a collection with the contents of an iterator. [Read more](../../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1365)#### fn extend\_one(&mut self, &'a T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1344)### impl<T, A> Extend<T> for BTreeSet<T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1346)#### fn extend<Iter>(&mut self, iter: Iter)where Iter: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Extends a collection with the contents of an iterator. [Read more](../../iter/trait.extend#tymethod.extend)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1353)#### fn extend\_one(&mut self, elem: T)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Extends a collection with exactly one element.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#379)#### fn extend\_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (`extend_one` [#72631](https://github.com/rust-lang/rust/issues/72631))
Reserves capacity in a collection for the given number of additional elements. [Read more](../../iter/trait.extend#method.extend_reserve)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1226)1.56.0 · ### impl<T, const N: usize> From<[T; N]> for BTreeSet<T, Global>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1236)#### fn from(arr: [T; N]) -> BTreeSet<T, Global>
Converts a `[T; N]` into a `BTreeSet<T>`.
```
use std::collections::BTreeSet;
let set1 = BTreeSet::from([1, 2, 3, 4]);
let set2: BTreeSet<_> = [1, 2, 3, 4].into();
assert_eq!(set1, set2);
```
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1203)### impl<T> FromIterator<T> for BTreeSet<T, Global>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1204)#### fn from\_iter<I>(iter: I) -> BTreeSet<T, Global>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = T>,
Creates a value from an iterator. [Read more](../../iter/trait.fromiterator#tymethod.from_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#89)### impl<T, A> Hash for BTreeSet<T, A>where T: [Hash](../../hash/trait.hash "trait std::hash::Hash"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#90)#### fn hash<H>(&self, state: &mut H)where H: [Hasher](../../hash/trait.hasher "trait std::hash::Hasher"),
Feeds this value into the given [`Hasher`](../../hash/trait.hasher "Hasher"). [Read more](../../hash/trait.hash#tymethod.hash)
[source](https://doc.rust-lang.org/src/core/hash/mod.rs.html#237-239)1.3.0 · #### fn hash\_slice<H>(data: &[Self], state: &mut H)where H: [Hasher](../../hash/trait.hasher "trait std::hash::Hasher"),
Feeds a slice of this type into the given [`Hasher`](../../hash/trait.hasher "Hasher"). [Read more](../../hash/trait.hash#method.hash_slice)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1272)### impl<'a, T, A> IntoIterator for &'a BTreeSet<T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = &'a T
The type of the elements being iterated over.
#### type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1276)#### fn into\_iter(self) -> Iter<'a, T>
Notable traits for [Iter](struct.iter "struct std::collections::btree_set::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1250)### impl<T, A> IntoIterator for BTreeSet<T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1266)#### fn into\_iter(self) -> IntoIter<T, A>
Notable traits for [IntoIter](struct.intoiter "struct std::collections::btree_set::IntoIter")<T, A>
```
impl<T, A> Iterator for IntoIter<T, A>where
A: Allocator + Clone,
type Item = T;
```
Gets an iterator for moving out the `BTreeSet`’s contents.
##### Examples
```
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3, 4]);
let v: Vec<_> = set.into_iter().collect();
assert_eq!(v, [1, 2, 3, 4]);
```
#### type Item = T
The type of the elements being iterated over.
#### type IntoIter = IntoIter<T, A>
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#113)### impl<T, A> Ord for BTreeSet<T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#114)#### fn cmp(&self, other: &BTreeSet<T, A>) -> Ordering
This method returns an [`Ordering`](../../cmp/enum.ordering "Ordering") between `self` and `other`. [Read more](../../cmp/trait.ord#tymethod.cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#804-807)1.21.0 · #### fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. [Read more](../../cmp/trait.ord#method.max)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#831-834)1.21.0 · #### fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. [Read more](../../cmp/trait.ord#method.min)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#863-867)1.50.0 · #### fn clamp(self, min: Self, max: Self) -> Selfwhere Self: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<Self>,
Restrict a value to a certain interval. [Read more](../../cmp/trait.ord#method.clamp)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#96)### impl<T, A> PartialEq<BTreeSet<T, A>> for BTreeSet<T, A>where T: [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<T>, A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#97)#### fn eq(&self, other: &BTreeSet<T, A>) -> bool
This method tests for `self` and `other` values to be equal, and is used by `==`. [Read more](../../cmp/trait.partialeq#tymethod.eq)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#236)#### fn ne(&self, other: &Rhs) -> bool
This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. [Read more](../../cmp/trait.partialeq#method.ne)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#106)### impl<T, A> PartialOrd<BTreeSet<T, A>> for BTreeSet<T, A>where T: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<T>, A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#107)#### fn partial\_cmp(&self, other: &BTreeSet<T, A>) -> Option<Ordering>
This method returns an ordering between `self` and `other` values if one exists. [Read more](../../cmp/trait.partialord#tymethod.partial_cmp)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1138)#### fn lt(&self, other: &Rhs) -> bool
This method tests less than (for `self` and `other`) and is used by the `<` operator. [Read more](../../cmp/trait.partialord#method.lt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1157)#### fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. [Read more](../../cmp/trait.partialord#method.le)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1175)#### fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for `self` and `other`) and is used by the `>` operator. [Read more](../../cmp/trait.partialord#method.gt)
[source](https://doc.rust-lang.org/src/core/cmp.rs.html#1194)#### fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. [Read more](../../cmp/trait.partialord#method.ge)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1379)### impl<T, A> Sub<&BTreeSet<T, A>> for &BTreeSet<T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1395)#### fn sub(self, rhs: &BTreeSet<T, A>) -> BTreeSet<T, A>
Returns the difference of `self` and `rhs` as a new `BTreeSet<T>`.
##### Examples
```
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([3, 4, 5]);
let result = &a - &b;
assert_eq!(result, BTreeSet::from([1, 2]));
```
#### type Output = BTreeSet<T, A>
The resulting type after applying the `-` operator.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#103)### impl<T, A> Eq for BTreeSet<T, A>where T: [Eq](../../cmp/trait.eq "trait std::cmp::Eq"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<T, A> RefUnwindSafe for BTreeSet<T, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T, A> Send for BTreeSet<T, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), T: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<T, A> Sync for BTreeSet<T, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<T, A> Unpin for BTreeSet<T, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T, A> UnwindSafe for BTreeSet<T, A>where A: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::IntoIter Struct std::collections::btree\_set::IntoIter
=============================================
```
pub struct IntoIter<T, A = Global>where A: Allocator + Clone,{ /* private fields */ }
```
An owning iterator over the items of a `BTreeSet`.
This `struct` is created by the [`into_iter`](../struct.btreeset#method.into_iter) method on [`BTreeSet`](../struct.btreeset "BTreeSet") (provided by the [`IntoIterator`](../../iter/trait.intoiterator) trait). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#157)### impl<T, A> Debug for IntoIter<T, A>where T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Debug](../../fmt/trait.debug "trait std::fmt::Debug") + [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#157)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1544)### impl<T, A> DoubleEndedIterator for IntoIter<T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1545)#### fn next\_back(&mut self) -> Option<T>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1550)### impl<T, A> ExactSizeIterator for IntoIter<T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1551)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1532)### impl<T, A> Iterator for IntoIter<T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1535)#### fn next(&mut self) -> Option<T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1539)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)#### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)#### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1557)1.26.0 · ### impl<T, A> FusedIterator for IntoIter<T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<T, A> RefUnwindSafe for IntoIter<T, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<T, A> Send for IntoIter<T, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), T: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<T, A> Sync for IntoIter<T, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<T, A> Unpin for IntoIter<T, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<T, A> UnwindSafe for IntoIter<T, A>where A: [UnwindSafe](../../panic/trait.unwindsafe "trait std::panic::UnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::Difference Struct std::collections::btree\_set::Difference
===============================================
```
pub struct Difference<'a, T, A = Global>where T: 'a, A: Allocator + Clone,{ /* private fields */ }
```
A lazy iterator producing elements in the difference of `BTreeSet`s.
This `struct` is created by the [`difference`](../struct.btreeset#method.difference) method on [`BTreeSet`](../struct.btreeset "BTreeSet"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1598)### impl<T, A> Clone for Difference<'\_, T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1599)#### fn clone(&self) -> Difference<'\_, T, A>
Notable traits for [Difference](struct.difference "struct std::collections::btree_set::Difference")<'a, T, A>
```
impl<'a, T, A> Iterator for Difference<'a, T, A>where
T: Ord,
A: Allocator + Clone,
type Item = &'a T;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#228)1.17.0 · ### impl<T, A> Debug for Difference<'\_, T, A>where T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#229)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1615)### impl<'a, T, A> Iterator for Difference<'a, T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = &'a T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1618)#### fn next(&mut self) -> Option<&'a T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1645)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1656)#### fn min(self) -> Option<&'a T>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1662)1.26.0 · ### impl<T, A> FusedIterator for Difference<'\_, T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<'a, T, A> RefUnwindSafe for Difference<'a, T, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T, A> Send for Difference<'a, T, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Sync for Difference<'a, T, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Unpin for Difference<'a, T, A>
### impl<'a, T, A> UnwindSafe for Difference<'a, T, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::DrainFilter Struct std::collections::btree\_set::DrainFilter
================================================
```
pub struct DrainFilter<'a, T, F, A = Global>where A: Allocator + Clone, T: 'a, F: 'a + FnMut(&T) -> bool,{ /* private fields */ }
```
🔬This is a nightly-only experimental API. (`btree_drain_filter` [#70530](https://github.com/rust-lang/rust/issues/70530))
An iterator produced by calling `drain_filter` on BTreeSet.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1309)### impl<T, F, A> Debug for DrainFilter<'\_, T, F, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1314)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1299)### impl<T, F, A> Drop for DrainFilter<'\_, T, F, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1303)#### fn drop(&mut self)
Executes the destructor for this type. [Read more](../../ops/trait.drop#tymethod.drop)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1320)### impl<'a, T, F, A> Iterator for DrainFilter<'\_, T, F, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), F: 'a + [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
#### type Item = T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1326)#### fn next(&mut self) -> Option<T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1332)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)1.0.0 · #### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1338)### impl<T, F, A> FusedIterator for DrainFilter<'\_, T, F, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
Auto Trait Implementations
--------------------------
### impl<'a, T, F, A> RefUnwindSafe for DrainFilter<'a, T, F, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), F: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T, F, A> Send for DrainFilter<'a, T, F, A>where A: [Send](../../marker/trait.send "trait std::marker::Send"), F: [Send](../../marker/trait.send "trait std::marker::Send"), T: [Send](../../marker/trait.send "trait std::marker::Send"),
### impl<'a, T, F, A> Sync for DrainFilter<'a, T, F, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), F: [Sync](../../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T, F, A> Unpin for DrainFilter<'a, T, F, A>where A: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"), F: [Unpin](../../marker/trait.unpin "trait std::marker::Unpin"),
### impl<'a, T, F, A = Global> !UnwindSafe for DrainFilter<'a, T, F, A>
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::Range Struct std::collections::btree\_set::Range
==========================================
```
pub struct Range<'a, T>where T: 'a,{ /* private fields */ }
```
An iterator over a sub-range of items in a `BTreeSet`.
This `struct` is created by the [`range`](../struct.btreeset#method.range) method on [`BTreeSet`](../struct.btreeset "BTreeSet"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1560)### impl<T> Clone for Range<'\_, T>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1561)#### fn clone(&self) -> Range<'\_, T>
Notable traits for [Range](struct.range "struct std::collections::btree_set::Range")<'a, T>
```
impl<'a, T> Iterator for Range<'a, T>
type Item = &'a T;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)1.0.0 · #### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#172)### impl<'a, T> Debug for Range<'a, T>where T: 'a + [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#172)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1588)### impl<'a, T> DoubleEndedIterator for Range<'a, T>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1589)#### fn next\_back(&mut self) -> Option<&'a T>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1567)### impl<'a, T> Iterator for Range<'a, T>
#### type Item = &'a T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1570)#### fn next(&mut self) -> Option<&'a T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1574)#### fn last(self) -> Option<&'a T>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1578)#### fn min(self) -> Option<&'a T>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1582)#### fn max(self) -> Option<&'a T>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#215)1.0.0 · #### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)1.0.0 · #### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)1.0.0 · #### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)1.0.0 · #### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)1.0.0 · #### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)1.0.0 · #### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)1.0.0 · #### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)1.0.0 · #### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)1.0.0 · #### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)1.0.0 · #### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)1.0.0 · #### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)1.0.0 · #### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)1.0.0 · #### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)1.0.0 · #### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)1.0.0 · #### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)1.0.0 · #### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)1.0.0 · #### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)1.0.0 · #### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)1.0.0 · #### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)1.0.0 · #### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)1.0.0 · #### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)1.0.0 · #### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)1.0.0 · #### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)1.0.0 · #### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)1.0.0 · #### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)1.0.0 · #### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)1.0.0 · #### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)1.0.0 · #### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)1.0.0 · #### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)1.0.0 · #### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1595)1.26.0 · ### impl<T> FusedIterator for Range<'\_, T>
Auto Trait Implementations
--------------------------
### impl<'a, T> RefUnwindSafe for Range<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T> Send for Range<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for Range<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Unpin for Range<'a, T>
### impl<'a, T> UnwindSafe for Range<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::SymmetricDifference Struct std::collections::btree\_set::SymmetricDifference
========================================================
```
pub struct SymmetricDifference<'a, T>(_)where T: 'a;
```
A lazy iterator producing elements in the symmetric difference of `BTreeSet`s.
This `struct` is created by the [`symmetric_difference`](../struct.btreeset#method.symmetric_difference) method on [`BTreeSet`](../struct.btreeset "BTreeSet"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1665)### impl<T> Clone for SymmetricDifference<'\_, T>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1666)#### fn clone(&self) -> SymmetricDifference<'\_, T>
Notable traits for [SymmetricDifference](struct.symmetricdifference "struct std::collections::btree_set::SymmetricDifference")<'a, T>
```
impl<'a, T> Iterator for SymmetricDifference<'a, T>where
T: Ord,
type Item = &'a T;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#246)1.17.0 · ### impl<T> Debug for SymmetricDifference<'\_, T>where T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#247)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1671)### impl<'a, T> Iterator for SymmetricDifference<'a, T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
#### type Item = &'a T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1674)#### fn next(&mut self) -> Option<&'a T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1683)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1691)#### fn min(self) -> Option<&'a T>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1697)1.26.0 · ### impl<T> FusedIterator for SymmetricDifference<'\_, T>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"),
Auto Trait Implementations
--------------------------
### impl<'a, T> RefUnwindSafe for SymmetricDifference<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T> Send for SymmetricDifference<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for SymmetricDifference<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Unpin for SymmetricDifference<'a, T>
### impl<'a, T> UnwindSafe for SymmetricDifference<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::Iter Struct std::collections::btree\_set::Iter
=========================================
```
pub struct Iter<'a, T>where T: 'a,{ /* private fields */ }
```
An iterator over the items of a `BTreeSet`.
This `struct` is created by the [`iter`](../struct.btreeset#method.iter) method on [`BTreeSet`](../struct.btreeset "BTreeSet"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1486)### impl<T> Clone for Iter<'\_, T>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1487)#### fn clone(&self) -> Iter<'\_, T>
Notable traits for [Iter](struct.iter "struct std::collections::btree_set::Iter")<'a, T>
```
impl<'a, T> Iterator for Iter<'a, T>
type Item = &'a T;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#143)1.17.0 · ### impl<T> Debug for Iter<'\_, T>where T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#144)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1516)### impl<'a, T> DoubleEndedIterator for Iter<'a, T>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1517)#### fn next\_back(&mut self) -> Option<&'a T>
Removes and returns an element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#tymethod.next_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#134)#### fn advance\_back\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator from the back by `n` elements. [Read more](../../iter/trait.doubleendediterator#method.advance_back_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#184)1.37.0 · #### fn nth\_back(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element from the end of the iterator. [Read more](../../iter/trait.doubleendediterator#method.nth_back)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#221-225)1.27.0 · #### fn try\_rfold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
This is the reverse version of [`Iterator::try_fold()`](../../iter/trait.iterator#method.try_fold "Iterator::try_fold()"): it takes elements starting from the back of the iterator. [Read more](../../iter/trait.doubleendediterator#method.try_rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#292-295)1.27.0 · #### fn rfold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
An iterator method that reduces the iterator’s elements to a single, final value, starting from the back. [Read more](../../iter/trait.doubleendediterator#method.rfold)
[source](https://doc.rust-lang.org/src/core/iter/traits/double_ended.rs.html#347-350)1.27.0 · #### fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator from the back that satisfies a predicate. [Read more](../../iter/trait.doubleendediterator#method.rfind)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1522)### impl<T> ExactSizeIterator for Iter<'\_, T>
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1523)#### fn len(&self) -> usize
Returns the exact remaining length of the iterator. [Read more](../../iter/trait.exactsizeiterator#method.len)
[source](https://doc.rust-lang.org/src/core/iter/traits/exact_size.rs.html#138)#### fn is\_empty(&self) -> bool
🔬This is a nightly-only experimental API. (`exact_size_is_empty` [#35428](https://github.com/rust-lang/rust/issues/35428))
Returns `true` if the iterator is empty. [Read more](../../iter/trait.exactsizeiterator#method.is_empty)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1492)### impl<'a, T> Iterator for Iter<'a, T>
#### type Item = &'a T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1495)#### fn next(&mut self) -> Option<&'a T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1499)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1503)#### fn last(self) -> Option<&'a T>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1507)#### fn min(self) -> Option<&'a T>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1511)#### fn max(self) -> Option<&'a T>
Returns the maximum element of an iterator. [Read more](../../iter/trait.iterator#method.max)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2079-2082)#### fn partition\_in\_place<'a, T, P>(self, predicate: P) -> usizewhere T: 'a, Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator")<Item = [&'a mut](../../primitive.reference) T>, P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&](../../primitive.reference)T) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_partition_in_place` [#62543](https://github.com/rust-lang/rust/issues/62543))
Reorders the elements of this iterator *in-place* according to the given predicate, such that all those that return `true` precede all those that return `false`. Returns the number of `true` elements found. [Read more](../../iter/trait.iterator#method.partition_in_place)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2920-2923)#### fn rposition<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool), Self: [ExactSizeIterator](../../iter/trait.exactsizeiterator "trait std::iter::ExactSizeIterator") + [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Searches for an element in an iterator from the right, returning its index. [Read more](../../iter/trait.iterator#method.rposition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3161-3163)#### fn rev(self) -> Rev<Self>where Self: [DoubleEndedIterator](../../iter/trait.doubleendediterator "trait std::iter::DoubleEndedIterator"),
Notable traits for [Rev](../../iter/struct.rev "struct std::iter::Rev")<I>
```
impl<I> Iterator for Rev<I>where
I: DoubleEndedIterator,
type Item = <I as Iterator>::Item;
```
Reverses an iterator’s direction. [Read more](../../iter/trait.iterator#method.rev)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1529)1.26.0 · ### impl<T> FusedIterator for Iter<'\_, T>
Auto Trait Implementations
--------------------------
### impl<'a, T> RefUnwindSafe for Iter<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T> Send for Iter<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Sync for Iter<'a, T>where T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T> Unpin for Iter<'a, T>
### impl<'a, T> UnwindSafe for Iter<'a, T>where T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
rust Struct std::collections::btree_set::Intersection Struct std::collections::btree\_set::Intersection
=================================================
```
pub struct Intersection<'a, T, A = Global>where T: 'a, A: Allocator + Clone,{ /* private fields */ }
```
A lazy iterator producing elements in the intersection of `BTreeSet`s.
This `struct` is created by the [`intersection`](../struct.btreeset#method.intersection) method on [`BTreeSet`](../struct.btreeset "BTreeSet"). See its documentation for more.
Trait Implementations
---------------------
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1700)### impl<T, A> Clone for Intersection<'\_, T, A>where A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1701)#### fn clone(&self) -> Intersection<'\_, T, A>
Notable traits for [Intersection](struct.intersection "struct std::collections::btree_set::Intersection")<'a, T, A>
```
impl<'a, T, A> Iterator for Intersection<'a, T, A>where
T: Ord,
A: Allocator + Clone,
type Item = &'a T;
```
Returns a copy of the value. [Read more](../../clone/trait.clone#tymethod.clone)
[source](https://doc.rust-lang.org/src/core/clone.rs.html#132-134)#### fn clone\_from(&mut self, source: &Self)
Performs copy-assignment from `source`. [Read more](../../clone/trait.clone#method.clone_from)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#300)1.17.0 · ### impl<T, A> Debug for Intersection<'\_, T, A>where T: [Debug](../../fmt/trait.debug "trait std::fmt::Debug"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#301)#### fn fmt(&self, f: &mut Formatter<'\_>) -> Result<(), Error>
Formats the value using the given formatter. [Read more](../../fmt/trait.debug#tymethod.fmt)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1716)### impl<'a, T, A> Iterator for Intersection<'a, T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Item = &'a T
The type of the elements being iterated over.
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1719)#### fn next(&mut self) -> Option<&'a T>
Advances the iterator and returns the next value. [Read more](../../iter/trait.iterator#tymethod.next)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1742)#### fn size\_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. [Read more](../../iter/trait.iterator#method.size_hint)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1751)#### fn min(self) -> Option<&'a T>
Returns the minimum element of an iterator. [Read more](../../iter/trait.iterator#method.min)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#138-142)#### fn next\_chunk<const N: usize>( &mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
🔬This is a nightly-only experimental API. (`iter_next_chunk` [#98326](https://github.com/rust-lang/rust/issues/98326))
Advances the iterator and returns an array containing the next `N` values. [Read more](../../iter/trait.iterator#method.next_chunk)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#252-254)#### fn count(self) -> usize
Consumes the iterator, counting the number of iterations and returning it. [Read more](../../iter/trait.iterator#method.count)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#282-284)#### fn last(self) -> Option<Self::Item>
Consumes the iterator, returning the last element. [Read more](../../iter/trait.iterator#method.last)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#328)#### fn advance\_by(&mut self, n: usize) -> Result<(), usize>
🔬This is a nightly-only experimental API. (`iter_advance_by` [#77404](https://github.com/rust-lang/rust/issues/77404))
Advances the iterator by `n` elements. [Read more](../../iter/trait.iterator#method.advance_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#376)#### fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the `n`th element of the iterator. [Read more](../../iter/trait.iterator#method.nth)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#428-430)1.28.0 · #### fn step\_by(self, step: usize) -> StepBy<Self>
Notable traits for [StepBy](../../iter/struct.stepby "struct std::iter::StepBy")<I>
```
impl<I> Iterator for StepBy<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator starting at the same point, but stepping by the given amount at each iteration. [Read more](../../iter/trait.iterator#method.step_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#499-502)#### fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")<Item = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Notable traits for [Chain](../../iter/struct.chain "struct std::iter::Chain")<A, B>
```
impl<A, B> Iterator for Chain<A, B>where
A: Iterator,
B: Iterator<Item = <A as Iterator>::Item>,
type Item = <A as Iterator>::Item;
```
Takes two iterators and creates a new iterator over both in sequence. [Read more](../../iter/trait.iterator#method.chain)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#617-620)#### fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"),
Notable traits for [Zip](../../iter/struct.zip "struct std::iter::Zip")<A, B>
```
impl<A, B> Iterator for Zip<A, B>where
A: Iterator,
B: Iterator,
type Item = (<A as Iterator>::Item, <B as Iterator>::Item);
```
‘Zips up’ two iterators into a single iterator of pairs. [Read more](../../iter/trait.iterator#method.zip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#717-720)#### fn intersperse\_with<G>(self, separator: G) -> IntersperseWith<Self, G>where G: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")() -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Notable traits for [IntersperseWith](../../iter/struct.interspersewith "struct std::iter::IntersperseWith")<I, G>
```
impl<I, G> Iterator for IntersperseWith<I, G>where
I: Iterator,
G: FnMut() -> <I as Iterator>::Item,
type Item = <I as Iterator>::Item;
```
🔬This is a nightly-only experimental API. (`iter_intersperse` [#79524](https://github.com/rust-lang/rust/issues/79524))
Creates a new iterator which places an item generated by `separator` between adjacent items of the original iterator. [Read more](../../iter/trait.iterator#method.intersperse_with)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#776-779)#### fn map<B, F>(self, f: F) -> Map<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Notable traits for [Map](../../iter/struct.map "struct std::iter::Map")<I, F>
```
impl<B, I, F> Iterator for Map<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> B,
type Item = B;
```
Takes a closure and creates an iterator which calls that closure on each element. [Read more](../../iter/trait.iterator#method.map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#821-824)1.21.0 · #### fn for\_each<F>(self, f: F)where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Calls a closure on each element of an iterator. [Read more](../../iter/trait.iterator#method.for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#896-899)#### fn filter<P>(self, predicate: P) -> Filter<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [Filter](../../iter/struct.filter "struct std::iter::Filter")<I, P>
```
impl<I, P> Iterator for Filter<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator which uses a closure to determine if an element should be yielded. [Read more](../../iter/trait.iterator#method.filter)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#941-944)#### fn filter\_map<B, F>(self, f: F) -> FilterMap<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [FilterMap](../../iter/struct.filtermap "struct std::iter::FilterMap")<I, F>
```
impl<B, I, F> Iterator for FilterMap<I, F>where
I: Iterator,
F: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both filters and maps. [Read more](../../iter/trait.iterator#method.filter_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#987-989)#### fn enumerate(self) -> Enumerate<Self>
Notable traits for [Enumerate](../../iter/struct.enumerate "struct std::iter::Enumerate")<I>
```
impl<I> Iterator for Enumerate<I>where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);
```
Creates an iterator which gives the current iteration count as well as the next value. [Read more](../../iter/trait.iterator#method.enumerate)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1058-1060)#### fn peekable(self) -> Peekable<Self>
Notable traits for [Peekable](../../iter/struct.peekable "struct std::iter::Peekable")<I>
```
impl<I> Iterator for Peekable<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which can use the [`peek`](../../iter/struct.peekable#method.peek) and [`peek_mut`](../../iter/struct.peekable#method.peek_mut) methods to look at the next element of the iterator without consuming it. See their documentation for more information. [Read more](../../iter/trait.iterator#method.peekable)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1123-1126)#### fn skip\_while<P>(self, predicate: P) -> SkipWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [SkipWhile](../../iter/struct.skipwhile "struct std::iter::SkipWhile")<I, P>
```
impl<I, P> Iterator for SkipWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that [`skip`](../../iter/trait.iterator#method.skip)s elements based on a predicate. [Read more](../../iter/trait.iterator#method.skip_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1204-1207)#### fn take\_while<P>(self, predicate: P) -> TakeWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Notable traits for [TakeWhile](../../iter/struct.takewhile "struct std::iter::TakeWhile")<I, P>
```
impl<I, P> Iterator for TakeWhile<I, P>where
I: Iterator,
P: FnMut(&<I as Iterator>::Item) -> bool,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields elements based on a predicate. [Read more](../../iter/trait.iterator#method.take_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1292-1295)1.57.0 · #### fn map\_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [MapWhile](../../iter/struct.mapwhile "struct std::iter::MapWhile")<I, P>
```
impl<B, I, P> Iterator for MapWhile<I, P>where
I: Iterator,
P: FnMut(<I as Iterator>::Item) -> Option<B>,
type Item = B;
```
Creates an iterator that both yields elements based on a predicate and maps. [Read more](../../iter/trait.iterator#method.map_while)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1323-1325)#### fn skip(self, n: usize) -> Skip<Self>
Notable traits for [Skip](../../iter/struct.skip "struct std::iter::Skip")<I>
```
impl<I> Iterator for Skip<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that skips the first `n` elements. [Read more](../../iter/trait.iterator#method.skip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1376-1378)#### fn take(self, n: usize) -> Take<Self>
Notable traits for [Take](../../iter/struct.take "struct std::iter::Take")<I>
```
impl<I> Iterator for Take<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. [Read more](../../iter/trait.iterator#method.take)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1420-1423)#### fn scan<St, B, F>(self, initial\_state: St, f: F) -> Scan<Self, St, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")([&mut](../../primitive.reference) St, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Notable traits for [Scan](../../iter/struct.scan "struct std::iter::Scan")<I, St, F>
```
impl<B, I, St, F> Iterator for Scan<I, St, F>where
I: Iterator,
F: FnMut(&mut St, <I as Iterator>::Item) -> Option<B>,
type Item = B;
```
An iterator adapter similar to [`fold`](../../iter/trait.iterator#method.fold) that holds internal state and produces a new iterator. [Read more](../../iter/trait.iterator#method.scan)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1460-1464)#### fn flat\_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where U: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> U,
Notable traits for [FlatMap](../../iter/struct.flatmap "struct std::iter::FlatMap")<I, U, F>
```
impl<I, U, F> Iterator for FlatMap<I, U, F>where
I: Iterator,
U: IntoIterator,
F: FnMut(<I as Iterator>::Item) -> U,
type Item = <U as IntoIterator>::Item;
```
Creates an iterator that works like map, but flattens nested structure. [Read more](../../iter/trait.iterator#method.flat_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1600-1602)#### fn fuse(self) -> Fuse<Self>
Notable traits for [Fuse](../../iter/struct.fuse "struct std::iter::Fuse")<I>
```
impl<I> Iterator for Fuse<I>where
I: Iterator,
type Item = <I as Iterator>::Item;
```
Creates an iterator which ends after the first [`None`](../../option/enum.option#variant.None "None"). [Read more](../../iter/trait.iterator#method.fuse)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1684-1687)#### fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")),
Notable traits for [Inspect](../../iter/struct.inspect "struct std::iter::Inspect")<I, F>
```
impl<I, F> Iterator for Inspect<I, F>where
I: Iterator,
F: FnMut(&<I as Iterator>::Item),
type Item = <I as Iterator>::Item;
```
Does something with each element of an iterator, passing the value on. [Read more](../../iter/trait.iterator#method.inspect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1714-1716)#### fn by\_ref(&mut self) -> &mut Self
Borrows an iterator, rather than consuming it. [Read more](../../iter/trait.iterator#method.by_ref)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1832-1834)#### fn collect<B>(self) -> Bwhere B: [FromIterator](../../iter/trait.fromiterator "trait std::iter::FromIterator")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Transforms an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#1983-1985)#### fn collect\_into<E>(self, collection: &mut E) -> &mut Ewhere E: [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
🔬This is a nightly-only experimental API. (`iter_collect_into` [#94780](https://github.com/rust-lang/rust/issues/94780))
Collects all the items from an iterator into a collection. [Read more](../../iter/trait.iterator#method.collect_into)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2017-2021)#### fn partition<B, F>(self, f: F) -> (B, B)where B: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Consumes an iterator, creating two collections from it. [Read more](../../iter/trait.iterator#method.partition)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2136-2139)#### fn is\_partitioned<P>(self, predicate: P) -> boolwhere P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_is_partitioned` [#62544](https://github.com/rust-lang/rust/issues/62544))
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return `true` precede all those that return `false`. [Read more](../../iter/trait.iterator#method.is_partitioned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2230-2234)1.27.0 · #### fn try\_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = B>,
An iterator method that applies a function as long as it returns successfully, producing a single, final value. [Read more](../../iter/trait.iterator#method.try_fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2288-2292)1.27.0 · #### fn try\_for\_each<F, R>(&mut self, f: F) -> Rwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [()](../../primitive.unit)>,
An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. [Read more](../../iter/trait.iterator#method.try_for_each)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2407-2410)#### fn fold<B, F>(self, init: B, f: F) -> Bwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(B, Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Folds every element into an accumulator by applying an operation, returning the final result. [Read more](../../iter/trait.iterator#method.fold)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2453-2456)1.51.0 · #### fn reduce<F>(self, f: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"),
Reduces the elements to a single one, by repeatedly applying a reducing operation. [Read more](../../iter/trait.iterator#method.reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2524-2529)#### fn try\_reduce<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`iterator_try_reduce` [#87053](https://github.com/rust-lang/rust/issues/87053))
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. [Read more](../../iter/trait.iterator#method.try_reduce)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2581-2584)#### fn all<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if every element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.all)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2634-2637)#### fn any<F>(&mut self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Tests if any element of the iterator matches a predicate. [Read more](../../iter/trait.iterator#method.any)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2694-2697)#### fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element of an iterator that satisfies a predicate. [Read more](../../iter/trait.iterator#method.find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2725-2728)1.30.0 · #### fn find\_map<B, F>(&mut self, f: F) -> Option<B>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<B>,
Applies function to the elements of iterator and returns the first non-none result. [Read more](../../iter/trait.iterator#method.find_map)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2781-2786)#### fn try\_find<F, R>( &mut self, f: F) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> R, R: [Try](../../ops/trait.try "trait std::ops::Try")<Output = [bool](../../primitive.bool)>, <R as [Try](../../ops/trait.try "trait std::ops::Try")>::[Residual](../../ops/trait.try#associatedtype.Residual "type std::ops::Try::Residual"): [Residual](../../ops/trait.residual "trait std::ops::Residual")<[Option](../../option/enum.option "enum std::option::Option")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>>,
🔬This is a nightly-only experimental API. (`try_find` [#63178](https://github.com/rust-lang/rust/issues/63178))
Applies function to the elements of iterator and returns the first true result or the first error. [Read more](../../iter/trait.iterator#method.try_find)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#2863-2866)#### fn position<P>(&mut self, predicate: P) -> Option<usize>where P: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [bool](../../primitive.bool),
Searches for an element in an iterator, returning its index. [Read more](../../iter/trait.iterator#method.position)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3031-3034)1.6.0 · #### fn max\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the maximum value from the specified function. [Read more](../../iter/trait.iterator#method.max_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3064-3067)1.15.0 · #### fn max\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the maximum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.max_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3091-3094)1.6.0 · #### fn min\_by\_key<B, F>(self, f: F) -> Option<Self::Item>where B: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> B,
Returns the element that gives the minimum value from the specified function. [Read more](../../iter/trait.iterator#method.min_by_key)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3124-3127)1.15.0 · #### fn min\_by<F>(self, compare: F) -> Option<Self::Item>where F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
Returns the element that gives the minimum value with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.min_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3199-3203)#### fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where FromA: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<A>, FromB: [Default](../../default/trait.default "trait std::default::Default") + [Extend](../../iter/trait.extend "trait std::iter::Extend")<B>, Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [(A, B)](../../primitive.tuple)>,
Converts an iterator of pairs into a pair of containers. [Read more](../../iter/trait.iterator#method.unzip)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3231-3234)1.36.0 · #### fn copied<'a, T>(self) -> Copied<Self>where T: 'a + [Copy](../../marker/trait.copy "trait std::marker::Copy"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Copied](../../iter/struct.copied "struct std::iter::Copied")<I>
```
impl<'a, I, T> Iterator for Copied<I>where
T: 'a + Copy,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which copies all of its elements. [Read more](../../iter/trait.iterator#method.copied)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3278-3281)#### fn cloned<'a, T>(self) -> Cloned<Self>where T: 'a + [Clone](../../clone/trait.clone "trait std::clone::Clone"), Self: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator")<Item = [&'a](../../primitive.reference) T>,
Notable traits for [Cloned](../../iter/struct.cloned "struct std::iter::Cloned")<I>
```
impl<'a, I, T> Iterator for Cloned<I>where
T: 'a + Clone,
I: Iterator<Item = &'a T>,
type Item = T;
```
Creates an iterator which [`clone`](../../clone/trait.clone#tymethod.clone)s all of its elements. [Read more](../../iter/trait.iterator#method.cloned)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3312-3314)#### fn cycle(self) -> Cycle<Self>where Self: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Notable traits for [Cycle](../../iter/struct.cycle "struct std::iter::Cycle")<I>
```
impl<I> Iterator for Cycle<I>where
I: Clone + Iterator,
type Item = <I as Iterator>::Item;
```
Repeats an iterator endlessly. [Read more](../../iter/trait.iterator#method.cycle)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3355-3357)#### fn array\_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
Notable traits for [ArrayChunks](../../iter/struct.arraychunks "struct std::iter::ArrayChunks")<I, N>
```
impl<I, const N: usize> Iterator for ArrayChunks<I, N>where
I: Iterator,
type Item = [<I as Iterator>::Item; N];
```
🔬This is a nightly-only experimental API. (`iter_array_chunks` [#100450](https://github.com/rust-lang/rust/issues/100450))
Returns an iterator over `N` elements of the iterator at a time. [Read more](../../iter/trait.iterator#method.array_chunks)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3385-3388)1.11.0 · #### fn sum<S>(self) -> Swhere S: [Sum](../../iter/trait.sum "trait std::iter::Sum")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Sums the elements of an iterator. [Read more](../../iter/trait.iterator#method.sum)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3414-3417)1.11.0 · #### fn product<P>(self) -> Pwhere P: [Product](../../iter/trait.product "trait std::iter::Product")<Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")>,
Iterates over the entire iterator, multiplying all the elements [Read more](../../iter/trait.iterator#method.product)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3464-3468)#### fn cmp\_by<I, F>(self, other: I, cmp: F) -> Orderingwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering"),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3511-3515)1.5.0 · #### fn partial\_cmp<I>(self, other: I) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another. [Read more](../../iter/trait.iterator#method.partial_cmp)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3549-3553)#### fn partial\_cmp\_by<I, F>(self, other: I, partial\_cmp: F) -> Option<Ordering>where I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
[Lexicographically](../../cmp/trait.ord#lexicographical-comparison) compares the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") with those of another with respect to the specified comparison function. [Read more](../../iter/trait.iterator#method.partial_cmp_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3591-3595)1.5.0 · #### fn eq<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another. [Read more](../../iter/trait.iterator#method.eq)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3616-3620)#### fn eq\_by<I, F>(self, other: I, eq: F) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), <I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")) -> [bool](../../primitive.bool),
🔬This is a nightly-only experimental API. (`iter_order_by` [#64295](https://github.com/rust-lang/rust/issues/64295))
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are equal to those of another with respect to the specified equality function. [Read more](../../iter/trait.iterator#method.eq_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3651-3655)1.5.0 · #### fn ne<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialEq](../../cmp/trait.partialeq "trait std::cmp::PartialEq")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are unequal to those of another. [Read more](../../iter/trait.iterator#method.ne)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3672-3676)1.5.0 · #### fn lt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less than those of another. [Read more](../../iter/trait.iterator#method.lt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3693-3697)1.5.0 · #### fn le<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) less or equal to those of another. [Read more](../../iter/trait.iterator#method.le)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3714-3718)1.5.0 · #### fn gt<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than those of another. [Read more](../../iter/trait.iterator#method.gt)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3735-3739)1.5.0 · #### fn ge<I>(self, other: I) -> boolwhere I: [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator"), Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"): [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<<I as [IntoIterator](../../iter/trait.intoiterator "trait std::iter::IntoIterator")>::[Item](../../iter/trait.intoiterator#associatedtype.Item "type std::iter::IntoIterator::Item")>,
Determines if the elements of this [`Iterator`](../../iter/trait.iterator "Iterator") are [lexicographically](../../cmp/trait.ord#lexicographical-comparison) greater than or equal to those of another. [Read more](../../iter/trait.iterator#method.ge)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3794-3797)#### fn is\_sorted\_by<F>(self, compare: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(&Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item"), &Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> [Option](../../option/enum.option "enum std::option::Option")<[Ordering](../../cmp/enum.ordering "enum std::cmp::Ordering")>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given comparator function. [Read more](../../iter/trait.iterator#method.is_sorted_by)
[source](https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#3840-3844)#### fn is\_sorted\_by\_key<F, K>(self, f: F) -> boolwhere F: [FnMut](../../ops/trait.fnmut "trait std::ops::FnMut")(Self::[Item](../../iter/trait.iterator#associatedtype.Item "type std::iter::Iterator::Item")) -> K, K: [PartialOrd](../../cmp/trait.partialord "trait std::cmp::PartialOrd")<K>,
🔬This is a nightly-only experimental API. (`is_sorted` [#53485](https://github.com/rust-lang/rust/issues/53485))
Checks if the elements of this iterator are sorted using the given key extraction function. [Read more](../../iter/trait.iterator#method.is_sorted_by_key)
[source](https://doc.rust-lang.org/src/alloc/collections/btree/set.rs.html#1757)1.26.0 · ### impl<T, A> FusedIterator for Intersection<'\_, T, A>where T: [Ord](../../cmp/trait.ord "trait std::cmp::Ord"), A: [Allocator](../../alloc/trait.allocator "trait std::alloc::Allocator") + [Clone](../../clone/trait.clone "trait std::clone::Clone"),
Auto Trait Implementations
--------------------------
### impl<'a, T, A> RefUnwindSafe for Intersection<'a, T, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
### impl<'a, T, A> Send for Intersection<'a, T, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Sync for Intersection<'a, T, A>where A: [Sync](../../marker/trait.sync "trait std::marker::Sync"), T: [Sync](../../marker/trait.sync "trait std::marker::Sync"),
### impl<'a, T, A> Unpin for Intersection<'a, T, A>
### impl<'a, T, A> UnwindSafe for Intersection<'a, T, A>where A: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"), T: [RefUnwindSafe](../../panic/trait.refunwindsafe "trait std::panic::RefUnwindSafe"),
Blanket Implementations
-----------------------
[source](https://doc.rust-lang.org/src/core/any.rs.html#200)### impl<T> Any for Twhere T: 'static + ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/any.rs.html#201)#### fn type\_id(&self) -> TypeId
Gets the `TypeId` of `self`. [Read more](../../any/trait.any#tymethod.type_id)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#209)### impl<T> Borrow<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#211)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow(&self) -> &T
Immutably borrows from an owned value. [Read more](../../borrow/trait.borrow#tymethod.borrow)
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#218)### impl<T> BorrowMut<T> for Twhere T: ?[Sized](../../marker/trait.sized "trait std::marker::Sized"),
[source](https://doc.rust-lang.org/src/core/borrow.rs.html#219)const: [unstable](https://github.com/rust-lang/rust/issues/91522 "Tracking issue for const_borrow") · #### fn borrow\_mut(&mut self) -> &mut T
Mutably borrows from an owned value. [Read more](../../borrow/trait.borrowmut#tymethod.borrow_mut)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#559)### impl<T> From<T> for T
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#562)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn from(t: T) -> T
Returns the argument unchanged.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#543)### impl<T, U> Into<U> for Twhere U: [From](../../convert/trait.from "trait std::convert::From")<T>,
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#551)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn into(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](../../convert/trait.from "From")<T> for U` chooses to do.
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#266)### impl<I> IntoIterator for Iwhere I: [Iterator](../../iter/trait.iterator "trait std::iter::Iterator"),
#### type Item = <I as Iterator>::Item
The type of the elements being iterated over.
#### type IntoIter = I
Which kind of iterator are we turning this into?
[source](https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#271)const: [unstable](https://github.com/rust-lang/rust/issues/90603 "Tracking issue for const_intoiterator_identity") · #### fn into\_iter(self) -> I
Creates an iterator from a value. [Read more](../../iter/trait.intoiterator#tymethod.into_iter)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#83)### impl<T> ToOwned for Twhere T: [Clone](../../clone/trait.clone "trait std::clone::Clone"),
#### type Owned = T
The resulting type after obtaining ownership.
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#88)#### fn to\_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. [Read more](../../borrow/trait.toowned#tymethod.to_owned)
[source](https://doc.rust-lang.org/src/alloc/borrow.rs.html#92)#### fn clone\_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. [Read more](../../borrow/trait.toowned#method.clone_into)
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#601)### impl<T, U> TryFrom<U> for Twhere U: [Into](../../convert/trait.into "trait std::convert::Into")<T>,
#### type Error = Infallible
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#607)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#586)### impl<T, U> TryInto<U> for Twhere U: [TryFrom](../../convert/trait.tryfrom "trait std::convert::TryFrom")<T>,
#### type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
[source](https://doc.rust-lang.org/src/core/convert/mod.rs.html#592)const: [unstable](https://github.com/rust-lang/rust/issues/88674 "Tracking issue for const_convert") · #### fn try\_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
| programming_docs |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.