Trait nom::lib::std::prelude::v1::rust_2021::Drop1.0.0[][src]

#[lang = "drop"]pub trait Drop {
    pub fn drop(&mut self);
}
[]

Custom code within the destructor.

When a value is no longer needed, Rust will run a “destructor” on that value. The most common way that a value is no longer needed is when it goes out of scope. Destructors may still run in other circumstances, but we’re going to focus on scope for the examples here. To learn about some of those other cases, please see the reference section on destructors.

This destructor consists of two components:

As Rust automatically calls the destructors of all contained fields, you don’t have to implement Drop in most cases. But there are some cases where it is useful, for example for types which directly manage a resource. That resource may be memory, it may be a file descriptor, it may be a network socket. Once a value of that type is no longer going to be used, it should “clean up” its resource by freeing the memory or closing the file or socket. This is the job of a destructor, and therefore the job of Drop::drop.

Examples

To see destructors in action, let’s take a look at the following program:

struct HasDrop;

impl Drop for HasDrop {
    fn drop(&mut self) {
        println!("Dropping HasDrop!");
    }
}

struct HasTwoDrops {
    one: HasDrop,
    two: HasDrop,
}

impl Drop for HasTwoDrops {
    fn drop(&mut self) {
        println!("Dropping HasTwoDrops!");
    }
}

fn main() {
    let _x = HasTwoDrops { one: HasDrop, two: HasDrop };
    println!("Running!");
}

Rust will first call Drop::drop for _x and then for both _x.one and _x.two, meaning that running this will print

Running!
Dropping HasTwoDrops!
Dropping HasDrop!
Dropping HasDrop!

Even if we remove the implementation of Drop for HasTwoDrop, the destructors of its fields are still called. This would result in

Running!
Dropping HasDrop!
Dropping HasDrop!

You cannot call Drop::drop yourself

Because Drop::drop is used to clean up a value, it may be dangerous to use this value after the method has been called. As Drop::drop does not take ownership of its input, Rust prevents misuse by not allowing you to call Drop::drop directly.

In other words, if you tried to explicitly call Drop::drop in the above example, you’d get a compiler error.

If you’d like explicitly call the destructor of a value, mem::drop can be used instead.

Drop order

Which of our two HasDrop drops first, though? For structs, it’s the same order that they’re declared: first one, then two. If you’d like to try this yourself, you can modify HasDrop above to contain some data, like an integer, and then use it in the println! inside of Drop. This behavior is guaranteed by the language.

Unlike for structs, local variables are dropped in reverse order:

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        println!("Dropping Foo!")
    }
}

struct Bar;

impl Drop for Bar {
    fn drop(&mut self) {
        println!("Dropping Bar!")
    }
}

fn main() {
    let _foo = Foo;
    let _bar = Bar;
}

This will print

Dropping Bar!
Dropping Foo!

Please see the reference for the full rules.

Copy and Drop are exclusive

You cannot implement both Copy and Drop on the same type. Types that are Copy get implicitly duplicated by the compiler, making it very hard to predict when, and how often destructors will be executed. As such, these types cannot have destructors.

Required methods

pub fn drop(&mut self)[src][]

Executes the destructor for this type.

This method is called implicitly when the value goes out of scope, and cannot be called explicitly (this is compiler error E0040). However, the mem::drop function in the prelude can be used to call the argument’s Drop implementation.

When this method has been called, self has not yet been deallocated. That only happens after the method is over. If this wasn’t the case, self would be a dangling reference.

Panics

Given that a panic! will call drop as it unwinds, any panic! in a drop implementation will likely abort.

Note that even if this panics, the value is considered to be dropped; you must not cause drop to be called again. This is normally automatically handled by the compiler, but when using unsafe code, can sometimes occur unintentionally, particularly when using ptr::drop_in_place.

Implementations on Foreign Types

impl Drop for CString[src][]

impl<'_, T> Drop for RwLockReadGuard<'_, T> where
    T: ?Sized
[src][]

impl<W> Drop for BufWriter<W> where
    W: Write
[src][]

impl<T> Drop for RwLock<T> where
    T: ?Sized
[src][]

impl<'_, T> Drop for RwLockWriteGuard<'_, T> where
    T: ?Sized
[src][]

impl<T> Drop for Receiver<T>[src][]

impl<'_, T> Drop for MutexGuard<'_, T> where
    T: ?Sized
[src][]

impl<T> Drop for SyncOnceCell<T>[src][]

