Trait libc::prelude::Sync

1.0.0 · source ·
pub(crate) unsafe auto trait Sync { }
Expand description

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 if and only if &T is Send. In other words, if there is no possibility of undefined behavior (including data races) when passing &T references between threads.

As one would expect, primitive types like u8 and f64 are all Sync, and so are simple aggregate types containing them, like tuples, structs and enums. More examples of basic Sync types include “immutable” types like &T, and those with simple inherited mutability, such as Box<T>, Vec<T> and most other collection types. (Generic parameters need to be Sync for their container to be 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.

A shorter overview of how Sync and Send relate to referencing:

  • &T is Send if and only if T is Sync
  • &mut T is Send if and only if T is Send
  • &T and &mut T are Sync if and only if T is Sync

Types that are not Sync are those that have “interior mutability” in a non-thread-safe form, such as Cell and RefCell. These types allow for mutation of their contents even through an immutable, shared reference. For example the set method on Cell<T> takes &self, so it requires only a shared reference &Cell<T>. The method performs no synchronization, thus Cell cannot be Sync.

Another example of a non-Sync type is the reference-counting pointer Rc. Given any reference &Rc<T>, you can clone a new Rc<T>, modifying the reference counts in a non-atomic way.

For cases when one does need thread-safe interior mutability, Rust provides atomic data types, as well as explicit locking via sync::Mutex and sync::RwLock. These types ensure that any mutation cannot cause data races, hence the types are Sync. Likewise, sync::Arc provides a thread-safe analogue of Rc.

Any types with interior mutability must also use the cell::UnsafeCell wrapper around the value(s) which can be mutated through a shared reference. Failing to doing this is undefined behavior. For example, transmute-ing from &T to &mut T is invalid.

See the Nomicon for more details about Sync.

Implementors§

1.0.0 · source§

impl !Sync for Arguments<'_>

source§

impl !Sync for LocalWaker

source§

impl Sync for Bytes<'_>

1.0.0 · source§

impl Sync for AtomicBool

1.34.0 · source§

impl Sync for AtomicI8

1.34.0 · source§

impl Sync for AtomicI16

1.34.0 · source§

impl Sync for AtomicI32

1.34.0 · source§

impl Sync for AtomicI64

1.0.0 · source§

impl Sync for AtomicIsize

1.34.0 · source§

impl Sync for AtomicU8

1.34.0 · source§

impl Sync for AtomicU16

1.34.0 · source§

impl Sync for AtomicU32

1.34.0 · source§

impl Sync for AtomicU64

1.0.0 · source§

impl Sync for AtomicUsize

1.36.0 · source§

impl Sync for Waker

source§

impl<Dyn> Sync for DynMetadata<Dyn>
where Dyn: ?Sized,

1.0.0 · source§

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

1.0.0 · source§

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

1.70.0 · source§

impl<T> !Sync for OnceCell<T>

1.0.0 · source§

impl<T> !Sync for Cell<T>
where T: ?Sized,

1.0.0 · source§

impl<T> !Sync for RefCell<T>
where T: ?Sized,

1.0.0 · source§

impl<T> !Sync for UnsafeCell<T>
where T: ?Sized,

1.25.0 · source§

impl<T> !Sync for NonNull<T>
where T: ?Sized,

NonNull pointers are not Sync because the data they reference may be aliased.

source§

impl<T> Sync for SyncUnsafeCell<T>
where T: Sync + ?Sized,

1.28.0 · source§

impl<T> Sync for NonZero<T>

1.31.0 · source§

impl<T> Sync for ChunksExactMut<'_, T>
where T: Sync,

1.0.0 · source§

impl<T> Sync for ChunksMut<'_, T>
where T: Sync,

1.0.0 · source§

impl<T> Sync for Iter<'_, T>
where T: Sync,

1.0.0 · source§

impl<T> Sync for IterMut<'_, T>
where T: Sync,

1.31.0 · source§

impl<T> Sync for RChunksExactMut<'_, T>
where T: Sync,

1.31.0 · source§

impl<T> Sync for RChunksMut<'_, T>
where T: Sync,

1.0.0 · source§

impl<T> Sync for AtomicPtr<T>

source§

impl<T> Sync for Exclusive<T>
where T: ?Sized,

Auto implementors§

§

impl !Sync for mcontext_t

§

impl !Sync for stack_t

§

impl !Sync for ucontext_t

§

impl !Sync for user

§

impl !Sync for aiocb

§

impl !Sync for glob64_t

§

impl !Sync for msghdr

§

impl !Sync for regex_t

§

impl !Sync for rtentry

§

impl !Sync for siginfo_f

§

impl !Sync for dl_phdr_info

§

impl !Sync for ff_periodic_effect

§

impl !Sync for glob_t

§

impl !Sync for if_nameindex

§

impl !Sync for ifconf

§

impl !Sync for ifreq

§

impl !Sync for iw_event

§

impl !Sync for iw_point

§

impl !Sync for iwreq

§

impl !Sync for mntent

§

impl !Sync for option

§

impl !Sync for passwd

§

impl !Sync for posix_spawn_file_actions_t

§

impl !Sync for sock_fprog

§

impl !Sync for spwd

§

impl !Sync for Dl_info

§

impl !Sync for addrinfo

§

impl !Sync for ifaddrs

§

impl !Sync for lconv

§

impl !Sync for mmsghdr

§

impl !Sync for sigevent

§

impl !Sync for tm

§

impl !Sync for group

§

impl !Sync for hostent

§

impl !Sync for iovec

§

impl !Sync for protoent

§

impl !Sync for servent

§

impl !Sync for sigval

§

impl !Sync for sifields

§

impl !Sync for __c_anonymous_ifc_ifcu

§

impl !Sync for __c_anonymous_ifr_ifru

§

impl !Sync for iwreq_data

§

impl Sync for c_void

§

impl Sync for DIR

§

impl Sync for FILE

§

impl Sync for fpos_t

§

impl Sync for timezone

§

impl Sync for fpos64_t

§

impl Sync for tpacket_versions

§

impl Sync for Alignment

§

impl Sync for termios2

§

impl Sync for msqid_ds

§

impl Sync for semid_ds

§

impl Sync for sigset_t

§

impl Sync for sysinfo

§

impl Sync for statvfs

§

impl Sync for _libc_fpstate

§

impl Sync for _libc_fpxreg

§

impl Sync for _libc_xmmreg

§

impl Sync for clone_args

§

impl Sync for flock64

§

impl Sync for flock

§

impl Sync for ipc_perm

§

impl Sync for max_align_t

§

impl Sync for pthread_attr_t

§

impl Sync for ptrace_rseq_configuration

§

impl Sync for shmid_ds

§

impl Sync for sigaction

§

impl Sync for siginfo_t

§

impl Sync for stat64

§

impl Sync for stat

§

impl Sync for statfs64

§

impl Sync for statfs

§

impl Sync for statvfs64

§

impl Sync for user_fpregs_struct

§

impl Sync for user_regs_struct

§

impl Sync for Elf32_Chdr

§

impl Sync for Elf64_Chdr

§

impl Sync for __c_anonymous_ptrace_syscall_info_entry

§

impl Sync for __c_anonymous_ptrace_syscall_info_exit

§

impl Sync for __c_anonymous_ptrace_syscall_info_seccomp

§

impl Sync for __exit_status

§

impl Sync for __timeval

§

impl Sync for cmsghdr

§

impl Sync for fanotify_event_info_error

§

impl Sync for fanotify_event_info_pidfd

§

impl Sync for iocb

§

impl Sync for mallinfo2

§

impl Sync for mallinfo

§

impl Sync for nl_mmap_hdr

§

impl Sync for nl_mmap_req

§

impl Sync for nl_pktinfo

§

impl Sync for ntptimeval

§

impl Sync for ptrace_peeksiginfo_args

§

impl Sync for ptrace_syscall_info

§

impl Sync for sem_t

§

impl Sync for seminfo

§

impl Sync for sifields_sigchld

§

impl Sync for sockaddr_xdp

§

impl Sync for tcp_info

§

impl Sync for termios

§

impl Sync for timex

§

impl Sync for utmpx

§

impl Sync for xdp_desc

§

impl Sync for xdp_mmap_offsets

§

impl Sync for xdp_mmap_offsets_v1

§

impl Sync for xdp_options

§

impl Sync for xdp_ring_offset

§

impl Sync for xdp_ring_offset_v1

§

impl Sync for xdp_statistics

§

impl Sync for xdp_statistics_v1

§

impl Sync for xdp_umem_reg

§

impl Sync for xdp_umem_reg_v1

§

impl Sync for Elf32_Ehdr

§

impl Sync for Elf32_Phdr

§

impl Sync for Elf32_Shdr

§

impl Sync for Elf32_Sym

§

impl Sync for Elf64_Ehdr

§

impl Sync for Elf64_Phdr

§

impl Sync for Elf64_Shdr

§

impl Sync for Elf64_Sym

§

impl Sync for __c_anonymous__kernel_fsid_t

§

impl Sync for __c_anonymous_elf32_rel

§

impl Sync for __c_anonymous_elf32_rela

§

impl Sync for __c_anonymous_elf64_rel

§

impl Sync for __c_anonymous_elf64_rela

§

impl Sync for __c_anonymous_ifru_map

§

impl Sync for __c_anonymous_sockaddr_can_j1939

§

impl Sync for __c_anonymous_sockaddr_can_tp

§

impl Sync for af_alg_iv

§

impl Sync for arpd_request

§

impl Sync for can_filter

§

impl Sync for can_frame

§

impl Sync for canfd_frame

§

impl Sync for canxl_frame

§

impl Sync for cpu_set_t

§

impl Sync for dirent64

§

impl Sync for dirent

§

impl Sync for dqblk

§

impl Sync for epoll_params

§

impl Sync for fanotify_event_info_fid

§

impl Sync for fanotify_event_info_header

§

impl Sync for fanotify_event_metadata

§

impl Sync for fanotify_response

§

impl Sync for fanout_args

§

impl Sync for ff_condition_effect

§

impl Sync for ff_constant_effect

§

impl Sync for ff_effect

§

impl Sync for ff_envelope

§

impl Sync for ff_ramp_effect

§

impl Sync for ff_replay

§

impl Sync for ff_rumble_effect

§

impl Sync for ff_trigger

§

impl Sync for file_clone_range

§

impl Sync for fsid_t

§

impl Sync for genlmsghdr

§

impl Sync for hwtstamp_config

§

impl Sync for in6_ifreq

§

impl Sync for in6_pktinfo

§

impl Sync for inotify_event

§

impl Sync for input_absinfo

§

impl Sync for input_event

§

impl Sync for input_id

§

impl Sync for input_keymap_entry

§

impl Sync for input_mask

§

impl Sync for itimerspec

§

impl Sync for iw_discarded

§

impl Sync for iw_encode_ext

§

impl Sync for iw_freq

§

impl Sync for iw_michaelmicfailure

§

impl Sync for iw_missed

§

impl Sync for iw_mlme

§

impl Sync for iw_param

§

impl Sync for iw_pmkid_cand

§

impl Sync for iw_pmksa

§

impl Sync for iw_priv_args

§

impl Sync for iw_quality

§

impl Sync for iw_range

§

impl Sync for iw_scan_req

§

impl Sync for iw_statistics

§

impl Sync for iw_thrspy

§

impl Sync for j1939_filter

§

impl Sync for mount_attr

§

impl Sync for mq_attr

§

impl Sync for msginfo

§

impl Sync for nlattr

§

impl Sync for nlmsgerr

§

impl Sync for nlmsghdr

§

impl Sync for open_how

§

impl Sync for packet_mreq

§

impl Sync for posix_spawnattr_t

§

impl Sync for pthread_barrier_t

§

impl Sync for pthread_barrierattr_t

§

impl Sync for pthread_cond_t

§

impl Sync for pthread_condattr_t

§

impl Sync for pthread_mutex_t

§

impl Sync for pthread_mutexattr_t

§

impl Sync for pthread_rwlock_t

§

impl Sync for pthread_rwlockattr_t

§

impl Sync for ptp_clock_caps

§

impl Sync for ptp_clock_time

§

impl Sync for ptp_extts_event

§

impl Sync for ptp_extts_request

§

impl Sync for ptp_perout_request

§

impl Sync for ptp_pin_desc

§

impl Sync for ptp_sys_offset

§

impl Sync for ptp_sys_offset_extended

§

impl Sync for ptp_sys_offset_precise

§

impl Sync for regmatch_t

§

impl Sync for rlimit64

§

impl Sync for sched_attr

§

impl Sync for sctp_authinfo

§

impl Sync for sctp_initmsg

§

impl Sync for sctp_nxtinfo

§

impl Sync for sctp_prinfo

§

impl Sync for sctp_rcvinfo

§

impl Sync for sctp_sndinfo

§

impl Sync for sctp_sndrcvinfo

§

impl Sync for seccomp_data

§

impl Sync for seccomp_notif

§

impl Sync for seccomp_notif_addfd

§

impl Sync for seccomp_notif_resp

§

impl Sync for seccomp_notif_sizes

§

impl Sync for sembuf

§

impl Sync for signalfd_siginfo

§

impl Sync for sock_extended_err

§

impl Sync for sock_filter

§

impl Sync for sock_txtime

§

impl Sync for sockaddr_alg

§

impl Sync for sockaddr_can

§

impl Sync for sockaddr_nl

§

impl Sync for sockaddr_pkt

§

impl Sync for sockaddr_vm

§

impl Sync for tls12_crypto_info_aes_gcm_128

§

impl Sync for tls12_crypto_info_aes_gcm_256

§

impl Sync for tls12_crypto_info_chacha20_poly1305

§

impl Sync for tls_crypto_info

§

impl Sync for tpacket2_hdr

§

impl Sync for tpacket3_hdr

§

impl Sync for tpacket_auxdata

§

impl Sync for tpacket_bd_ts

§

impl Sync for tpacket_block_desc

§

impl Sync for tpacket_hdr

§

impl Sync for tpacket_hdr_v1

§

impl Sync for tpacket_hdr_variant1

§

impl Sync for tpacket_req3

§

impl Sync for tpacket_req

§

impl Sync for tpacket_rollover_stats

§

impl Sync for tpacket_stats

§

impl Sync for tpacket_stats_v3

§

impl Sync for ucred

§

impl Sync for uinput_abs_setup

§

impl Sync for uinput_ff_erase

§

impl Sync for uinput_ff_upload

§

impl Sync for uinput_setup

§

impl Sync for uinput_user_dev

§

impl Sync for xsk_tx_metadata

§

impl Sync for xsk_tx_metadata_completion

§

impl Sync for xsk_tx_metadata_request

§

impl Sync for arphdr

§

impl Sync for arpreq

§

impl Sync for arpreq_old

§

impl Sync for epoll_event

§

impl Sync for fd_set

§

impl Sync for in6_rtmsg

§

impl Sync for in_addr

§

impl Sync for in_pktinfo

§

impl Sync for ip_mreq

§

impl Sync for ip_mreq_source

§

impl Sync for ip_mreqn

§

impl Sync for sched_param

§

impl Sync for sockaddr

§

impl Sync for sockaddr_in6

§

impl Sync for sockaddr_in

§

impl Sync for sockaddr_ll

§

impl Sync for sockaddr_storage

§

impl Sync for sockaddr_un

§

impl Sync for statx

§

impl Sync for statx_timestamp

§

impl Sync for utsname

§

impl Sync for in6_addr

§

impl Sync for ipv6_mreq

§

impl Sync for itimerval

§

impl Sync for linger

§

impl Sync for pollfd

§

impl Sync for rlimit

§

impl Sync for rusage

§

impl Sync for timespec

§

impl Sync for timeval

§

impl Sync for tms

§

impl Sync for utimbuf

§

impl Sync for winsize

§

impl Sync for Error

§

impl Sync for SipHasher

§

impl Sync for Assume

§

impl Sync for __c_anonymous_ptrace_syscall_info_data

§

impl Sync for __c_anonymous_iwreq

§

impl Sync for __c_anonymous_ptp_perout_request_1

§

impl Sync for __c_anonymous_ptp_perout_request_2

§

impl Sync for __c_anonymous_sockaddr_can_can_addr

§

impl Sync for __c_anonymous_xsk_tx_metadata_union

§

impl Sync for tpacket_bd_header_u

§

impl Sync for tpacket_req_u

§

impl<'a> !Sync for Formatter<'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, I> Sync for ByRefSized<'a, I>
where I: Sync,

§

impl<A> Sync for Repeat<A>
where A: Sync,

§

impl<A> Sync for RepeatN<A>
where A: Sync,

§

impl<A, B> Sync for Chain<A, B>
where A: Sync, B: Sync,

§

impl<A, B> Sync for Zip<A, B>
where A: Sync, B: Sync,

§

impl<F> Sync for libc::prelude::fmt::FromFn<F>
where F: Sync,

§

impl<F> Sync for libc::prelude::iter::FromFn<F>
where F: Sync,

§

impl<F> Sync for OnceWith<F>
where F: Sync,

§

impl<F> Sync for RepeatWith<F>
where F: Sync,

§

impl<H> Sync for BuildHasherDefault<H>

§

impl<I> Sync for Cloned<I>
where I: Sync,

§

impl<I> Sync for Copied<I>
where I: Sync,

§

impl<I> Sync for Cycle<I>
where I: Sync,

§

impl<I> Sync for Enumerate<I>
where I: Sync,

§

impl<I> Sync for Flatten<I>
where <<I as Iterator>::Item as IntoIterator>::IntoIter: Sync, I: Sync,

§

impl<I> Sync for Fuse<I>
where I: Sync,

§

impl<I> Sync for Intersperse<I>
where <I as Iterator>::Item: Sized + Sync, I: Sync,

§

impl<I> Sync for Peekable<I>
where I: Sync, <I as Iterator>::Item: Sync,

§

impl<I> Sync for Skip<I>
where I: Sync,

§

impl<I> Sync for StepBy<I>
where I: Sync,

§

impl<I> Sync for Take<I>
where I: Sync,

§

impl<I, F> Sync for FilterMap<I, F>
where I: Sync, F: Sync,

§

impl<I, F> Sync for Inspect<I, F>
where I: Sync, F: Sync,

§

impl<I, F> Sync for Map<I, F>
where I: Sync, F: Sync,

§

impl<I, F, const N: usize> Sync for MapWindows<I, F, N>
where F: Sync, I: Sync, <I as Iterator>::Item: Sync,

§

impl<I, G> Sync for IntersperseWith<I, G>
where G: Sync, <I as Iterator>::Item: Sync, I: Sync,

§

impl<I, P> Sync for Filter<I, P>
where I: Sync, P: Sync,

§

impl<I, P> Sync for MapWhile<I, P>
where I: Sync, P: Sync,

§

impl<I, P> Sync for SkipWhile<I, P>
where I: Sync, P: Sync,

§

impl<I, P> Sync for TakeWhile<I, P>
where I: Sync, P: Sync,

§

impl<I, St, F> Sync for Scan<I, St, F>
where I: Sync, F: Sync, St: Sync,

§

impl<I, U, F> Sync for FlatMap<I, U, F>
where <U as IntoIterator>::IntoIter: Sync, I: Sync, F: Sync,

§

impl<I, const N: usize> Sync for ArrayChunks<I, N>
where I: Sync, <I as Iterator>::Item: Sync,

§

impl<T> Sync for Option<T>
where T: Sync,

§

impl<T> Sync for Empty<T>

§

impl<T> Sync for Once<T>
where T: Sync,

§

impl<T> Sync for Rev<T>
where T: Sync,

§

impl<T> Sync for Discriminant<T>

§

impl<T> Sync for ManuallyDrop<T>
where T: Sync + ?Sized,

§

impl<T> Sync for MaybeUninit<T>
where T: Sync,

§

impl<T, F> Sync for Successors<T, F>
where F: Sync, T: Sync,