From 4e834eba4841508b8ced2673b6a5c0ec9bb99edb Mon Sep 17 00:00:00 2001 From: Tristan <122918260+TAdev0@users.noreply.github.com> Date: Fri, 3 Jan 2025 19:00:45 +0100 Subject: [PATCH] Core Lib Documentation: `Gas` module (#6967) Co-authored-by: Mathieu <60658558+enitrat@users.noreply.github.com> --- corelib/src/gas.cairo | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/corelib/src/gas.cairo b/corelib/src/gas.cairo index ffe943b1e3b..cd1d778d2e7 100644 --- a/corelib/src/gas.cairo +++ b/corelib/src/gas.cairo @@ -1,3 +1,5 @@ +//! Utilities for handling gas in Cairo code. + #[cfg(not(gas: "disabled"))] use crate::RangeCheck; @@ -20,12 +22,15 @@ pub extern type GasBuiltin; /// Returns `Option::Some(())` if there is sufficient gas to handle the success case, otherwise /// returns `Option::None`. /// -/// Example: +/// # Examples +/// /// ``` /// // The success branch is the following lines, the failure branch is the `panic` caused by the /// // `unwrap` call. /// withdraw_gas().unwrap(); +/// ``` /// +/// ``` /// // Direct handling of `withdraw_gas`. /// match withdraw_gas() { /// Option::Some(()) => success_case(), @@ -34,6 +39,7 @@ pub extern type GasBuiltin; /// ``` #[cfg(not(gas: "disabled"))] pub extern fn withdraw_gas() -> Option<()> implicits(RangeCheck, GasBuiltin) nopanic; + /// Placeholder when gas mechanism is disabled. #[cfg(gas: "disabled")] pub fn withdraw_gas() -> Option<()> nopanic { @@ -48,13 +54,13 @@ pub fn withdraw_gas() -> Option<()> nopanic { pub extern fn withdraw_gas_all( costs: BuiltinCosts, ) -> Option<()> implicits(RangeCheck, GasBuiltin) nopanic; + /// Placeholder when gas mechanism is disabled. #[cfg(gas: "disabled")] pub fn withdraw_gas_all(costs: BuiltinCosts) -> Option<()> nopanic { Option::Some(()) } - /// Returns unused gas into the gas builtin. /// /// Useful for cases where different branches take different amounts of gas, but gas withdrawal is @@ -64,6 +70,7 @@ pub extern fn redeposit_gas() implicits(GasBuiltin) nopanic; /// Returns the `BuiltinCosts` table to be used in `withdraw_gas_all`. #[cfg(not(gas: "disabled"))] pub extern fn get_builtin_costs() -> BuiltinCosts nopanic; + /// Placeholder when gas mechanism is disabled. #[cfg(gas: "disabled")] pub fn get_builtin_costs() -> BuiltinCosts nopanic {