impl<T> Drop for Sender<T>[src][]

impl<T> Drop for SyncSender<T>[src][]

impl Drop for Waker[src][]

impl<'f> Drop for VaListImpl<'f>[src][]

impl<T, const N: usize> Drop for IntoIter<T, N>[src][]

impl<T> Drop for Arc<T> where
    T: ?Sized
[src][]

pub fn drop(&mut self)[src][]

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, 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!"

impl<T> Drop for Weak<T> where
    T: ?Sized
[src][]

pub fn drop(&mut self)[src][]

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());

impl<T> Drop for Weak<T> where
    T: ?Sized
[src][]

pub fn drop(&mut self)[src][]

Drops the Weak pointer.

Examples

use std::rc::{Rc, Weak};

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        println!("dropped!");
    }
}

let foo = Rc::new(Foo);
let weak_foo = Rc::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());

impl<T> Drop for Rc<T> where
    T: ?Sized
[src][]

pub fn drop(&mut self)[src][]

Drops the Rc.

This will decrement the strong reference count. If the strong reference count reaches zero then the only other references (if any) are Weak, so we drop the inner value.

Examples

use std::rc::Rc;

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        println!("dropped!");
    }
}

let foo  = Rc::new(Foo);
let foo2 = Rc::clone(&foo);

drop(foo);    // Doesn't print anything
drop(foo2);   // Prints "dropped!"

Implementors

impl<'_> Drop for nom::lib::std::string::Drain<'_>1.6.0[src][+]

impl<'_, I, A> Drop for Splice<'_, I, A> where
    I: Iterator,
    A: Allocator
1.21.0[src][+]

impl<'_, K, V, F> Drop for nom::lib::std::collections::btree_map::DrainFilter<'_, K, V, F> where
    F: FnMut(&K, &mut V) -> bool
[src][+]

impl<'_, T> Drop for PeekMut<'_, T> where
    T: Ord
1.12.0[src][+]

impl<'_, T> Drop for nom::lib::std::collections::vec_deque::Drain<'_, T>1.6.0[src][+]

impl<'_, T, A> Drop for nom::lib::std::vec::Drain<'_, T, A> where
    A: Allocator
1.6.0[src][+]

impl<'_, T, F> Drop for nom::lib::std::collections::btree_set::DrainFilter<'_, T, F> where
    F: FnMut(&T) -> bool
[src][+]

impl<'_, T, F> Drop for nom::lib::std::collections::linked_list::DrainFilter<'_, T, F> where
    F: FnMut(&mut T) -> bool
[src][+]

impl<'_, T, F, A> Drop for nom::lib::std::vec::DrainFilter<'_, T, F, A> where
    F: FnMut(&mut T) -> bool,
    A: Allocator
[src][+]

impl<'a, T> Drop for DrainSorted<'a, T> where
    T: Ord
[src][+]

pub fn drop(&mut self)[src][]

Removes heap elements in heap order.

impl<K, V> Drop for nom::lib::std::collections::btree_map::IntoIter<K, V>1.7.0[src][+]

impl<K, V> Drop for BTreeMap<K, V>1.7.0[src][+]

impl<T> Drop for LinkedList<T>[src][+]

impl<T> Drop for VecDeque<T>[src][+]

impl<T, A> Drop for Box<T, A> where
    T: ?Sized,
    A: Allocator
[src][+]

impl<T, A> Drop for nom::lib::std::vec::IntoIter<T, A> where
    A: Allocator
[src][+]

impl<T, A> Drop for Vec<T, A> where
    A: Allocator
[src][+]

impl Drop for Error

impl<'a, T: RefCnt> Drop for Guard<'a, T>

impl<T: RefCnt, S: LockStorage> Drop for ArcSwapAny<T, S>

impl<A: Array> Drop for ArrayVec<A>

impl<A: Array> Drop for IntoIter<A>

impl<'a, A: Array> Drop for Drain<'a, A> where
    A::Item: 'a, 

impl Drop for BacktraceFrameFmt<'_, '_, '_>

impl<'a, W: Write> Drop for EncoderWriter<'a, W>

impl<N> Drop for FsmState<N>

impl Drop for Bytes

impl Drop for BytesMut

impl Drop for Pending

impl Drop for KeyHandle

impl Drop for KeyHandleGuard

impl<T> Drop for Sender<T>

impl<T> Drop for Receiver<T>

impl Drop for SelectedOperation<'_>

impl<T> Drop for Injector<T>

impl<T: ?Sized + Pointable> Drop for Owned<T>

