### Build Application Bundle Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Builds the application bundle into the specified installation directory. Documentation is available in the OS X build. ```rust pub fn build(&mut self, dir: InstallDir) -> Result ``` -------------------------------- ### Box::from_raw Example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates recreating a Box from a raw pointer obtained via Box::into_raw. This is crucial for managing memory ownership after converting a Box to a raw pointer. ```rust let x = Box::new(5); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` -------------------------------- ### InstallDir Enum Definition Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/enum.InstallDir.html Defines the possible locations for saving generated app bundles. Use this enum to specify where your application should be installed or saved. ```rust pub enum InstallDir { Temp, SystemApplications, UserApplications, Custom(String), } ``` -------------------------------- ### Box::into_pin conversion example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Illustrates a problematic implementation of From> for Pin, which can lead to ambiguity when calling Pin::from. This highlights why such direct conversions are not recommended. ```rust struct Foo; impl From> for Pin { fn from(_: Box<()>) -> Pin { Pin::new(Foo) } } let foo = Box::new(()); let bar = Pin::from(foo); ``` -------------------------------- ### Box::into_raw Example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Shows how to consume a Box and obtain a raw pointer, transferring memory management responsibility to the caller. The pointer can be converted back to a Box for automatic cleanup. ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` -------------------------------- ### Box::clone_from_ref Example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Shows how to clone a value from a reference into a new Box using the experimental `clone_from_ref` function. This is efficient as it avoids unnecessary allocations for zero-sized types. ```rust #![feature(clone_from_ref)] let hello: Box = Box::clone_from_ref("hello"); ``` -------------------------------- ### Box::from_non_null Example (Nightly) Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Illustrates recreating a Box from a NonNull pointer, typically obtained from Box::into_non_null. This API is experimental and requires the nightly Rust toolchain. ```rust #![feature(box_vec_non_null)] let x = Box::new(5); let non_null = Box::into_non_null(x); let x = unsafe { Box::from_non_null(non_null) }; ``` -------------------------------- ### Box::try_clone_from_ref Example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Illustrates cloning a value from a reference into a new Box, returning a Result to handle potential allocation errors. This uses the experimental `try_clone_from_ref` function. ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] let hello: Box = Box::try_clone_from_ref("hello")?; ``` -------------------------------- ### Get Bundled Resource Path for FruitApp Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Retrieves the path to a bundled resource for the FruitApp. Documentation is available in the OS X build. ```rust pub fn bundled_resource_path(_name: &str, _extension: &str) -> Option ``` -------------------------------- ### Box::try_map Example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates mapping a value within a Box using the experimental `try_map` function. This function attempts to reuse the allocation if the mapping operation succeeds. ```rust #![feature(smart_pointer_try_map)] let b = Box::new(7); let new = Box::try_map(b, u32::try_from).unwrap(); assert_eq!(*new, 7); ``` -------------------------------- ### Get FruitApp Stopper Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Retrieves the stopper for the FruitApp. Documentation is available in the OS X build. ```rust pub fn stopper(&self) -> FruitStopper ``` -------------------------------- ### Box::as_ptr and Box::as_mut_ptr aliasing example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Illustrates the interaction between Box::as_ptr and Box::as_mut_ptr, showing that a raw pointer obtained via as_ptr remains valid until a write operation occurs via as_mut_ptr. ```rust #![feature(box_as_ptr)] unsafe { let mut v = Box::new(0); let ptr1 = Box::as_ptr(&v); let ptr2 = Box::as_mut_ptr(&mut v); let _val = ptr2.read(); // No write to this memory has happened yet, so `ptr1` is still valid. let _val = ptr1.read(); // However, once we do a write... ptr2.write(1); // ... `ptr1` is no longer valid. // This would be UB: let _val = ptr1.read(); } ``` -------------------------------- ### Box::as_mut_ptr aliasing guarantee example Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates the aliasing guarantee of Box::as_mut_ptr, showing that writes to a Box's memory do not invalidate other raw pointers obtained from it, as long as no mutable references are materialized. ```rust #![feature(box_as_ptr)] unsafe { let mut b = Box::new(0); let ptr1 = Box::as_mut_ptr(&mut b); ptr1.write(1); let ptr2 = Box::as_mut_ptr(&mut b); ptr2.write(2); // Notably, the write to `ptr2` did *not* invalidate `ptr1`: ptr1.write(3); } ``` -------------------------------- ### Get Type ID Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Gets the `TypeId` of `self`. This is a blanket implementation for any type `T` that is `'static` and `?Sized`. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### GetTypeId Implementation Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Gets the `TypeId` of `self`. This is a blanket implementation for any type `T` that is 'static and ?Sized. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Box::from_raw_in with System Allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates manually creating a Box from a raw pointer using the system allocator. This is an experimental API and requires careful handling of memory safety. ```rust #![feature(allocator_api, slice_ptr_get)] use std::alloc::{Allocator, Layout, System}; unsafe { let ptr = System.allocate(Layout::new::())?.as_mut_ptr() as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw_in(ptr, System); } ``` -------------------------------- ### Box::new_uninit Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a new Box with uninitialized contents. ```APIDOC ## Box::new_uninit ### Description Constructs a new box with uninitialized contents. ### Method Associated function (called as `Box::new_uninit()`) ### Returns * **Box>** - A Box containing an uninitialized value of type `T`. ### Examples ```rust let mut five = Box::::new_uninit(); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ``` -------------------------------- ### FruitApp Constructor Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Creates a new instance of FruitApp. Documentation is available in the OS X build. ```rust pub fn new() -> FruitApp ``` -------------------------------- ### Box Reverse Fold and Try Fold Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Performs fold and try_fold operations starting from the back of the iterator. These are nightly-only experimental APIs. ```rust fn try_rfold(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try, ``` ```rust fn rfold(self, init: B, f: F) -> B where Self: Sized, F: FnMut(B, Self::Item) -> B, ``` -------------------------------- ### Box::new Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory on the heap and places a value into it. ```APIDOC ## Box::new ### Description Allocates memory on the heap and then places `x` into it. ### Method Associated function (called as `Box::new(x)`) ### Parameters * **x** (*T*) - The value to place in the new Box. ### Returns * **Box** - A Box containing the value `x`. ### Remarks This doesn’t actually allocate if `T` is zero-sized. ### Examples ```rust let five = Box::new(5); ``` ``` -------------------------------- ### Box::try_new_uninit Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Attempts to construct a new Box with uninitialized contents on the heap, returning an error if the allocation fails. This is a nightly-only experimental API. ```APIDOC ## Box::try_new_uninit ### Description Constructs a new box with uninitialized contents on the heap, returning an error if the allocation fails. ### Method Associated function (called as `Box::try_new_uninit()`) ### Returns * **Result>, AllocError>** - Ok containing the Box if allocation succeeds, or an AllocError if it fails. ### Remarks This is a nightly-only experimental API. (`allocator_api`) ### Examples ```rust #![feature(allocator_api)] let mut five = Box::::try_new_uninit()?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` ``` -------------------------------- ### Bundle Application Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Bundles the application into the specified directory. Documentation is available in the OS X build. ```rust pub fn self_bundle(&mut self, _dir: InstallDir) -> Result<(), FruitError> ``` -------------------------------- ### Box::from_raw with Manual Allocation Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Shows how to manually create a Box from a raw pointer obtained through direct memory allocation. This requires careful handling of memory layout and ownership. ```rust use std::alloc::{alloc, Layout}; unsafe { let ptr = alloc(Layout::new::()) as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw(ptr); } ``` -------------------------------- ### new_uninit_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a new box with uninitialized contents in the provided allocator. ```APIDOC ## new_uninit_in ### Description Constructs a new box with uninitialized contents in the provided allocator. ### Signature `pub fn new_uninit_in(alloc: A) -> Box, A>` ### Type Parameters - `T`: The type of the value to be stored. - `A`: The type of the allocator, which must implement `Allocator`. ### Parameters - `alloc` (`A`): The allocator to use for memory allocation. ### Returns - `Box, A>`: A `Box` containing uninitialized memory. ### Examples ```rust #![feature(allocator_api)] use std::alloc.System; let mut five = Box::::new_uninit_in(System); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ``` -------------------------------- ### Box::leak usage with unsized data Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Shows how Box::leak can be used with unsized data, such as a Box<[T]>, to obtain a &'static mut slice. The example modifies an element of the leaked slice. ```rust let x = vec![1, 2, 3].into_boxed_slice(); let static_ref = Box::leak(x); static_ref[0] = 4; assert_eq!(*static_ref, [4, 2, 3]); ``` -------------------------------- ### try_new_uninit_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a new box with uninitialized contents in the provided allocator, returning an error if the allocation fails. ```APIDOC ## try_new_uninit_in ### Description Constructs a new box with uninitialized contents in the provided allocator, returning an error if the allocation fails. ### Signature `pub fn try_new_uninit_in(alloc: A) -> Result, A>, AllocError>` ### Type Parameters - `T`: The type of the value to be stored. - `A`: The type of the allocator, which must implement `Allocator`. ### Parameters - `alloc` (`A`): The allocator to use for memory allocation. ### Returns - `Result, A>, AllocError>`: A `Result` containing a `Box, A>` on success, or an `AllocError` if the allocation fails. ### Examples ```rust #![feature(allocator_api)] use std::alloc.System; let mut five = Box::::try_new_uninit_in(System)?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` ``` -------------------------------- ### Add Multiple Resource Files Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Adds multiple resource files to the application bundle. Documentation is available in the OS X build. ```rust pub fn resources(&mut self, _files: &Vec<&str>) -> &mut Self ``` -------------------------------- ### Box::leak usage with primitive types Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates how to use Box::leak to convert a Box into a &'static mut T, suitable for data that should live for the entire program's duration. The example shows incrementing a leaked value. ```rust let x = Box::new(41); let static_ref: &'static mut usize = Box::leak(x); *static_ref += 1; assert_eq!(*static_ref, 42); ``` -------------------------------- ### Box Provide Method Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Provides type-based access to context for error reports. This is a nightly-only experimental API. ```rust fn provide<'b>(&'b self, request: &mut Request<'b>) ``` -------------------------------- ### Box::new_uninit_in with Allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a Box with uninitialized contents using a provided allocator. Initialization can be deferred. This API is nightly-only and requires the `allocator_api` feature. ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::new_uninit_in(System); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` -------------------------------- ### Cloning a string slice into a Box with a specific allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates how to use the experimental `try_clone_from_ref_in` function to clone a string slice into a Box allocated by `System`. This API is nightly-only. ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc.System; let hello: Box = Box::try_clone_from_ref_in("hello", System)?; ``` -------------------------------- ### Box::from_non_null with Manual Allocation (Nightly) Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates creating a Box from a NonNull pointer derived from manual memory allocation. This is an advanced use case requiring nightly features and careful memory management. ```rust #![feature(box_vec_non_null)] use std::alloc::{alloc, Layout}; use std::ptr::NonNull; unsafe { let non_null = NonNull::new(alloc(Layout::new::()).cast::()) .expect("allocation failed"); // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `non_null`. non_null.write(5); let x = Box::from_non_null(non_null); } ``` -------------------------------- ### Equivalent Manual Cleanup using Box::from_non_null Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Shows an alternative manual cleanup method by converting the NonNull pointer back to a Box and letting its destructor handle deallocation. ```rust #![feature(box_vec_non_null)] let x = Box::new(String::from("Hello")); let non_null = Box::into_non_null(x); unsafe { drop(Box::from_non_null(non_null)); } ``` -------------------------------- ### Try to Create a Box with Uninitialized Contents Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Attempts to construct a Box with uninitialized memory, returning a Result. Use `write` and `assume_init` for initialization and access. ```rust #![feature(allocator_api)] let mut five = Box::::try_new_uninit()?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` -------------------------------- ### Try to Create a Box with Zeroed Contents Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Attempts to construct a Box with zeroed memory, returning a Result. Use `assume_init` to access the value. ```rust #![feature(allocator_api)] let zero = Box::::try_new_zeroed()?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` -------------------------------- ### take Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ```APIDOC ## fn take(self, n: usize) -> Take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Method Iterator adapter ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) An iterator that yields the first `n` elements. #### Response Example None ``` -------------------------------- ### TryFrom Implementation Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitStopper.html Attempts to convert a value of type U into FruitStopper. The conversion might fail, returning an Infallible error type. ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Add Resource File Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Adds a single resource file to the application bundle. Documentation is available in the OS X build. ```rust pub fn resource(&mut self, _file: &str) -> &mut Self ``` -------------------------------- ### Set Activation Policy for FruitApp Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Sets the activation policy for the FruitApp. Documentation is available in the OS X build. ```rust pub fn set_activation_policy(&self, _policy: ActivationPolicy) ``` -------------------------------- ### Create a Box with Uninitialized Contents Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a Box with uninitialized memory. Use `write` to initialize and `assume_init` to access the value. ```rust let mut five = Box::::new_uninit(); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` -------------------------------- ### TryInto Implementation Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitStopper.html Attempts to convert the FruitStopper into another type U. The conversion might fail, returning an error type defined by U. ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Manually Create Box with System Allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Manually creates a Box using the system allocator by allocating memory, writing the value, and then constructing the Box. This requires unsafe operations and careful memory management. ```rust #![feature(allocator_api)] use std::alloc::{Allocator, Layout, System}; unsafe { let non_null = System.allocate(Layout::new::())?.cast::(); // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `non_null`. non_null.write(5); let x = Box::from_non_null_in(non_null, System); } ``` -------------------------------- ### Box::try_new_uninit_in with Allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a Box with uninitialized contents using a provided allocator, returning an error if allocation fails. Initialization can be deferred. This API is nightly-only and requires the `allocator_api` feature. ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::try_new_uninit_in(System)?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` -------------------------------- ### Register Callback for FruitApp Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Registers a callback with the FruitApp. Documentation is available in the OS X build. ```rust pub fn register_callback( &mut self, _key: FruitCallbackKey, _cb: FruitObjcCallback, ) ``` -------------------------------- ### Box::from_raw_in with Recreated Box Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Shows how to recreate a Box from a raw pointer and allocator after it was previously converted using `Box::into_raw_with_allocator`. This utilizes the experimental `from_raw_in` function. ```rust #![feature(allocator_api)] use std::alloc::System; let x = Box::new_in(5, System); let (ptr, alloc) = Box::into_raw_with_allocator(x); let x = unsafe { Box::from_raw_in(ptr, alloc) }; ``` -------------------------------- ### Box::try_new_zeroed Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Attempts to construct a new Box with uninitialized contents, with the memory being filled with 0 bytes on the heap, returning an error if the allocation fails. This is a nightly-only experimental API. ```APIDOC ## Box::try_new_zeroed ### Description Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes on the heap. ### Method Associated function (called as `Box::try_new_zeroed()`) ### Returns * **Result>, AllocError>** - Ok containing the Box if allocation succeeds, or an AllocError if it fails. ### Remarks This is a nightly-only experimental API. (`allocator_api`) See `MaybeUninit::zeroed` for examples of correct and incorrect usage of this method. ### Examples ```rust #![feature(allocator_api)] let zero = Box::::try_new_zeroed()?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` ``` -------------------------------- ### Run FruitApp Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Runs the FruitApp for a specified period. Documentation is available in the OS X build. ```rust pub fn run(&mut self, period: RunPeriod) -> Result<(), ()> ``` -------------------------------- ### Box::new_zeroed_in with Allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a Box with memory initialized to zero bytes using a provided allocator. This API is nightly-only and requires the `allocator_api` feature. ```rust #![feature(allocator_api)] use std::alloc::System; let zero = Box::::new_zeroed_in(System); let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0) ``` -------------------------------- ### Create a Boxed Value Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory on the heap and places a value into it. This is the basic way to create a Box. ```rust let five = Box::new(5); ``` -------------------------------- ### try_new_zeroed_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes in the provided allocator, returning an error if the allocation fails. ```APIDOC ## try_new_zeroed_in ### Description Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes in the provided allocator, returning an error if the allocation fails. ### Signature `pub fn try_new_zeroed_in(alloc: A) -> Result, A>, AllocError>` ### Type Parameters - `T`: The type of the value to be stored. - `A`: The type of the allocator, which must implement `Allocator`. ### Parameters - `alloc` (`A`): The allocator to use for memory allocation. ### Returns - `Result, A>, AllocError>`: A `Result` containing a `Box, A>` on success, or an `AllocError` if the allocation fails. ### Examples ```rust #![feature(allocator_api)] use std::alloc.System; let zero = Box::::try_new_zeroed_in(System)?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` ``` -------------------------------- ### Set Raw Plist String Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Sets the entire Info.plist content as a raw string. Documentation is available in the OS X build. ```rust pub fn plist_raw_string(&mut self, _s: String) -> &mut Self ``` -------------------------------- ### Box::try_new_zeroed_in with Allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a Box with memory initialized to zero bytes using a provided allocator, returning an error if allocation fails. This API is nightly-only and requires the `allocator_api` feature. ```rust #![feature(allocator_api)] use std::alloc::System; let zero = Box::::try_new_zeroed_in(System)?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` -------------------------------- ### Box::try_new Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Attempts to allocate memory on the heap and place a value into it, returning an error if the allocation fails. This is a nightly-only experimental API. ```APIDOC ## Box::try_new ### Description Allocates memory on the heap then places `x` into it, returning an error if the allocation fails. ### Method Associated function (called as `Box::try_new(x)`) ### Parameters * **x** (*T*) - The value to place in the new Box. ### Returns * **Result, AllocError>** - Ok containing the Box if allocation succeeds, or an AllocError if it fails. ### Remarks This is a nightly-only experimental API. (`allocator_api`) This doesn’t actually allocate if `T` is zero-sized. ### Examples ```rust #![feature(allocator_api)] let five = Box::try_new(5)?; ``` ``` -------------------------------- ### Box::new_in with System allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates the usage of the nightly-only Box::new_in function to allocate a Box with a specific allocator, in this case, the standard System allocator. ```rust #![feature(allocator_api)] use std::alloc::System; let five = Box::new_in(5, System); ``` -------------------------------- ### Box::into_raw Equivalent Manual Cleanup Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Presents an alternative manual cleanup method for a raw pointer obtained from Box::into_raw, by converting it back to a Box and then dropping that Box. ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { drop(Box::from_raw(ptr)); } ``` -------------------------------- ### Create a Box with Zeroed Contents Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a Box with memory initialized to zero bytes. Use `assume_init` to access the value. ```rust let zero = Box::::new_zeroed(); let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0) ``` -------------------------------- ### FruitApp Struct Definition Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Defines the main interface for controlling and interacting with the AppKit app. This is a dummy implementation for non-OSX platforms. ```rust pub struct FruitApp { /* private fields */ } ``` -------------------------------- ### Clone to Uninit (Experimental) Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitStopper.html Performs copy-assignment from self to a mutable pointer to uninitialized memory. This is a nightly-only experimental API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### New Trampoline Instance Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Creates a new Trampoline instance. Documentation is available in the OS X build. ```rust pub fn new(_name: &str, _exe: &str, _ident: &str) -> Trampoline ``` -------------------------------- ### Check if Bundled Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Checks if the application is currently bundled. Documentation is available in the OS X build. ```rust pub fn is_bundled() -> bool ``` -------------------------------- ### Box::clone_from_ref_in with Allocator Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory using a specified allocator and clones a referenced value into it. This API is nightly-only and requires the `clone_from_ref` and `allocator_api` features. ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc::System; let hello: Box = Box::clone_from_ref_in("hello", System); ``` -------------------------------- ### Clone From FruitStopper Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitStopper.html Performs copy-assignment from a source FruitStopper to self. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### take Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Consumes the `Box` without consuming its allocation, returning the wrapped value and a `Box` to the uninitialized memory where the wrapped value used to live. ```APIDOC ## take ### Description Consumes the `Box` without consuming its allocation, returning the wrapped value and a `Box` to the uninitialized memory where the wrapped value used to live. ### Signature `pub fn take(boxed: Box) -> (T, Box, A>)` ### Type Parameters - `T`: The type of the value inside the `Box`. - `A`: The type of the allocator. ### Parameters - `boxed` (`Box`): The `Box` to take the value from. ### Returns - `(T, Box, A>)`: A tuple containing the wrapped value and a `Box` to the uninitialized memory. ### Notes This can be used together with `write` to reuse the allocation for multiple boxed values. ### Examples ```rust #![feature(box_take)] let c = Box::new(5); // take the value out of the box let (value, uninit) = Box::take(c); assert_eq!(value, 5); // reuse the box for a second value let c = Box::write(uninit, 6); assert_eq!(*c, 6); ``` ``` -------------------------------- ### Box::into_raw with Manual Cleanup Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Demonstrates manual memory management after converting a Box to a raw pointer using Box::into_raw. This involves explicitly dropping the value and deallocating the memory. ```rust use std::alloc::{dealloc, Layout}; use std::ptr; let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { ptr::drop_in_place(ptr); dealloc(ptr as *mut u8, Layout::new::()); } ``` -------------------------------- ### new_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory in the given allocator and places the value into it. ```APIDOC ## new_in ### Description Allocates memory in the given allocator then places `x` into it. This doesn’t actually allocate if `T` is zero-sized. ### Method `pub fn new_in(x: T, alloc: A) -> Box` ### Parameters - **x** (T) - The value to place in the Box. - **alloc** (A) - The allocator to use. ### Request Example ```rust #![feature(allocator_api)] use std::alloc.System; let five = Box::new_in(5, System); ``` ### Response `Box` - A new Box containing the value, allocated using the specified allocator. ``` -------------------------------- ### try_clone_from_ref_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Clones a value into a new Box allocated with a specified allocator. This is a nightly-only experimental API. ```APIDOC ## pub fn try_clone_from_ref_in(src: &T, alloc: A) -> Result, AllocError> ### Description Allocates memory in the given allocator then clones `src` into it, returning an error if allocation fails. This doesn’t actually allocate if `src` is zero-sized. ### Parameters #### Path Parameters - **src** (&T) - Required - The source value to clone. - **alloc** (A) - Required - The allocator to use for memory allocation. ### Response #### Success Response (Result, AllocError>) - **Ok(Box)**: A new Box containing the cloned value, allocated using the provided allocator. - **Err(AllocError)**: An error indicating that memory allocation failed. ### Examples ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc.System; let hello: Box = Box::try_clone_from_ref_in("hello", System)?; ``` ``` -------------------------------- ### create_logger Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/fn.create_logger.html Configures the Rust `log` and `log4rs` libraries to redirect log macros to stdout and a rotating log file. This function requires the 'logging' feature to be enabled at compile time. ```APIDOC ## Function create_logger ### Description Enable logging to rolling log files with Rust `log` library. This is a helper utility for configuring the Rust `log` and `log4rs` libraries to redirect the `log` macros (`info!()`, `warn!()`, `error!()`, etc) to both stdout and a rotating log file on disk. ### Signature ```rust pub fn create_logger( _filename: &str, _dir: LogDir, _max_size_mb: u32, _backup_count: u32, ) -> Result ``` ### Arguments * `filename` - Filename for the log file, _without_ path * `dir` - Directory to save log files in. This is provided as an enum, `LogDir`, which offers some standard logging directories, or allows specification of any custom directory. * `max_size_mb` - Max size (in megabytes) of the log file before it is rolled into an archive file in the same directory. * `backup_count` - Number of archived log files to keep before deleting old logs. ### Returns Full path to opened log file on disk ### Feature Flag Requires the ‘logging’ feature to be specified at compile time. ``` -------------------------------- ### clone_from_ref_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory in the given allocator then clones `src` into it. This doesn’t actually allocate if `src` is zero-sized. ```APIDOC ## clone_from_ref_in ### Description Allocates memory in the given allocator then clones `src` into it. This doesn’t actually allocate if `src` is zero-sized. ### Signature `pub fn clone_from_ref_in(src: &T, alloc: A) -> Box` ### Type Parameters - `T`: The type of the value to be cloned, must implement `CloneToUninit`. - `A`: The type of the allocator, which must implement `Allocator`. ### Parameters - `src` (`&T`): A reference to the value to be cloned. - `alloc` (`A`): The allocator to use for memory allocation. ### Returns - `Box`: A new `Box` containing the cloned value. ### Examples ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc.System; let hello: Box = Box::clone_from_ref_in("hello", System); ``` ``` -------------------------------- ### new_zeroed_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes in the provided allocator. ```APIDOC ## new_zeroed_in ### Description Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes in the provided allocator. ### Signature `pub fn new_zeroed_in(alloc: A) -> Box, A>` ### Type Parameters - `T`: The type of the value to be stored. - `A`: The type of the allocator, which must implement `Allocator`. ### Parameters - `alloc` (`A`): The allocator to use for memory allocation. ### Returns - `Box, A>`: A `Box` containing memory initialized to zero. ### Examples ```rust #![feature(allocator_api)] use std::alloc.System; let zero = Box::::new_zeroed_in(System); let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0) ``` ``` -------------------------------- ### pin_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a new `Pin>`. If `T` does not implement `Unpin`, then `x` will be pinned in memory and unable to be moved. ```APIDOC ## pin_in ### Description Constructs a new `Pin>`. If `T` does not implement `Unpin`, then `x` will be pinned in memory and unable to be moved. ### Signature `pub fn pin_in(x: T, alloc: A) -> Pin>` ### Type Parameters - `T`: The type of the value to be pinned. - `A`: The type of the allocator, which must implement `Allocator` and have a `'static` lifetime. ### Parameters - `x` (`T`): The value to be pinned. - `alloc` (`A`): The allocator to use for memory allocation. ### Returns - `Pin>`: A pinned `Box` containing the value. ### Notes Constructing and pinning of the `Box` can also be done in two steps: `Box::pin_in(x, alloc)` does the same as `Box::into_pin(Box::new_in(x, alloc))`. Consider using `into_pin` if you already have a `Box`, or if you want to construct a (pinned) `Box` in a different way than with `Box::new_in`. ### Examples ```rust #![feature(allocator_api)] use std::alloc.System; let x = Box::pin_in(1, System); ``` ``` -------------------------------- ### Register Apple Event for FruitApp Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Registers an Apple event with the FruitApp. Documentation is available in the OS X build. ```rust pub fn register_apple_event(&mut self, _class: u32, _id: u32) ``` -------------------------------- ### LogDir Enum Definition Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/enum.LogDir.html Defines the possible locations for logging output. Use Home for user's home directory, Temp for OS-defined temporary directory, or Custom with a String for a specific path. ```rust pub enum LogDir { Home, Temp, Custom(String), } ``` -------------------------------- ### into_pin Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Converts a Box into a Pin>. ```APIDOC ## into_pin ### Description Converts a `Box` into a `Pin>`. If `T` does not implement `Unpin`, then `*boxed` will be pinned in memory and unable to be moved. This conversion does not allocate on the heap and happens in place. This is also available via `From`. ### Method `pub fn into_pin(boxed: Box) -> Pin>` ### Parameters None ### Request Example ```rust let boxed_value = Box::new(5); let pinned_boxed = Box::into_pin(boxed_value); ``` ### Response `Pin>` - A pinned version of the Box. ``` -------------------------------- ### try_new_in Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory in the given allocator then places `x` into it, returning an error if the allocation fails. This doesn’t actually allocate if `T` is zero-sized. ```APIDOC ## try_new_in ### Description Allocates memory in the given allocator then places `x` into it, returning an error if the allocation fails. This doesn’t actually allocate if `T` is zero-sized. ### Signature `pub fn try_new_in(x: T, alloc: A) -> Result, AllocError>` ### Type Parameters - `T`: The type of the value to be boxed. - `A`: The type of the allocator, which must implement `Allocator`. ### Parameters - `x` (`T`): The value to place into the allocated memory. - `alloc` (`A`): The allocator to use for memory allocation. ### Returns - `Result, AllocError>`: A `Result` containing a `Box` on success, or an `AllocError` if the allocation fails. ### Examples ```rust #![feature(allocator_api)] use std::alloc.System; let five = Box::try_new_in(5, System)?; ``` ``` -------------------------------- ### map_windows Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Calls a function for each contiguous window of size `N` over the iterator and returns an iterator over the results. This is an experimental API. ```APIDOC ## fn map_windows(self, f: F) -> MapWindows ### Description Calls the given function `f` for each contiguous window of size `N` over `self` and returns an iterator over the outputs of `f`. Like `slice::windows()`, the windows during mapping overlap as well. This is a nightly-only experimental API. ### Method Iterator adapter (Experimental) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) An iterator over the results of applying the function to each window. #### Response Example None ``` -------------------------------- ### TryFrom Implementation Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.FruitApp.html Performs a conversion from type `U` to type `T`, returning a `Result`. This is a blanket implementation where `U` implements `Into`. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Box::new_zeroed Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a new Box with uninitialized contents, with the memory being filled with 0 bytes. ```APIDOC ## Box::new_zeroed ### Description Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes. ### Method Associated function (called as `Box::new_zeroed()`) ### Returns * **Box>** - A Box containing a zeroed, uninitialized value of type `T`. ### Remarks See `MaybeUninit::zeroed` for examples of correct and incorrect usage of this method. ### Examples ```rust let zero = Box::::new_zeroed(); let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0) ``` ``` -------------------------------- ### Set Multiple Plist Key-Value Pairs Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Sets multiple key-value pairs in the application's Info.plist from a vector. Documentation is available in the OS X build. ```rust pub fn plist_keys(&mut self, _pairs: &Vec<(&str, &str)>) -> &mut Self ``` -------------------------------- ### Create a Pinned Box Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Constructs a `Pin>`. If `T` is not `Unpin`, the value will be pinned in memory and cannot be moved. ```rust let five = Box::new(5); let pinned_five = Box::pin(five); ``` -------------------------------- ### Try to Create a Boxed Value with Fallback Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Attempts to allocate memory and place a value into it, returning a Result that indicates success or an allocation error. ```rust #![feature(allocator_api)] let five = Box::try_new(5)?; ``` -------------------------------- ### Set Trampoline Executable Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Sets the executable path for the Trampoline. Documentation is available in the OS X build. ```rust pub fn exe(&mut self, _exe: &str) -> &mut Self ``` -------------------------------- ### Set Plist Key-Value Pair Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Sets a specific key-value pair in the application's Info.plist. Documentation is available in the OS X build. ```rust pub fn plist_key(&mut self, _key: &str, _value: &str) -> &mut Self ``` -------------------------------- ### by_ref Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Creates a "by reference" adapter for an iterator, allowing mutable access to the iterator itself. ```APIDOC ## fn by_ref(&mut self) -> &mut Self ### Description Creates a “by reference” adapter for this instance of `Iterator`. This allows methods that consume `self` to be called on a mutable reference to the iterator. ### Method Iterator adapter ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) A mutable reference to the iterator. #### Response Example None ``` -------------------------------- ### Box::try_clone_from_ref Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory on the heap and clones the referenced value into it, returning an error if the allocation fails. This method does not allocate if the source value is zero-sized. ```APIDOC ## Box::try_clone_from_ref ### Description Allocates memory on the heap and clones the referenced value into it, returning an error if the allocation fails. This method does not allocate if the source value is zero-sized. ### Method Associated Function ### Parameters - **src** (&T) - A reference to the value to be cloned. ### Return Value - Result, AllocError> - A `Result` containing a new box with a clone of `src` on success, or an `AllocError` on failure. ### Examples ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] let hello: Box = Box::try_clone_from_ref("hello")?; ``` ``` -------------------------------- ### From Conversion Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/struct.Trampoline.html Returns the argument unchanged. This is a blanket implementation for `From` for type `T`. ```rust fn from(t: T) -> T ``` -------------------------------- ### into_inner Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Consumes the `Box`, returning the wrapped value. ```APIDOC ## into_inner ### Description Consumes the `Box`, returning the wrapped value. ### Signature `pub fn into_inner(boxed: Box) -> T` ### Type Parameters - `T`: The type of the value inside the `Box`. - `A`: The type of the allocator. ### Parameters - `boxed` (`Box`): The `Box` to consume. ### Returns - `T`: The value that was wrapped in the `Box`. ### Examples ```rust #![feature(box_into_inner)] let c = Box::new(5); assert_eq!(Box::into_inner(c), 5); ``` ``` -------------------------------- ### Box::clone_from_ref Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Allocates memory on the heap and then clones the referenced value into it. This method does not allocate if the source value is zero-sized. ```APIDOC ## Box::clone_from_ref ### Description Allocates memory on the heap and then clones the referenced value into it. This method does not allocate if the source value is zero-sized. ### Method Associated Function ### Parameters - **src** (&T) - A reference to the value to be cloned. ### Return Value - Box - A new box containing a clone of `src`. ### Examples ```rust #![feature(clone_from_ref)] let hello: Box = Box::clone_from_ref("hello"); ``` ``` -------------------------------- ### Recreate Box from NonNull Pointer Source: https://docs.rs/fruitbasket/0.10.0/fruitbasket/type.FruitObjcCallback.html Recreates a Box from a NonNull pointer and allocator, previously obtained using Box::into_non_null_with_allocator. This is the recommended way to manage memory after conversion. ```rust #![feature(allocator_api)] use std::alloc::System; let x = Box::new_in(5, System); let (non_null, alloc) = Box::into_non_null_with_allocator(x); let x = unsafe { Box::from_non_null_in(non_null, alloc) }; ```