Files
boc/aamos-ledger-rust/target/debug/deps/libscopeguard-29f0bdb2ea82739e.rmeta
T

43 lines
21 KiB
Plaintext
Raw Normal View History

rust
ÚS#rustc 1.96.0 (ac68faa20 2026-05-25)ÁíàÄTËŸ ÜJîÄ)'ß\¥!-3d1337db07d0b3aeÁ¤°ð ¾ä-±($²ï=©Ã-7e98a21bfd32b0edÁOnUnwindÁDÀ6»use_stdÁœ6 OnSuccessÁLà7»žœ°7defer_on_successÁ„§?»žœô>defer_on_unwindÁ|²B»žœÿAguard_on_successÁ„”[»žœáZguard_on_unwindÁ|öb»žœÃbtestsÁ,¤n$™níÀStrategyÁ 
should_runÁ
¾deferÁ
ScopeGuardÁ¥¤»dropfnÁstrategyÁ¥¤
with_strategyÁ
into_innerÁ£¥ ¥  ¤$¥$$¤$å$´*¥**¤*/¥//¤/ã4¥44¤4×AlwaysÁ:×)
.
3
8
8
8
;
;
;
 ¿c9u+Æøõd à æ» Ü'6šÞ¬h¥¤é!ö!Œ"¿c:94
9 $*/¿c# 
 é!ö!Œ" 9íÀÍ0×Ü0 ` PhantomDataÁ\ò0ù  ManuallyDropÁd1ÃÛr,ª1é!DerefMutÁD±1ö! µ Å1
Ú,±<üò…ütEB A scope guard will run a given closure when it goes out of scope,Áüº$! even if the code between panics.Áüß$! (as long as panic doesn't abort)Áútˆ # ExamplesÁú”› ## Hello WorldÁ®úü²@= This example creates a scope guard with an example function:Áóú ```Áäÿ extern crate scopeguard;Áœúd  fn f() {Áü­0- let _guard = scopeguard::guard((), |_| {ÁüÞ*' println!("Hello Scope Exit!");Á\‰ });Áúü™! // rest of the code here.Á»úü¿OL // Here, at the end of `_guard`'s scope, the guard's closure is called.ÁüMJ // It is also called if we exit this scope through unwinding instead.ÁŒã # fn main() {Á
# f();Á # }Á<þ ú|— ## `defer!`Á§úü«<9 Use the `defer` macro to run an operation at scope exit,Áüè?< either regular scope exit or during unwinding from a panic.Á¨úþ ü´0- #[macro_use(defer)] extern crate scopeguard;ÁåúÄé use std::cell::Cell;Áú|† fn main() {Áü–QN // use a cell to observe drops during and after the scope guard is activeÁüè(% let drop_counter = Cell::new(0);ÁL ü› HE // Create a scope guard using `defer!` for the current scopeÁ¤ä  defer! {Áüù 96 drop_counter.set(1 + drop_counter.get());Á
Á
úüÅ
:7 // Do regular operations here in the meantime.Á úü„ 96 // Just before scope exit: it hasn't run yet.Áü¾ .+ assert_eq!(drop_counter.get(), 0);Áí úüñ KH // The following scope end is where the defer closure is calledÁ üÇ *' assert_eq!(drop_counter.get(), 1);Á É þ 
úì„
 ## Scope Guard with ValueÁ¢