impl Drop for LocalHandle

impl Drop for Guard

impl<T> Drop for ArrayQueue<T>

impl<T> Drop for SegQueue<T>

impl<K, V> Drop for SkipList<K, V>

impl<K, V> Drop for IntoIter<K, V>

impl<K, V> Drop for Entry<'_, K, V>

impl<T: ?Sized> Drop for ShardedLockWriteGuard<'_, T>

impl Drop for WaitGroup

impl<'rwlock, T: ?Sized> Drop for RwLockReadGuard<'rwlock, T>

impl<'rwlock, T: ?Sized> Drop for RwLockUpgradeableGuard<'rwlock, T>

impl<'rwlock, T: ?Sized> Drop for RwLockWriteGuard<'rwlock, T>

impl<W: Write> Drop for EncrypterWriter<W>

impl Drop for DataKeyManager

impl Drop for RocksSnapshot

impl<'a> Drop for FailScenario<'a>

impl Drop for WithIOType

impl<W: Write> Drop for GzEncoder<W>

impl<T> Drop for Receiver<T>

impl<T> Drop for UnboundedReceiver<T>

impl<T> Drop for Sender<T>

impl<T> Drop for Receiver<T>

impl Drop for ThreadPool

impl Drop for Enter

impl<T> Drop for LocalFutureObj<'_, T>

impl Drop for Delay

impl<Fut> Drop for Shared<Fut> where
    Fut: Future

impl<Fut> Drop for FuturesUnordered<Fut>

impl<T: ?Sized> Drop for MutexLockFuture<'_, T>

impl<T: ?Sized> Drop for MutexGuard<'_, T>

impl<T: ?Sized, U: ?Sized> Drop for MappedMutexGuard<'_, T, U>

impl<T, N> Drop for GenericArrayIter<T, N> where
    N: ArrayLength<T>, 

impl Drop for AuthContext

impl Drop for GrpcSlice

impl<T> Drop for ClientCStreamReceiver<T>

impl<P> Drop for StreamingCallSink<P>

impl<Resp> Drop for ClientDuplexReceiver<Resp>

impl<T> Drop for RequestStream<T>

impl<T> Drop for UnarySink<T>

impl<T> Drop for ClientStreamingSink<T>

impl<T> Drop for ServerStreamingSink<T>

impl<T> Drop for DuplexSink<T>

impl Drop for Environment

impl Drop for Metadata

impl Drop for ResourceQuota

impl Drop for ServerCredentialsBuilder

impl Drop for ServerCredentials

impl Drop for ChannelCredentialsBuilder

impl Drop for ChannelCredentials

impl Drop for Server

impl Drop for RecvStream

impl<'a, T> Drop for Drain<'a, T>

impl<T> Drop for IntoIter<T>

impl<'a, T> Drop for ValueDrain<'a, T>

impl<'a, K, I, F> Drop for Group<'a, K, I, F> where
    I: Iterator,
    I::Item: 'a, 

impl<'a, I> Drop for Chunk<'a, I> where
    I: Iterator,
    I::Item: 'a, 

impl<T: Complete> Drop for AutoFinish<T>

impl<T: Complete> Drop for AutoFinishUnchecked<T>

impl Drop for Library

impl<K, V, S> Drop for LinkedHashMap<K, V, S>

impl<K, V> Drop for IntoIter<K, V>

impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Drop for MutexGuard<'a, R, T>

impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Drop for MappedMutexGuard<'a, R, T>

impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> Drop for ReentrantMutexGuard<'a, R, G, T>

impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> Drop for MappedReentrantMutexGuard<'a, R, G, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Drop for RwLockReadGuard<'a, R, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Drop for RwLockWriteGuard<'a, R, T>

impl<'a, R: RawRwLockUpgrade + 'a, T: ?Sized + 'a> Drop for RwLockUpgradableReadGuard<'a, R, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Drop for MappedRwLockReadGuard<'a, R, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Drop for MappedRwLockWriteGuard<'a, R, T>

impl Drop for Registration

impl Drop for Dir

impl<'d> Drop for Iter<'d>

impl Drop for InterfaceAddressIterator

impl Drop for PtyMaster

impl<'a> Drop for AioCb<'a>

impl Drop for SignalFd

impl<T> Drop for NoDrop<T>

impl Drop for INotifyWatcher

impl Drop for PollWatcher

impl<T> Drop for OnceBox<T>

impl Drop for Asn1GeneralizedTime

