### Recursive factorial with stacksafe Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html?search=u32+-%3E+bool Example of using the stacksafe attribute on a recursive factorial function. ```rust use stacksafe::stacksafe; #[stacksafe] fn factorial(n: u64) -> u64 { if n <= 1 { 1 } else { n * factorial(n - 1) } } ``` -------------------------------- ### Recursive tree depth with stacksafe Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html?search=u32+-%3E+bool Example of using StackSafe and stacksafe attribute for recursive data structures. ```rust use stacksafe::StackSafe; use stacksafe::stacksafe; struct TreeNode { value: T, left: Option>>>, right: Option>>>, } #[stacksafe] fn tree_depth(node: &Option>>>) -> usize { match node { None => 0, Some(n) => 1 + tree_depth(&n.left).max(tree_depth(&n.right)), } } ``` -------------------------------- ### Get minimum stack size signature Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_minimum_stack_size.html Returns the current minimum stack space threshold in bytes. ```rust pub fn get_minimum_stack_size() -> usize ``` -------------------------------- ### Get stack allocation size signature Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_stack_allocation_size.html Returns the current stack allocation size in bytes as a usize. ```rust pub fn get_stack_allocation_size() -> usize ``` -------------------------------- ### Create StackSafe Instance Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search= Initialize a new StackSafe wrapper. ```rust use stacksafe::StackSafe; let wrapped = StackSafe::new(vec![1, 2, 3]); ``` -------------------------------- ### Add StackSafe dependency Source: https://docs.rs/stacksafe/latest/stacksafe/index.html?search= Include the crate in your Cargo.toml file. ```toml [dependencies] stacksafe = "1" ``` -------------------------------- ### Configuration Functions Source: https://docs.rs/stacksafe/latest/stacksafe/index.html Functions to configure the stack management thresholds and allocation sizes. ```APIDOC ## Configuration Functions ### set_minimum_stack_size(bytes: usize) Configures the minimum stack space threshold (in bytes) that triggers a new stack allocation. ### set_stack_allocation_size(bytes: usize) Configures the size (in bytes) of newly allocated stack segments. ### get_minimum_stack_size() -> usize Returns the current minimum stack space threshold in bytes. ### get_stack_allocation_size() -> usize Returns the current stack allocation size in bytes. ``` -------------------------------- ### Configuration Functions Source: https://docs.rs/stacksafe/latest/stacksafe/index.html?search= Functions to configure the stack management thresholds and allocation sizes. ```APIDOC ## Configuration Functions ### set_minimum_stack_size(bytes: usize) Configures the minimum stack space threshold (in bytes) for triggering stack allocation. ### set_stack_allocation_size(bytes: usize) Configures the size (in bytes) of newly allocated stack segments. ### get_minimum_stack_size() -> usize Returns the current minimum stack space threshold in bytes. ### get_stack_allocation_size() -> usize Returns the current stack allocation size in bytes. ``` -------------------------------- ### StackSafe::new Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search=std%3A%3Avec Creates a new StackSafe wrapper around a given value. ```APIDOC ## pub fn new(value: T) -> Self ### Description Creates a new `StackSafe` wrapper around the provided value. ### Parameters - **value** (T) - The value to wrap. ### Example ```rust use stacksafe::StackSafe; let wrapped = StackSafe::new(vec![1, 2, 3]); ``` ``` -------------------------------- ### Configure stack management settings Source: https://docs.rs/stacksafe/latest/stacksafe/index.html?search= Adjust the threshold for triggering stack allocation and the size of allocated segments. ```rust use stacksafe::set_minimum_stack_size; use stacksafe::set_stack_allocation_size; // Trigger allocation when < 64 KiB remaining (default: 128 KiB). set_minimum_stack_size(64 * 1024); // Allocate 4 MiB stacks for deep recursion (default: 2 MiB). set_stack_allocation_size(4 * 1024 * 1024); ``` -------------------------------- ### StackSafe::new Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search= Creates a new StackSafe wrapper around the provided value. ```APIDOC ## pub fn new(value: T) -> Self ### Description Creates a new `StackSafe` wrapper around the given value. ### Example ```rust use stacksafe::StackSafe; let wrapped = StackSafe::new(vec![1, 2, 3]); ``` ``` -------------------------------- ### get_minimum_stack_size Source: https://docs.rs/stacksafe/latest/stacksafe/all.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the current minimum stack size configuration. ```APIDOC ## get_minimum_stack_size ### Description Returns the minimum stack size currently configured for the application. ### Signature `pub fn get_minimum_stack_size() -> usize` ``` -------------------------------- ### set_minimum_stack_size(bytes: usize) Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_minimum_stack_size.html Configures the minimum stack space threshold for triggering stack allocation in bytes. When a function marked with #[stacksafe] is called and the remaining stack space is less than this threshold, a new stack segment will be allocated. ```APIDOC ## set_minimum_stack_size ### Description Configures the minimum stack space threshold for triggering stack allocation in bytes. When a function marked with `#[stacksafe]` is called and the remaining stack space is less than this threshold, a new stack segment will be allocated. The default value is 128 KiB. ### Signature `pub fn set_minimum_stack_size(bytes: usize)` ### Parameters - **bytes** (usize) - The minimum stack space threshold in bytes. ``` -------------------------------- ### set_minimum_stack_size Source: https://docs.rs/stacksafe/latest/stacksafe/all.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Sets the minimum stack size. ```APIDOC ## set_minimum_stack_size ### Description Configures the minimum stack size for the application. ### Signature `pub fn set_minimum_stack_size(size: usize)` ``` -------------------------------- ### set_minimum_stack_size(bytes: usize) Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_minimum_stack_size.html?search=u32+-%3E+bool Configures the minimum stack space threshold for triggering stack allocation. When a function marked with #[stacksafe] is called and the remaining stack space is less than this threshold, a new stack segment will be allocated. ```APIDOC ## set_minimum_stack_size ### Description Configures the minimum stack space threshold for triggering stack allocation in bytes. Defaults to 128 KiB. ### Signature `pub fn set_minimum_stack_size(bytes: usize)` ### Parameters - **bytes** (usize) - The minimum stack space threshold in bytes. ``` -------------------------------- ### set_minimum_stack_size(bytes: usize) Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_minimum_stack_size.html?search=std%3A%3Avec Configures the minimum stack space threshold for triggering stack allocation. When a function marked with #[stacksafe] is called and the remaining stack space is less than this threshold, a new stack segment will be allocated. ```APIDOC ## fn set_minimum_stack_size ### Description Configures the minimum stack space threshold for triggering stack allocation in bytes. When a function marked with `#[stacksafe]` is called and the remaining stack space is less than this threshold, a new stack segment will be allocated. The default value is 128 KiB. ### Signature `pub fn set_minimum_stack_size(bytes: usize)` ### Parameters - **bytes** (usize) - The minimum stack space threshold in bytes. ``` -------------------------------- ### get_minimum_stack_size Source: https://docs.rs/stacksafe/latest/stacksafe/all.html?search= Retrieves the currently configured minimum stack size. ```APIDOC ## get_minimum_stack_size ### Description Returns the current minimum stack size configuration. ### Signature `pub fn get_minimum_stack_size() -> usize` ``` -------------------------------- ### set_minimum_stack_size function signature Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_minimum_stack_size.html The function signature for configuring the stack size threshold. ```rust pub fn set_minimum_stack_size(bytes: usize) ``` -------------------------------- ### #[stacksafe] Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html An attribute macro applied to functions to enable automatic stack overflow prevention. ```APIDOC ## #[stacksafe] ### Description An attribute macro that transforms recursive functions to automatically check available stack space and allocate new stack segments when needed, preventing stack overflow in deeply recursive scenarios. ### Usage Apply the `#[stacksafe]` attribute to a recursive function definition. ### Example ```rust use stacksafe::stacksafe; #[stacksafe] fn factorial(n: u64) -> u64 { if n <= 1 { 1 } else { n * factorial(n - 1) } } ``` ### Limitations - Cannot be applied to `async` functions. - Functions with `impl Trait` return types may require explicit type annotations. - Introduces a small runtime overhead for stack size checking. ``` -------------------------------- ### set_stack_allocation_size(bytes: usize) Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_stack_allocation_size.html?search= Configures the size of newly allocated stack segments in bytes. When a function marked with #[stacksafe] requires additional stack space, it will allocate a new segment of the specified size. The default value is 2 MiB. ```APIDOC ## set_stack_allocation_size ### Description Configures the size of newly allocated stack segments in bytes. When a function marked with `#[stacksafe]` needs more stack space, it allocates a new stack segment of this size. ### Signature `pub fn set_stack_allocation_size(bytes: usize)` ### Parameters - **bytes** (usize) - The size of the stack segment in bytes. Defaults to 2 MiB. ``` -------------------------------- ### set_stack_allocation_size(bytes: usize) Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_stack_allocation_size.html?search=std%3A%3Avec Configures the size of newly allocated stack segments in bytes. When a function marked with #[stacksafe] requires additional stack space, it will allocate a new segment of the specified size. The default value is 2 MiB. ```APIDOC ## set_stack_allocation_size ### Description Configures the size of newly allocated stack segments in bytes. When a function marked with `#[stacksafe]` needs more stack space, it allocates a new stack segment of this size. ### Signature `pub fn set_stack_allocation_size(bytes: usize)` ### Parameters - **bytes** (usize) - The size of the stack segment in bytes. ``` -------------------------------- ### set_stack_allocation_size(bytes: usize) Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_stack_allocation_size.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Configures the size of newly allocated stack segments in bytes. When a function marked with #[stacksafe] requires additional stack space, it will allocate a new segment of the specified size. The default value is 2 MiB. ```APIDOC ## set_stack_allocation_size ### Description Configures the size of newly allocated stack segments in bytes. When a function marked with `#[stacksafe]` needs more stack space, it allocates a new stack segment of this size. ### Signature `pub fn set_stack_allocation_size(bytes: usize)` ### Parameters - **bytes** (usize) - The size of the stack segment in bytes. ### Notes - Defaults to 2 MiB. ``` -------------------------------- ### Set stack allocation size Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_stack_allocation_size.html Configures the size of newly allocated stack segments in bytes. Defaults to 2 MiB. ```rust pub fn set_stack_allocation_size(bytes: usize) ``` -------------------------------- ### get_minimum_stack_size Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_minimum_stack_size.html?search=u32+-%3E+bool Returns the current minimum stack space threshold in bytes. ```APIDOC ## Function: get_minimum_stack_size ### Description Returns the current minimum stack space threshold in bytes. This value determines when new stack segments are allocated for functions marked with `#[stacksafe]`. ### Signature `pub fn get_minimum_stack_size() -> usize` ### Returns - **usize**: The minimum stack space threshold in bytes. ``` -------------------------------- ### #[stacksafe] Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html?search= The #[stacksafe] attribute macro is applied to recursive functions to prevent stack overflow by managing stack space allocation automatically. ```APIDOC ## #[stacksafe] ### Description An attribute macro that transforms functions to automatically check available stack space and allocate new stack segments when needed, preventing stack overflow in deeply recursive scenarios. ### Usage Apply the attribute to a recursive function: ```rust use stacksafe::stacksafe; #[stacksafe] fn factorial(n: u64) -> u64 { if n <= 1 { 1 } else { n * factorial(n - 1) } } ``` ### Limitations - Cannot be applied to `async` functions. - Functions with `impl Trait` return types may require explicit type annotations. - Introduces a small runtime overhead for stack size checking. ``` -------------------------------- ### Use StackSafe for recursive data structures Source: https://docs.rs/stacksafe/latest/stacksafe/index.html?search= Wrap recursive data structures in StackSafe to ensure safe traversal. ```rust use stacksafe::StackSafe; use stacksafe::stacksafe; #[derive(Debug, Clone)] enum BinaryTree { Leaf(i32), Node { value: i32, left: Box>, right: Box>, }, } #[stacksafe] fn tree_sum(tree: &BinaryTree) -> i32 { match tree { BinaryTree::Leaf(value) => *value, BinaryTree::Node { value, left, right } => value + tree_sum(left) + tree_sum(right), } } ``` -------------------------------- ### get_minimum_stack_size() Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_minimum_stack_size.html?search= Returns the current minimum stack space threshold in bytes. ```APIDOC ## Function: get_minimum_stack_size() ### Description Returns the current minimum stack space threshold in bytes. This value determines when new stack segments are allocated for functions marked with `#[stacksafe]`. ### Signature `pub fn get_minimum_stack_size() -> usize` ### Returns - **usize**: The minimum stack space threshold in bytes. ``` -------------------------------- ### get_minimum_stack_size() Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_minimum_stack_size.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the current minimum stack space threshold in bytes. ```APIDOC ## get_minimum_stack_size ### Description Returns the current minimum stack space threshold in bytes. This value determines when new stack segments are allocated for functions marked with `#[stacksafe]`. ### Signature `pub fn get_minimum_stack_size() -> usize` ### Returns - **usize** - The minimum stack space threshold in bytes. ``` -------------------------------- ### set_stack_allocation_size Source: https://docs.rs/stacksafe/latest/stacksafe/all.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Sets the stack allocation size. ```APIDOC ## set_stack_allocation_size ### Description Configures the stack allocation size for the application. ### Signature `pub fn set_stack_allocation_size(size: usize)` ``` -------------------------------- ### Apply stacksafe attribute Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html?search=u32+-%3E+bool Basic usage of the stacksafe attribute macro on a function. ```rust #[stacksafe] ``` -------------------------------- ### #[stacksafe] Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html?search=std%3A%3Avec The stacksafe attribute macro is applied to recursive functions to prevent stack overflow by managing stack segments automatically. ```APIDOC ## #[stacksafe] ### Description An attribute macro that transforms recursive functions to automatically check available stack space and allocate new stack segments when needed. This prevents stack overflow errors in deeply recursive scenarios. ### Usage Apply the `#[stacksafe]` attribute to any recursive function definition. ### Example ```rust use stacksafe::stacksafe; #[stacksafe] fn factorial(n: u64) -> u64 { if n <= 1 { 1 } else { n * factorial(n - 1) } } ``` ### Limitations - Cannot be applied to `async` functions. - Functions with `impl Trait` return types may require explicit type annotations. - Introduces a small runtime overhead for stack size checking. ``` -------------------------------- ### fn set_stack_allocation_size Source: https://docs.rs/stacksafe/latest/stacksafe/fn.set_stack_allocation_size.html Configures the size of newly allocated stack segments in bytes. When a function marked with #[stacksafe] requires additional stack space, it will allocate a new segment of the specified size. ```APIDOC ## fn set_stack_allocation_size(bytes: usize) ### Description Configures the size of newly allocated stack segments in bytes. When a function marked with `#[stacksafe]` needs more stack space, it allocates a new stack segment of this size. The default value is 2 MiB. ### Parameters - **bytes** (usize) - Required - The size of the stack segment in bytes. ``` -------------------------------- ### get_stack_allocation_size Source: https://docs.rs/stacksafe/latest/stacksafe/all.html?search= Retrieves the currently configured stack allocation size. ```APIDOC ## get_stack_allocation_size ### Description Returns the current stack allocation size configuration. ### Signature `pub fn get_stack_allocation_size() -> usize` ``` -------------------------------- ### StackSafe::into_inner Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search=std%3A%3Avec Consumes the wrapper and returns the inner value. ```APIDOC ## pub fn into_inner(self) -> T ### Description Consumes the `StackSafe` wrapper and returns the inner value. Note that in debug builds, this will panic if called outside of a stack-safe context. ### Example ```rust use stacksafe::StackSafe; let wrapped = StackSafe::new(vec![1, 2, 3]); let inner = wrapped.into_inner(); ``` ``` -------------------------------- ### StackSafe::into_inner Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search= Consumes the wrapper and returns the inner value. ```APIDOC ## pub fn into_inner(self) -> T ### Description Consumes the `StackSafe` wrapper and returns the inner value. ### Panics In debug builds, panics if called outside of a stack-safe context. ### Example ```rust use stacksafe::StackSafe; let wrapped = StackSafe::new(vec![1, 2, 3]); let inner = wrapped.into_inner(); assert_eq!(inner, vec![1, 2, 3]); ``` ``` -------------------------------- ### get_minimum_stack_size Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_minimum_stack_size.html?search=std%3A%3Avec Returns the current minimum stack space threshold in bytes, which determines when new stack segments are allocated for functions marked with #[stacksafe]. ```APIDOC ## Function: get_minimum_stack_size ### Description Returns the current minimum stack space threshold in bytes. This value determines when new stack segments are allocated for functions marked with #[stacksafe]. ### Signature `pub fn get_minimum_stack_size() -> usize` ### Returns - **usize** - The minimum stack space threshold in bytes. ``` -------------------------------- ### get_stack_allocation_size Source: https://docs.rs/stacksafe/latest/stacksafe/all.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the current stack allocation size. ```APIDOC ## get_stack_allocation_size ### Description Returns the stack allocation size currently configured. ### Signature `pub fn get_stack_allocation_size() -> usize` ``` -------------------------------- ### get_stack_allocation_size() Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_stack_allocation_size.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the current stack allocation size in bytes. ```APIDOC ## Function: get_stack_allocation_size ### Description Returns the current stack allocation size in bytes. This value represents the size of new stack segments allocated when functions marked with `#[stacksafe]` require additional stack space. ### Signature `pub fn get_stack_allocation_size() -> usize` ### Returns - **usize**: The size of the stack allocation in bytes. ``` -------------------------------- ### get_stack_allocation_size() Source: https://docs.rs/stacksafe/latest/stacksafe/fn.get_stack_allocation_size.html Returns the current stack allocation size in bytes, representing the size of new stack segments allocated for stacksafe functions. ```APIDOC ## get_stack_allocation_size ### Description Returns the current stack allocation size in bytes. This value represents the size of new stack segments allocated when functions marked with `#[stacksafe]` require additional stack space. ### Signature `pub fn get_stack_allocation_size() -> usize` ### Returns - **usize** - The current stack allocation size in bytes. ``` -------------------------------- ### Define StackSafe Struct Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search= The definition of the StackSafe wrapper type. ```rust pub struct StackSafe(/* private fields */); ``` -------------------------------- ### stacksafe Attribute Macro Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html?search=u32+-%3E+bool The #[stacksafe] attribute macro is applied to recursive functions to prevent stack overflow by managing stack segments automatically. ```APIDOC ## #[stacksafe] ### Description An attribute macro that transforms recursive functions to automatically check available stack space and allocate new stack segments when necessary. This prevents stack overflow errors in deeply recursive scenarios. ### Usage Apply the attribute to a recursive function: ```rust use stacksafe::stacksafe; #[stacksafe] fn factorial(n: u64) -> u64 { if n <= 1 { 1 } else { n * factorial(n - 1) } } ``` ### Limitations - Cannot be applied to `async` functions. - Functions with `impl Trait` return types may require explicit type annotations. - Introduces a small runtime overhead for stack size checking. ``` -------------------------------- ### stacksafe Attribute Macro Source: https://docs.rs/stacksafe/latest/stacksafe/attr.stacksafe.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E The #[stacksafe] attribute macro is applied to recursive functions to prevent stack overflow by managing stack segments automatically. ```APIDOC ## #[stacksafe] ### Description An attribute macro that transforms recursive functions to automatically check available stack space and allocate new stack segments when needed, preventing stack overflow in deeply recursive scenarios. ### Usage Apply the attribute to a recursive function: ```rust use stacksafe::stacksafe; #[stacksafe] fn factorial(n: u64) -> u64 { if n <= 1 { 1 } else { n * factorial(n - 1) } } ``` ### Limitations - Cannot be applied to `async` functions. - Functions with `impl Trait` return types may require explicit type annotations. - Introduces a small runtime overhead for stack size checking. ``` -------------------------------- ### StackSafe Source: https://docs.rs/stacksafe/latest/stacksafe/index.html A wrapper type for recursive data structures that ensures stack-safe operations during traversal. ```APIDOC ## StackSafe ### Description Wraps recursive data structures to prevent stack overflow during operations like cloning or debugging. ``` -------------------------------- ### Consume StackSafe Wrapper Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search= Extract the inner value from the StackSafe wrapper. ```rust use stacksafe::StackSafe; let wrapped = StackSafe::new(vec![1, 2, 3]); let inner = wrapped.into_inner(); assert_eq!(inner, vec![1, 2, 3]); ``` -------------------------------- ### Prevent stack overflow in recursive functions Source: https://docs.rs/stacksafe/latest/stacksafe/index.html?search= Use the #[stacksafe] attribute on recursive functions to automatically manage stack space. ```rust use stacksafe::stacksafe; #[stacksafe] fn fibonacci(n: u64) -> u64 { match n { 0 | 1 => n, _ => fibonacci(n - 1) + fibonacci(n - 2), } } // No stack overflow, even for deep recursion println!("Fibonacci of 30: {}", fibonacci(30)); ``` -------------------------------- ### Deref StackSafe Value Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search= Access the underlying value within a stack-safe context. ```rust use stacksafe::StackSafe; use stacksafe::stacksafe; #[stacksafe] fn get_length(data: &StackSafe>) -> usize { data.len() // Automatic deref to Vec } ``` -------------------------------- ### DerefMut StackSafe Value Source: https://docs.rs/stacksafe/latest/stacksafe/struct.StackSafe.html?search= Access the underlying value mutably within a stack-safe context. ```rust use stacksafe::StackSafe; use stacksafe::stacksafe; #[stacksafe] fn append_value(data: &mut StackSafe>, value: i32) { data.push(value); // Automatic deref to Vec } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.