úü¦
JG If the scope guard closure needs to access an outer value that is alsoÁüñ
PM mutated outside of the scope guard, then you may want to use the scope guardÁüÂNK with a value. The guard works like a smart pointer, so the inner value canÁü‘52 be accessed by reference or by mutable reference.ÁÇúüË  ### 1. The guard owns a fileÁìúüðOL In this example, the scope guard owns a file and ensures pending writes areÁÌÀ synced at scope exit.ÁÚúþ äæŽ
ƒúœ‡ use std::fs::*;Áü› use std::io::{self, Write};Áü»96 # // Mock file so that we don't actually write a fileÁ´õ # struct MockFile;Á¬Œ # impl MockFile {Áü¢B? # fn create(_s: &str) -> io::Result<Self> { Ok(MockFile) }ÁüåEB # fn write_all(&self, _b: &[u8]) -> io::Result<()> { Ok(()) }Áü«96 # fn sync_all(&self) -> io::Result<()> { Ok(()) }Áüí! # use self::MockFile as File;Áúü“%" fn try_main() -> io::Result<()> {Áü¹-* let f = File::create("newfile.txt")?;Áüç1. let mut file = scopeguard::guard(f, |f| {Áü™63 // ensure we flush file at return or panicÁüÐ! let _ = f.sync_all();ÁÂüþ96 // Access the file through the scope guard itselfÁü¸0- file.write_all(b"test me\n").map(|_| ())ÁÉïúíäƒ try_main().unwrap();Á, É¦úþ ²úü¶85 ### 2. The guard restores an invariant on scope exitÁïúþ äûŽ
˜úüœ use std::mem::ManuallyDrop;ÁŒ¼ use std::ptr;ÁÎúüÒDA // This function, just for this example, takes the first elementÁü—A> // and inserts it into the assumed sorted tail of the vector.Á //ÁüàKH // For optimization purposes we temporarily violate an invariant of theÁü¬-* // Vec, that it owns all of its elements.ÁÀ)üáJG // The safe approach is to use swap, which means two writes to memory,Áü¬RO // the optimization is to use a “hole†which uses only one write of memoryÁüÿ" // for each position it moves.ÁÀ)ü©>; // We *must* use a scope guard to run this code safely. WeÁüèMJ // are running arbitrary user code (comparison operators) that may panic.Áü¶HE // The scope guard ensures we restore the invariant after successfulÁüÿ+( // exit or during unwinding from panic.Áü«.+ fn insertion_sort_first<T>(v: &mut Vec<T>)ÁÜÚ where T: PartialOrdÁüü  struct Hole<'a, T: 'a> {Áô v: &'a mut Vec<T>,Á̼ index: usize,ÁüÖ# value: ManuallyDrop<T>,Á¤ú„ˆ
unsafe {Áü™ HE // Create a moved-from location in the vector, a “holeâ€üâ )& let value = ptr::read(&v[0]);ÁüŒ!TQ let mut hole = Hole { v: v, index: 0, value: ManuallyDrop::new(value) };Áá!úüå!.+ // Use a scope guard with a value.Áü”"GD // At scope exit, plug the hole so that the vector is fullyÁüÜ"! // initialized again.Áüþ"UR // The scope guard owns the hole, but we can access it through the guard.ÁüÔ#A> let mut hole_guard = scopeguard::guard(hole, |hole| {Áü–$SP // plug the hole in the vector with the value that was // taken outÁüê$'$ let index =
Ú Fĸ0VD×0hÄå0´ƒ1¸DŸ1ËËææDÀ1ù”‰2üË1=: Controls in which cases the associated code should be runÁD“2  Îìü‰2« ÕHÕH  Äš3ü¢2=: Return `true` if the guard’s associated code should runÁüä21. (in the context where this method is called).ÁT3 
ÝHÄî7à ¼£8T¦8

”¤<üó:0- Macro to create a `ScopeGuard` (always run).Á¤;úü¨;?< The macro takes statements, which are the body of a closureÁüè;+( that will run when the scope is exited.Á(|”<  ·< Ž= ½< Ç<, ¾< ¿< Å<, À<8¿ Á<& Â<8¯Ã<
Æ<*É< Ì< = 8Ö<8_guardÁ4Ú< á<, ã<8,ä<'é<8£,ë< ð< „= ñ< ò<$ ó< õ< ö< ÷< ø< ú< ƒ=, ü< ý< €=, þ<8¿ ÿ<
=% …=% Œ=üðG'ü¦CA> `ScopeGuard` is a scope guard that may own a protected value.ÁèCúüìC=: If you place a guard in a local variable, the closure canÁüªDNK run regardless how you leave the scope — through regular return or panicÁüùDJG (except if panic or other code aborts; so as long as destructors run).ÁÄÄE It is run only once.ÁÝEúüáEIF The `S` parameter for [`Strategy`](trait.Strategy.html) determines ifÁô«F the closure actually runs.ÁÊFúüÎFMJ The guard's closure will be called with the held value in the destructor.ÁœGúü GOL The `ScopeGuard` implements `Deref` so that you can access the inner value.ÁTûG¥¤Íìà †HÍìÉ ‰HÍìÏTŒH"ÉÃL¥HÉÃU˜" ÏD·HÜ'6šÞ¬h3tvqsn ŒHà´ÇH,ÇHÃÛÃÛª ÅÛ»¬µÜÀ,%*üãH4ãHÃÛÃÛª ÅÛ»¬µÜÀ,%*ÉüÔI!DÔIùFu\»ŸÏÏüúIJ¥¤ÍUL©J™U ‚J©U …J¹U‰U ÿIßUD»J248:üºL<üËJLI Create a `ScopeGuard` that owns `v` (accessible through deref) and callsÁüœK&# `dropfn` when its destructor runs.ÁÇKúüÏKHE The `Strategy` decides whether the scope guard's closure should run.Á.\ªLlÁLÃÉ
ÃÉÏÁ ÏL4ÕLüâS#üžNMJ “Defuse†the guard and extract the value without calling the closure.ÁðNú<øNþ ä„OŽ
¥Oúü­O(% use scopeguard::{guard, ScopeGuard};ÁÚOúüâO%" fn conditional() -> bool { true }ÁŒPú|”Píü¨P=: let mut guard = guard(Vec::new(), |mut v| v.clear());Á´êP guard.push(1);Á…QúÔQ if conditional() {Áü¬Q30 // a condition maybe makes us decide toÁüäQB? // “defuse†the guard and get back its inner partsÁü«R63 let value = ScopeGuard::into_inner(guard);Á„æR
} else {ÁüûR0- // guard still exists in this branchÁL°S¤,¾SÉ<ÈSþ TéSÃ
ÃÉÏ£,ôSüÞXWüûWLI Create a new `ScopeGuard` owning `v` and with deferred closure `dropfn`.Á.\ÒX,åXÃÉæ» Ü'6šÞ¬hÃÉॉU ëX™U îX¹UL«YÍU