impl Drop for Asn1Time

impl Drop for Asn1String

impl Drop for Asn1Integer

impl Drop for Asn1BitString

impl Drop for Asn1Object

impl Drop for BigNumContext

impl Drop for BigNum

impl Drop for CmsContentInfo

impl Drop for Conf

impl<T> Drop for Dh<T>

impl<T> Drop for Dsa<T>

impl Drop for EcGroup

impl Drop for EcPoint

impl<T> Drop for EcKey<T>

impl Drop for EcdsaSig

impl Drop for Seal

impl Drop for Open

impl Drop for Hasher

impl Drop for OcspBasicResponse

impl Drop for OcspCertId

impl Drop for OcspResponse

impl Drop for OcspRequest

impl Drop for OcspOneReq

impl Drop for Pkcs12

impl Drop for Pkcs7

impl<T> Drop for PKey<T>

impl<T> Drop for Rsa<T>

impl<'a> Drop for Signer<'a>

impl<'a> Drop for Verifier<'a>

impl Drop for SrtpProtectionProfile

impl Drop for SslContext

impl Drop for SslSession

impl Drop for Ssl

impl<S> Drop for SslStream<S>

impl<T: Stackable> Drop for Stack<T>

impl<T: Stackable> Drop for IntoIter<T>

impl Drop for OpensslString

impl Drop for Crypter

impl Drop for X509VerifyParam

impl Drop for X509StoreBuilder

impl Drop for X509Store

impl Drop for X509StoreContext

impl Drop for X509

impl Drop for X509Extension

impl Drop for X509Name

impl Drop for X509NameEntry

impl Drop for X509Req

impl Drop for GeneralName

impl Drop for X509Algorithm

impl Drop for FileDesc

impl<'a> Drop for ProfilerGuard<'a>

impl Drop for HistogramTimer

impl Drop for LocalHistogramTimer

impl Drop for LocalHistogram

impl<S> Drop for PendingCmd<S> where
    S: Snapshot

impl<S: Snapshot> Drop for Apply<S>

impl<EK> Drop for ApplyFsm<EK> where
    EK: KvEngine

impl<EK> Drop for ApplyRouter<EK> where
    EK: KvEngine

impl<EK, ER> Drop for PeerFsm<EK, ER> where
    EK: KvEngine,
    ER: RaftEngine

impl<EK, ER> Drop for RaftRouter<EK, ER> where
    EK: KvEngine,
    ER: RaftEngine

impl<S: Snapshot> Drop for CmdEpochChecker<S>

impl Drop for EntryCache

impl<S> Drop for ReadIndexRequest<S> where
    S: Snapshot

impl Drop for Snap

impl Drop for ReadDelegate

impl<'a, T: Ord + Send> Drop for Drain<'a, T>

impl<'a, T: Send> Drop for Drain<'a, T>

impl<'a> Drop for Drain<'a>

impl<'data, T: Send> Drop for Drain<'data, T>

impl Drop for ThreadPool

impl Drop for Ast

impl Drop for ClassSet

impl Drop for Hir

impl Drop for CompactionFilterHandle

impl Drop for CompactionFilterFactoryHandle

impl Drop for ColumnFamilyMetaData

impl Drop for CFHandle

impl Drop for MapProperty

impl<D> Drop for DBIterator<D>

impl<D: Deref<Target = DB>> Drop for Snapshot<D>

impl Drop for DB

impl Drop for DBVector

impl Drop for BackupEngine

impl Drop for SstFileReader

impl Drop for SstFileWriter

impl Drop for ExternalSstFileInfo

impl Drop for Env

impl Drop for SequentialFile

impl Drop for Cache

impl Drop for MemoryAllocator

impl Drop for BlockBasedOptions

impl Drop for RateLimiter

impl Drop for ReadOptions

impl Drop for WriteOptions

impl Drop for CompactOptions

impl Drop for CompactionOptions

impl Drop for DBOptions

impl Drop for ColumnFamilyOptions

impl Drop for CColumnFamilyDescriptor

impl Drop for FlushOptions

impl Drop for IngestExternalFileOptions

impl Drop for EnvOptions

impl Drop for RestoreOptions

impl Drop for FifoCompactionOptions

impl Drop for LRUCacheOptions

impl Drop for TablePropertiesCollection

impl Drop for TitanDBOptions

impl<'a> Drop for WriteBatchIter<'a>

impl Drop for WriteBatch

impl Drop for Secret

impl<T, F, S> Drop for ScopeGuard<T, F, S> where
    F: FnOnce(T),
    S: Strategy

impl Drop for Trap

impl<'a> Drop for PushFnValueSerializer<'a>

impl Drop for AsyncGuard

impl Drop for AsyncCore

impl Drop for Async

impl<'a, W> Drop for PlainRecordDecorator<'a, W> where
    W: Write

impl<W> Drop for PlainSyncRecordDecorator<W> where
    W: Write

impl<'a> Drop for TermRecordDecorator<'a>

impl<'a, T: 'a + Array> Drop for Drain<'a, T>

impl<A: Array> Drop for SmallVec<A>

impl<A: Array> Drop for IntoIter<A>

impl<'a, T: ?Sized> Drop for MutexGuard<'a, T>

impl<'rwlock, T: ?Sized> Drop for RwLockReadGuard<'rwlock, T>

impl<'rwlock, T: ?Sized> Drop for RwLockUpgradeableGuard<'rwlock, T>

impl<'rwlock, T: ?Sized> Drop for RwLockWriteGuard<'rwlock, T>

impl Drop for ImportFile

impl<'a> Drop for Writer<'a>

impl<'a> Drop for ParseBuffer<'a>

impl Drop for Process

impl<'c, 'm, T: 'm, F: FnOnce() -> T> Drop for Hole<'c, 'm, T, F>

impl Drop for TempDir

impl Drop for TempPath

impl<T: Simulator> Drop for Cluster<T>

impl Drop for CaseTraceLogger

impl<H: TestHook> Drop for CaseLifeWatcher<H>

impl<T: Send> Drop for ThreadLocal<T>

impl Drop for Tracker

impl Drop for AppliedLockCollector

impl Drop for WriteCompactionFilter

impl<E, RR> Drop for GcWorker<E, RR> where
    E: Engine,
    RR: RaftStoreRouter<RocksEngine> + 'static, 

impl Drop for ProfGuard

impl<I: Iterator> Drop for TTLIterator<I>

impl Drop for CmdTimer

impl<E: Engine, L: LockManager> Drop for Storage<E, L>

impl Drop for ExpectedWriteList

impl Drop for RocksEngineCore

impl Drop for StatsCollector<'_>

impl<T, C, A> Drop for MustCall<T, C, A> where
    C: FnOnce(T),
    A: FnOnce() -> T, 

impl Drop for RotatingFileLogger

impl<'a> Drop for Serializer<'a>

impl<K, V> Drop for LruCache<K, V>

impl Drop for State

impl Drop for Notifier

impl<T> Drop for Sender<T>

impl<T> Drop for Sender<T>

impl<T> Drop for Receiver<T>

impl Drop for Monitor

impl<R: Runnable + 'static> Drop for RunnableWrapper<R>

impl<T: FnOnce()> Drop for DeferContext<T>

impl<T> Drop for MustConsumeVec<T>

impl<E: Evented> Drop for PollEvented<E>

impl Drop for Registration

impl Drop for DuplexStream

impl Drop for OwnedWriteHalf

impl Drop for OwnedSendHalf

impl Drop for OwnedWriteHalf

impl<T> Drop for JoinHandle<T>

impl<T> Drop for Sender<T>

impl<T> Drop for Receiver<T>

impl<T: ?Sized> Drop for MutexGuard<'_, T>

impl<T: ?Sized> Drop for OwnedMutexGuard<T>

impl<T> Drop for Sender<T>

impl<T> Drop for Receiver<T>

impl<'a> Drop for SemaphorePermit<'_>

impl Drop for OwnedSemaphorePermit

impl<'a, T: ?Sized> Drop for RwLockReadGuard<'a, T>

impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T>

impl<T> Drop for Receiver<T>

impl<T> Drop for Sender<T>

impl Drop for LocalSet

impl Drop for Enter

impl Drop for DefaultGuard

impl Drop for DefaultGuard

impl Drop for DefaultGuard

impl<T, N> Drop for Timer<T, N>

impl Drop for Span

impl<'a> Drop for Entered<'a>

impl Drop for EnteredSpan

impl Drop for DefaultGuard

impl<'a, T> Drop for Locked<'a, T>

impl<'a> Drop for PathSegmentsMut<'a>

impl<'a> Drop for UrlQuery<'a>

impl Drop for Taker

impl<T: TaskCell + Send> Drop for ThreadPool<T>

impl<Z> Drop for Zeroizing<Z> where
    Z: Zeroize