### Edges Initialization Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Edges.html Example showing how to manually initialize an Edges instance. ```rust let edges = Edges { top: 10.0, right: 20.0, bottom: 30.0, left: 40.0, }; assert_eq!(edges.top, 10.0); assert_eq!(edges.right, 20.0); assert_eq!(edges.bottom, 30.0); assert_eq!(edges.left, 40.0); ``` -------------------------------- ### Edges::all Constructor Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Edges.html Example of using the all method to set all edges to the same value. ```rust let uniform_edges = Edges::all(10.0); assert_eq!(uniform_edges.top, 10.0); assert_eq!(uniform_edges.right, 10.0); assert_eq!(uniform_edges.bottom, 10.0); assert_eq!(uniform_edges.left, 10.0); ``` -------------------------------- ### trim_start_matches example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Demonstrates removing a slice of characters from the start of a string. ```rust let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12"); ``` -------------------------------- ### Install Xcode command line tools Source: https://docs.rs/gpui-pre/latest/gpui/index.html Run this command to install the necessary Xcode command line tools on macOS. ```bash xcode-select --install ``` -------------------------------- ### center method example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Bounds.html Returns the center point of the bounds by adding half the width and height to the origin. The example creates a bounds with origin (0,0) and size (10,20) and asserts the center is (5,10). ```rust let bounds = Bounds { origin: Point { x: 0, y: 0 }, size: Size { width: 10, height: 20 }, }; let center = bounds.center(); assert_eq!(center, Point { x: 5, y: 10 }); ``` -------------------------------- ### str::len example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to use the len method to get the byte length of a string, including a Unicode example. ```rust let len = "foo".len(); assert_eq!(3, len); assert_eq!("ƒoo".len(), 4); // fancy f! assert_eq!("ƒoo".chars().count(), 3); ``` -------------------------------- ### Example: to_pixels method usage Source: https://docs.rs/gpui-pre/latest/gpui/enum.DefiniteLength.html Example usage of the to_pixels method, converting absolute lengths and fractions to pixels. ```rust let length_in_pixels = DefiniteLength::Absolute(AbsoluteLength::Pixels(px(42.0))); let length_in_rems = DefiniteLength::Absolute(AbsoluteLength::Rems(rems(2.0))); let length_as_fraction = DefiniteLength::Fraction(0.5); let base_size = AbsoluteLength::Pixels(px(100.0)); let rem_size = px(16.0); assert_eq!(length_in_pixels.to_pixels(base_size, rem_size), Pixels::from(42.0)); assert_eq!(length_in_rems.to_pixels(base_size, rem_size), Pixels::from(32.0)); assert_eq!(length_as_fraction.to_pixels(base_size, rem_size), Pixels::from(50.0)); ``` -------------------------------- ### str::get example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to use the get method to safely get a subslice of a string, returning None for invalid indices. ```rust let v = String::from("🗻∈🌏"); assert_eq!(Some("🗻"), v.get(0..4)); // indices not on UTF-8 sequence boundaries assert!(v.get(1..).is_none()); assert!(v.get(..8).is_none()); // out of bounds assert!(v.get(..42).is_none()); ``` -------------------------------- ### Edges::any Method Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Edges.html Example of using the any method to check if any edge satisfies a predicate. ```rust let edges = Edges { top: 10, right: 0, bottom: 5, left: 0, }; assert!(edges.any(|value| *value == 0)); assert!(edges.any(|value| *value > 0)); assert!(!edges.any(|value| *value > 10)); ``` -------------------------------- ### Edges::zero Constructor Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Edges.html Example of using the zero constructor for Length-based edges. ```rust let no_edges = Edges::::zero(); assert_eq!(no_edges.top, Length::Definite(DefiniteLength::from(Pixels::ZERO))); assert_eq!(no_edges.right, Length::Definite(DefiniteLength::from(Pixels::ZERO))); assert_eq!(no_edges.bottom, Length::Definite(DefiniteLength::from(Pixels::ZERO))); assert_eq!(no_edges.left, Length::Definite(DefiniteLength::from(Pixels::ZERO))); ``` -------------------------------- ### str::as_bytes example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to convert a string slice to a byte slice using as_bytes. ```rust let bytes = "bors".as_bytes(); assert_eq!(b"bors", bytes); ``` -------------------------------- ### container_query usage example Source: https://docs.rs/gpui-pre/latest/gpui/fn.container_query.html Example usage of `container_query` that checks the width and renders either a 'Narrow layout' or 'Wide layout' div accordingly. ```rust container_query(|size, _window, _cx| { if size.width < px(240.) { div().child("Narrow layout") } else { div().child("Wide layout") } }); ``` -------------------------------- ### Edges::auto Constructor Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Edges.html Example of using the auto constructor for Length-based edges. ```rust let auto_edges = Edges::auto(); assert_eq!(auto_edges.top, Length::Auto); assert_eq!(auto_edges.right, Length::Auto); assert_eq!(auto_edges.bottom, Length::Auto); assert_eq!(auto_edges.left, Length::Auto); ``` -------------------------------- ### Path::new Source: https://docs.rs/gpui-pre/latest/gpui/struct.Path.html Creates a new path with the given starting point. ```APIDOC ## Path::new ### Description Creates a new path with the given starting point. ### Method new ### Signature pub fn new(start: Point) -> Self ### Parameters - **start** (Point) - Required - The starting point of the path. ### Returns - **Self** - A new Path instance. ``` -------------------------------- ### size function usage example Source: https://docs.rs/gpui-pre/latest/gpui/fn.size.html Demonstrates how to construct a Size instance and verify its dimensions. ```rust use gpui::size; let my_size = size(10, 20); assert_eq!(my_size.width, 10); assert_eq!(my_size.height, 20); ``` -------------------------------- ### str::floor_char_boundary example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to use floor_char_boundary to find the closest char boundary not exceeding a given index. ```rust let s = "❤️🧡💛💚💙💜"; assert_eq!(s.len(), 26); assert!(!s.is_char_boundary(13)); let closest = s.floor_char_boundary(13); assert_eq!(closest, 10); assert_eq!(&s[..closest], "❤️🧡"); ``` -------------------------------- ### Edges::map Method Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Edges.html Example of using the map method to transform edge values. ```rust let edges = Edges { top: 10, right: 20, bottom: 30, left: 40 }; let edges_float = edges.map(|&value| value as f32 * 1.1); assert_eq!(edges_float, Edges { top: 11.0, right: 22.0, bottom: 33.0, left: 44.0 }); ``` -------------------------------- ### key_bindings Source: https://docs.rs/gpui-pre/latest/gpui/struct.Context.html Gets all key bindings in the app. ```APIDOC ## key_bindings ### Description Get all key bindings in the app. ### Method pub fn key_bindings(&self) -> Rc> ### Returns - **Rc>** - The keymap containing all key bindings. ``` -------------------------------- ### half_perimeter method example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Bounds.html Calculates the half perimeter of the rectangle defined by the bounds, which is the sum of width and height. The example creates a bounds with size (10,20) and asserts the half perimeter is 30. ```rust let bounds = Bounds { origin: Point { x: 0, y: 0 }, size: Size { width: 10, height: 20 }, }; let half_perimeter = bounds.half_perimeter(); assert_eq!(half_perimeter, 30); ``` -------------------------------- ### trim_start Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Demonstrates trimming leading whitespace from a string containing Hebrew characters. ```rust let s = " עברית "; assert!(Some('ע') == s.trim_start().chars().next()); ``` -------------------------------- ### dilate method example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Bounds.html Expands the bounds by a specified amount in all directions. The example dilates a bounds with origin (10,10) and size (10,10) by 5, resulting in origin (5,5) and size (20,20). ```rust let mut bounds = Bounds { origin: Point { x: 10, y: 10 }, size: Size { width: 10, height: 10 }, }; let expanded_bounds = bounds.dilate(5); assert_eq!(expanded_bounds, Bounds { origin: Point { x: 5, y: 5 }, size: Size { width: 20, height: 20 }, }); ``` -------------------------------- ### Pixels usage example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Pixels.html Shows how to create a `Pixels` value, scale it, and compare with `ScaledPixels`. ```rust use gpui::{Pixels, ScaledPixels}; // Define a length of 10 pixels let length = Pixels::from(10.0); // Define a length and scale it by a factor of 2 let scaled_length = length.scale(2.0); assert_eq!(scaled_length, ScaledPixels::from(20.0)); ``` -------------------------------- ### Titlecase conversion example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Text.html Demonstrates the use of word_to_titlecase on a string slice. ```rust assert_eq!("Ο οδυσσέας βασιλιάς της ιθάκης", odysseus_king_of_ithaca.word_to_titlecase()); ``` -------------------------------- ### Initialize a GPUI application Source: https://docs.rs/gpui-pre/latest/gpui/index.html Create an application using gpui_platform::application() and start it with a callback to open windows and register views. ```rust use gpui::*; fn main() { gpui_platform::application().run(|cx: &mut App| { // .. }); } ``` -------------------------------- ### trim_start_matches Example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Removes prefixes matching a character or numeric check. ```rust assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123"); ``` -------------------------------- ### str::as_ptr example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to get a raw pointer to the string's bytes using as_ptr. ```rust let s = "Hello"; let ptr = s.as_ptr(); ``` -------------------------------- ### Application::run Source: https://docs.rs/gpui-pre/latest/gpui/struct.Application.html Start the application. The provided callback will be called once the app is fully launched. ```APIDOC ## Application::run ### Description Start the application. The provided callback will be called once the app is fully launched. ### Method run ### Signature pub fn run(self, on_finish_launching: F) where F: 'static + FnOnce(&mut App) ### Parameters - **on_finish_launching** (F) - Required - The callback to invoke once the app is fully launched. ``` -------------------------------- ### strip_prefix example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Demonstrates removing a prefix exactly once if it exists, returning an Option. ```rust assert_eq!("foo:bar".strip_prefix("foo:"), Some("bar")); assert_eq!("foo:bar".strip_prefix("bar"), None); assert_eq!("foofoo".strip_prefix("foo"), Some("foo")); ``` -------------------------------- ### Example using AvailableSpace::min_size() Source: https://docs.rs/gpui-pre/latest/gpui/enum.AvailableSpace.html Shows how to use the min_size() method to create a size with both dimensions set to MinContent, and then verify the result. ```rust use gpui::AvailableSpace; let min_content_size = AvailableSpace::min_size(); assert_eq!(min_content_size.width, AvailableSpace::MinContent); assert_eq!(min_content_size.height, AvailableSpace::MinContent); ``` -------------------------------- ### str::get_unchecked example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to use the unsafe get_unchecked method to get a subslice without bounds checking, with safety requirements. ```rust let v = "🗻∈🌏"; unsafe { assert_eq!("🗻", v.get_unchecked(0..4)); assert_eq!("∈", v.get_unchecked(4..7)); assert_eq!("🌏", v.get_unchecked(7..11)); } ``` -------------------------------- ### Example: is_ok() on Result Source: https://docs.rs/gpui-pre/latest/gpui/type.Result.html Returns true if the result is Ok. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### init Source: https://docs.rs/gpui-pre/latest/gpui/struct.SystemWindowTabController.html Initializes the global window tab controller. ```APIDOC ## init ### Description Initializes the global window tab controller. ### Method init ### Signature pub fn init(cx: &mut App) ### Parameters - **cx** (&mut App) - Required - The application context. ### Returns None ``` -------------------------------- ### Box::new_uninit_in example Source: https://docs.rs/gpui-pre/latest/gpui/type.InspectorRenderer.html Constructs a new box with uninitialized contents in the provided allocator. ```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) ``` -------------------------------- ### scrollbar_drag_started Source: https://docs.rs/gpui-pre/latest/gpui/struct.ListState.html Call this method when the user starts dragging the scrollbar. This prevents the height reported to the scrollbar from changing during the drag as items in the overdraw get measured, and helps offset scroll position changes accordingly. ```APIDOC ## scrollbar_drag_started ### Description Call this method when the user starts dragging the scrollbar. This will prevent the height reported to the scrollbar from changing during the drag as items in the overdraw get measured, and help offset scroll position changes accordingly. ### Method pub fn scrollbar_drag_started(&self) ### Parameters None ### Returns None ``` -------------------------------- ### Configure Linux and FreeBSD platform features Source: https://docs.rs/gpui-pre/latest/gpui/index.html Enable windowing backends for Linux or FreeBSD by specifying wayland, x11, or both. ```toml gpui_platform = { version = "*", features = ["wayland", "x11"] } ``` -------------------------------- ### Manually create Box from scratch using global allocator Source: https://docs.rs/gpui-pre/latest/gpui/type.InspectorRenderer.html Shows how to manually allocate memory and create a `Box` using `Box::from_raw`. Uses `alloc` and `Layout` to allocate, then writes a value before wrapping in a `Box`. ```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); } ``` -------------------------------- ### Product implementation example for Result Source: https://docs.rs/gpui-pre/latest/gpui/type.Result.html Demonstrates using the product method on an iterator of Results, which returns the product of all elements or the first Err encountered. ```rust let nums = vec!["5", "10", "1", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert_eq!(total, Ok(100)); let nums = vec!["5", "10", "one", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert!(total.is_err()); ``` -------------------------------- ### open_with_system Source: https://docs.rs/gpui-pre/latest/gpui/struct.App.html Opens the specified path with the system's default application. ```APIDOC ## open_with_system ### Description Opens the specified path with the system's default application. ### Method pub fn open_with_system(&self, path: &Path) ### Parameters - **path** (&Path) - Required - The path to open. ### Returns No return value. ``` -------------------------------- ### KeyContext::new_with_defaults Source: https://docs.rs/gpui-pre/latest/gpui/struct.KeyContext.html Initializes a new KeyContext with an 'os' key set to either 'macos', 'linux', 'windows', or 'unknown'. ```APIDOC ## KeyContext::new_with_defaults ### Description Initializes a new `KeyContext` that contains an `os` key set to either `macos`, `linux`, `windows` or `unknown`. ### Method `pub fn new_with_defaults() -> Self` ### Parameters None. ### Returns - `Self` - A new `KeyContext` instance with the default `os` key set. ``` -------------------------------- ### new Source: https://docs.rs/gpui-pre/latest/gpui/struct.SystemWindowTabController.html Creates a new instance of the window tab controller. ```APIDOC ## new ### Description Creates a new instance of the window tab controller. ### Method new ### Signature pub fn new() -> Self ### Parameters None ### Returns - **Self** - A new instance of SystemWindowTabController. ``` -------------------------------- ### str::is_empty example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to use the is_empty method to check if a string has zero length. ```rust let s = ""; assert!(s.is_empty()); let s = "not empty"; assert!(!s.is_empty()); ``` -------------------------------- ### str::ceil_char_boundary example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to use ceil_char_boundary to find the closest char boundary not below a given index. ```rust let s = "❤️🧡💛💚💙💜"; assert_eq!(s.len(), 26); assert!(!s.is_char_boundary(13)); let closest = s.ceil_char_boundary(13); assert_eq!(closest, 14); assert_eq!(&s[..closest], "❤️🧡💛"); ``` -------------------------------- ### pub fn paint_background(&self, origin: Point, line_height: Pixels, align: TextAlign, align_width: Option, window: &mut Window, cx: &mut App) -> Result<()> Source: https://docs.rs/gpui-pre/latest/gpui/struct.ShapedLine.html Paints the background of the line to the window. ```APIDOC ## pub fn paint_background(&self, origin: Point, line_height: Pixels, align: TextAlign, align_width: Option, window: &mut Window, cx: &mut App) -> Result<()> ### Description Paints the background of the line to the window. ### Parameters - `origin` (Point) - Required - The origin point for painting. - `line_height` (Pixels) - Required - The line height in pixels. - `align` (TextAlign) - Required - The text alignment. - `align_width` (Option) - Optional - The alignment width. - `window` (&mut Window) - Required - The window. - `cx` (&mut App) - Required - The app context. ### Returns - `Result<()>` - A successful indication if any. ``` -------------------------------- ### AsyncApp::open_window Source: https://docs.rs/gpui-pre/latest/gpui/struct.AsyncApp.html Open a window with the given options based on the root view returned by the given function. ```APIDOC ## AsyncApp::open_window ### Description Open a window with the given options based on the root view returned by the given function. ### Method open_window ### Signature pub fn open_window(&self, options: WindowOptions, build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity) -> Result> where V: 'static + Render ### Parameters - **options** (WindowOptions) - Required - The options for the window. - **build_root_view** (impl FnOnce(&mut Window, &mut App) -> Entity) - Required - A function that builds the root view for the window. ### Returns - **Result>** - A result containing the window handle, or an error. ``` -------------------------------- ### pub fn paint(&self, origin: Point, line_height: Pixels, align: TextAlign, align_width: Option, window: &mut Window, cx: &mut App) -> Result<()> Source: https://docs.rs/gpui-pre/latest/gpui/struct.ShapedLine.html Paints the line of text to the window. ```APIDOC ## pub fn paint(&self, origin: Point, line_height: Pixels, align: TextAlign, align_width: Option, window: &mut Window, cx: &mut App) -> Result<()> ### Description Paints the line of text to the window. ### Parameters - `origin` (Point) - Required - The origin point for painting. - `line_height` (Pixels) - Required - The line height in pixels. - `align` (TextAlign) - Required - The text alignment. - `align_width` (Option) - Optional - The alignment width. - `window` (&mut Window) - Required - The window. - `cx` (&mut App) - Required - The app context. ### Returns - `Result<()>` - A result indicating success or failure. ``` -------------------------------- ### str::is_char_boundary example Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Example showing how to use is_char_boundary to check if a byte index is a UTF-8 code point boundary. ```rust let s = "Löwe 老虎 Léopard"; assert!(s.is_char_boundary(0)); // start of `老` assert!(s.is_char_boundary(6)); assert!(s.is_char_boundary(s.len())); // second byte of `ö` assert!(!s.is_char_boundary(2)); // third byte of `老` assert!(!s.is_char_boundary(8)); ``` -------------------------------- ### new Source: https://docs.rs/gpui-pre/latest/gpui/struct.WindowTextSystem.html Creates a new WindowTextSystem with the given TextSystem. ```APIDOC ## new ### Description Creates a new WindowTextSystem with the given TextSystem. ### Method Constructor ### Parameters - **text_system** (Arc) - Required - The TextSystem to use. ### Returns - **WindowTextSystem** - A new WindowTextSystem instance. ``` -------------------------------- ### AppContext derive compile error example Source: https://docs.rs/gpui-pre/latest/gpui/derive.AppContext.html An example of a structure that will cause a compile error due to the missing #[app] attribute. ```rust #[derive(AppContext)] struct MyContext<'a> { app: &'a mut gpui::App } ``` -------------------------------- ### fn prefers_ime_for_printable_keys(&mut self, _window: &mut Window, _cx: &mut App) -> bool Source: https://docs.rs/gpui-pre/latest/gpui/trait.InputHandler.html Returns whether printable keys should be routed to the IME before keybinding matching when a non-ASCII input source is active. Defaults to false. ```APIDOC ## fn prefers_ime_for_printable_keys(&mut self, _window: &mut Window, _cx: &mut App) -> bool ### Description Returns whether printable keys should be routed to the IME before keybinding matching when a non-ASCII input source (e.g. Japanese, Korean, Chinese IME) is active. This prevents multi-stroke keybindings like `jj` from intercepting keys that the IME should compose. Defaults to `false`. ### Parameters - **_window** (&mut Window) - Required - The window context. - **_cx** (&mut App) - Required - The application context. ### Returns - **bool** - Whether printable keys should be routed to the IME. ``` -------------------------------- ### block_on usage example Source: https://docs.rs/gpui-pre/latest/gpui/fn.block_on.html Example of using pollster::block_on to run an async block. The future is an empty async block, and the result is stored in a variable. ```rust let my_fut = async {}; let result = pollster::block_on(my_fut); ``` -------------------------------- ### start_window_move Source: https://docs.rs/gpui-pre/latest/gpui/struct.Window.html Handles window movement for Linux and macOS. Tells the compositor to take control of window movement (Wayland and X11). Events may not be received during a move operation. ```APIDOC ## start_window_move ### Description Handles window movement for Linux and macOS. Tells the compositor to take control of window movement (Wayland and X11). Events may not be received during a move operation. ### Method pub fn start_window_move(&self) ### Parameters None ### Returns None ``` -------------------------------- ### Example: is_ok_and() on Result Source: https://docs.rs/gpui-pre/latest/gpui/type.Result.html Returns true if the result is Ok and the value inside matches a predicate. The example also shows using as_ref() to avoid moving the value. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### fn text_input_configuration(&mut self, _window: &mut Window, _cx: &mut App) -> TextInputConfiguration Source: https://docs.rs/gpui-pre/latest/gpui/trait.InputHandler.html Gets this handler's preferences for platform text assistance. GPUI re-queries this every frame and forwards it to the platform window only when it changes. ```APIDOC ## fn text_input_configuration(&mut self, _window: &mut Window, _cx: &mut App) -> TextInputConfiguration ### Description Get this handler's preferences for platform text assistance. GPUI re-queries this every frame and forwards it to the platform window only when it changes, so implementations must be cheap and may vary the result with application state. ### Parameters - **_window** (&mut Window) - Required - The window context. - **_cx** (&mut App) - Required - The application context. ### Returns - **TextInputConfiguration** - The handler's text input configuration. ``` -------------------------------- ### str::rsplit_terminator Source: https://docs.rs/gpui-pre/latest/gpui/struct.SharedUri.html Returns an iterator over substrings of the string slice, separated by a pattern, starting from the end of the string, and omitting the leading empty substring if the string starts with the pattern. ```APIDOC ## str::rsplit_terminator ### Description Returns an iterator over substrings of the string slice, separated by a pattern, starting from the end of the string, and omitting the leading empty substring if the string starts with the pattern. ### Method pub fn rsplit_terminator

(&self, pat: P) -> RSplitTerminator<'_, P> where P: Pattern,

::Searcher<'a>: for<'a> ReverseSearcher<'a> ### Parameters - **pat** (P) - Required - The pattern to split on. Can be a &str, char, slice of chars, or a closure. ### Examples ```rust let v: Vec<&str> = "A.B:C.D".rsplit_terminator(&['.', ':'][..]).collect(); assert_eq!(v, ["D", "C", "B", "A"]); ``` ``` -------------------------------- ### Creating a Bounds with new Source: https://docs.rs/gpui-pre/latest/gpui/struct.Bounds.html Example of constructing a Bounds using the new method with a Point and Size, then asserting the origin and size. ```rust let origin = Point { x: 0, y: 0 }; let size = Size { width: 10, height: 20 }; let bounds = Bounds::new(origin, size); assert_eq!(bounds.origin, origin); assert_eq!(bounds.size, size); ``` -------------------------------- ### KeyBinding::new Source: https://docs.rs/gpui-pre/latest/gpui/struct.KeyBinding.html Constructs a new keybinding from the given data. Panics on parse error. ```APIDOC ## KeyBinding::new ### Description Construct a new keybinding from the given data. Panics on parse error. ### Method `pub fn new(keystrokes: &str, action: A, context: Option<&str>) -> Self` ### Parameters - `keystrokes` (`&str`) - Required - The keystrokes for the keybinding. - `action` (`A`) - Required - The action to bind. - `context` (`Option<&str>`) - Optional - The context for the keybinding. ### Returns - `Self` - The new KeyBinding instance. ``` -------------------------------- ### DevicePixels::to_bytes usage example Source: https://docs.rs/gpui-pre/latest/gpui/struct.DevicePixels.html Demonstrates calculating the total memory bytes required for a given number of device pixels based on bytes per pixel. ```rust let pixels = DevicePixels(10); // 10 device pixels let bytes_per_pixel = 4; // Assume each pixel is represented by 4 bytes (e.g., RGBA) let total_bytes = pixels.to_bytes(bytes_per_pixel); assert_eq!(total_bytes, 40); // 10 pixels * 4 bytes/pixel = 40 bytes ``` -------------------------------- ### intersects method example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Bounds.html Checks if two Bounds instances overlap. Returns true if there is any intersection, false otherwise. The example creates three bounds and asserts that the first intersects with the second but not the third. ```rust let bounds1 = Bounds { origin: Point { x: 0, y: 0 }, size: Size { width: 10, height: 10 }, }; let bounds2 = Bounds { origin: Point { x: 5, y: 5 }, size: Size { width: 10, height: 10 }, }; let bounds3 = Bounds { origin: Point { x: 20, y: 20 }, size: Size { width: 10, height: 10 }, }; assert_eq!(bounds1.intersects(&bounds2), true); // Overlapping bounds assert_eq!(bounds1.intersects(&bounds3), false); // Non-overlapping bounds ``` -------------------------------- ### window_id Source: https://docs.rs/gpui-pre/latest/gpui/struct.AnyWindowHandle.html Gets the ID of this window. ```APIDOC ## window_id ### Description Returns the window ID associated with this handle. ### Method `pub fn window_id(&self) -> WindowId` ### Return Value - `WindowId` - The ID of the window. ``` -------------------------------- ### Example usage of point Source: https://docs.rs/gpui-pre/latest/gpui/fn.point.html Demonstrates creating a new point with integer coordinates and verifying the values of its x and y fields. ```rust use gpui::point; let p = point(10, 20); assert_eq!(p.x, 10); assert_eq!(p.y, 20); ``` -------------------------------- ### pub fn starts_with

(&self, pat: P) -> bool Source: https://docs.rs/gpui-pre/latest/gpui/struct.Text.html Returns true if the given pattern matches a prefix of this string slice. ```APIDOC ## pub fn starts_with

(&self, pat: P) -> bool ### Description Returns true if the given pattern matches a prefix of this string slice, otherwise returns false. ### Parameters - **pat** (P) - Required - The pattern to check as a prefix. ``` -------------------------------- ### get Source: https://docs.rs/gpui-pre/latest/gpui/struct.ImageFormatIter.html Returns an iterator over a subsection of the iterator. ```APIDOC ## get ### Description Returns an iterator over a subsection of the iterator. ### Method get ### Signature fn get(self, index: R) -> >::Output where Self: Sized, R: IteratorIndex ### Parameters - **index** (R) - Required - The index or range specifying the subsection. ### Returns >::Output - An iterator over the specified subsection. ``` -------------------------------- ### Size::min method example Source: https://docs.rs/gpui-pre/latest/gpui/struct.Size.html Returns a new Size containing the minimum width and height values from two instances. ```rust let size1 = Size { width: 30, height: 40 }; let size2 = Size { width: 50, height: 20 }; let min_size = size1.min(&size2); assert_eq!(min_size, Size { width: 30, height: 20 }); ``` -------------------------------- ### KeyBinding::meta Source: https://docs.rs/gpui-pre/latest/gpui/struct.KeyBinding.html Gets the metadata for this binding. ```APIDOC ## KeyBinding::meta ### Description Get the metadata for this binding. ### Method `pub fn meta(&self) -> Option` ### Returns - `Option` - The metadata, if any. ``` -------------------------------- ### keyboard_mapper Source: https://docs.rs/gpui-pre/latest/gpui/struct.Context.html Gets the current keyboard mapper. ```APIDOC ## keyboard_mapper ### Description Get the current keyboard mapper. ### Method pub fn keyboard_mapper(&self) -> &Rc ### Parameters None ### Returns &Rc - The current keyboard mapper. ``` -------------------------------- ### open_window Source: https://docs.rs/gpui-pre/latest/gpui/trait.Platform.html Opens a new window with the given handle and options. ```APIDOC ## open_window ### Description Opens a new window with the given handle and options. ### Method open_window ### Signature fn open_window(&self, handle: AnyWindowHandle, options: WindowParams) -> Result> ### Parameters - **handle** (AnyWindowHandle) - Required - The handle for the new window. - **options** (WindowParams) - Required - The parameters for the new window. ### Returns - **Result>** - The platform window object, or an error. ``` -------------------------------- ### Create an entity with cx.new Source: https://docs.rs/gpui-pre/latest/gpui/_ownership_and_data_flow/index.html Shows the basic pattern of creating an entity with `cx.new` inside the `run` callback. The `App` reference `cx` owns all entity state, and `new` returns an `Entity` handle. ```rust gpui_platform::application().run(|cx: &mut App| { let _counter: Entity = cx.new(|_cx| Counter { count: 0 }); // ... }); ``` -------------------------------- ### read Source: https://docs.rs/gpui-pre/latest/gpui/struct.Entity.html Gets a reference to the entity from the context. ```APIDOC ## read ### Description Grab a reference to this entity from the context. ### Method read ### Signature pub fn read<'a>(&self, cx: &'a App) -> &'a T ### Parameters - **cx** (&'a App) - The application context. ### Returns - **&'a T** - A reference to the entity data. ``` -------------------------------- ### Constructing Uniform Corners Source: https://docs.rs/gpui-pre/latest/gpui/struct.Corners.html Example of using the all() method to initialize a Corners instance with the same value for all four corners. ```rust let uniform_corners = Corners::all(5.0); assert_eq!(uniform_corners.top_left, 5.0); assert_eq!(uniform_corners.top_right, 5.0); assert_eq!(uniform_corners.bottom_right, 5.0); assert_eq!(uniform_corners.bottom_left, 5.0); ``` -------------------------------- ### get_menus Source: https://docs.rs/gpui-pre/latest/gpui/struct.App.html Gets the menu bar for this application. ```APIDOC ## get_menus ### Description Gets the menu bar for this application. ### Method pub fn get_menus(&self) -> Option> ### Returns - **Option>** - The menu bar if set, otherwise None. ``` -------------------------------- ### KeyBinding::load Source: https://docs.rs/gpui-pre/latest/gpui/struct.KeyBinding.html Loads a keybinding from the given raw data. ```APIDOC ## KeyBinding::load ### Description Load a keybinding from the given raw data. ### Method `pub fn load(keystrokes: &str, action: Box, context_predicate: Option>, use_key_equivalents: bool, action_input: Option, keyboard_mapper: &dyn PlatformKeyboardMapper) -> Result` ### Parameters - `keystrokes` (`&str`) - Required - The keystrokes for the keybinding. - `action` (`Box`) - Required - The action to bind. - `context_predicate` (`Option>`) - Optional - The context predicate. - `use_key_equivalents` (`bool`) - Required - Whether to use key equivalents. - `action_input` (`Option`) - Optional - The action input. - `keyboard_mapper` (`&dyn PlatformKeyboardMapper`) - Required - The keyboard mapper. ### Returns - `Result` - The loaded KeyBinding or an error. ``` -------------------------------- ### Text::as_str Source: https://docs.rs/gpui-pre/latest/gpui/struct.Text.html Gets a &str from the underlying string. ```APIDOC ## Text::as_str ### Description Gets a `&str` from the underlying string. ### Method `pub fn as_str(&self) -> &str` ### Returns - **&str** - The string slice. ``` -------------------------------- ### ScrollHandle::bounds_for_item Source: https://docs.rs/gpui-pre/latest/gpui/struct.ScrollHandle.html Gets the bounds for a specific child. ```APIDOC ## ScrollHandle::bounds_for_item ### Description Get the bounds for a specific child. ### Method `pub fn bounds_for_item(&self, ix: usize) -> Option>` ### Parameters - `&self` - The scroll handle. - `ix` (usize) - The index of the child. ### Returns - `Option>` - The bounds of the child, or `None` if the index is out of range. ``` -------------------------------- ### Example: Using Result in main Source: https://docs.rs/gpui-pre/latest/gpui/type.Result.html Demonstrates using Result as the return type of main, with the ? operator to propagate errors and print failures with context. ```rust use anyhow::Result; fn main() -> Result<()> { let config = std::fs::read_to_string("cluster.json")?; let map: ClusterMap = serde_json::from_str(&config)?; println!("cluster info: {:#?}", map); Ok(()) } ``` -------------------------------- ### pub fn paint(&self, bounds: Bounds, window: &mut Window, cx: &mut App, continuation: impl FnOnce(&mut Window, &mut App)) Source: https://docs.rs/gpui-pre/latest/gpui/struct.Style.html Paints the background of an element styled with this style. ```APIDOC ## paint ### Description Paints the background of an element styled with this style. ### Method paint ### Signature pub fn paint(&self, bounds: Bounds, window: &mut Window, cx: &mut App, continuation: impl FnOnce(&mut Window, &mut App)) ### Parameters - **bounds** (Bounds) - The bounds of the element. - **window** (&mut Window) - The window to paint into. - **cx** (&mut App) - The application context. - **continuation** (impl FnOnce(&mut Window, &mut App)) - A closure to continue painting. ``` -------------------------------- ### ScrollHandle::max_offset Source: https://docs.rs/gpui-pre/latest/gpui/struct.ScrollHandle.html Gets the maximum scroll offset. ```APIDOC ## ScrollHandle::max_offset ### Description Get the maximum scroll offset. ### Method `pub fn max_offset(&self) -> Point` ### Parameters - `&self` - The scroll handle. ### Returns - `Point` - The maximum scroll offset. ``` -------------------------------- ### ScrollHandle::offset Source: https://docs.rs/gpui-pre/latest/gpui/struct.ScrollHandle.html Gets the current scroll offset. ```APIDOC ## ScrollHandle::offset ### Description Get the current scroll offset. ### Method `pub fn offset(&self) -> Point` ### Parameters - `&self` - The scroll handle. ### Returns - `Point` - The current scroll offset. ``` -------------------------------- ### TextSystem::new Source: https://docs.rs/gpui-pre/latest/gpui/struct.TextSystem.html Creates a new TextSystem with the given platform text system. ```APIDOC ## TextSystem::new ### Description Creates a new TextSystem with the given platform text system. ### Method new ### Parameters - **platform_text_system** (Arc) - Required - The platform text system to use. ### Returns - **Self** - A new TextSystem instance. ``` -------------------------------- ### RenderImage::frame_count Source: https://docs.rs/gpui-pre/latest/gpui/struct.RenderImage.html Gets the number of frames in the image. ```APIDOC ## RenderImage::frame_count ### Description Gets the number of frames in the image. ### Method `pub fn frame_count(&self) -> usize` ### Returns - `usize` - The number of frames in the image. ``` -------------------------------- ### KeyBinding::action Source: https://docs.rs/gpui-pre/latest/gpui/struct.KeyBinding.html Gets the action associated with this binding. ```APIDOC ## KeyBinding::action ### Description Get the action associated with this binding. ### Method `pub fn action(&self) -> &dyn Action` ### Returns - `&dyn Action` - The action. ``` -------------------------------- ### activate_window Source: https://docs.rs/gpui-pre/latest/gpui/struct.Window.html Focuses the current window and brings it to the foreground at the platform level. ```APIDOC ## activate_window ### Description Focuses the current window and brings it to the foreground at the platform level. ### Method pub fn activate_window(&self) ``` -------------------------------- ### KeyBinding::keystrokes Source: https://docs.rs/gpui-pre/latest/gpui/struct.KeyBinding.html Gets the keystrokes associated with this binding. ```APIDOC ## KeyBinding::keystrokes ### Description Get the keystrokes associated with this binding. ### Method `pub fn keystrokes(&self) -> &[KeybindingKeystroke]` ### Returns - `&[KeybindingKeystroke]` - The keystrokes. ``` -------------------------------- ### AsyncWindowContext::new Source: https://docs.rs/gpui-pre/latest/gpui/struct.AsyncWindowContext.html Creates a new entity in the app context using a build closure. ```APIDOC ## AsyncWindowContext::new ### Description Creates a new entity in the app context using a build closure. ### Method fn new(&mut self, build_entity: impl FnOnce(&mut Context<'_, T>) -> T) -> Entity ### Parameters - **build_entity** (impl FnOnce(&mut Context<'_, T>) -> T) - Required - A closure that builds the entity. ### Returns - **Entity** - The newly created entity. ``` -------------------------------- ### Box::new_uninit Source: https://docs.rs/gpui-pre/latest/gpui/type.InspectorRenderer.html Constructs a new box with uninitialized contents. ```APIDOC ## Box::new_uninit ### Description Constructs a new box with uninitialized contents. ### Signature pub fn new_uninit() -> Box> ### Returns - **Box>** - A box with uninitialized contents. ### Examples ```rust let mut five = Box::::new_uninit(); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ``` -------------------------------- ### keyboard_layout Source: https://docs.rs/gpui-pre/latest/gpui/struct.Context.html Gets the id of the current keyboard layout. ```APIDOC ## keyboard_layout ### Description Get the id of the current keyboard layout. ### Method pub fn keyboard_layout(&self) -> &dyn PlatformKeyboardLayout ### Parameters None ### Returns &dyn PlatformKeyboardLayout - The current keyboard layout. ``` -------------------------------- ### Application::with_platform Source: https://docs.rs/gpui-pre/latest/gpui/struct.Application.html Builds an app with a caller-provided platform implementation. ```APIDOC ## Application::with_platform ### Description Builds an app with a caller-provided platform implementation. ### Method with_platform ### Signature pub fn with_platform(platform: Rc) -> Self ### Parameters - **platform** (Rc) - Required - The platform implementation to use. ### Returns - **Self** - The Application instance. ``` -------------------------------- ### ClipboardItem::entries Source: https://docs.rs/gpui-pre/latest/gpui/struct.ClipboardItem.html Get the item's entries. ```APIDOC ## ClipboardItem::entries ### Description Get the item's entries. ### Method entries ### Signature pub fn entries(&self) -> &[ClipboardEntry] ### Returns &[ClipboardEntry] - A slice of the clipboard entries. ``` -------------------------------- ### AnyView::entity_type Source: https://docs.rs/gpui-pre/latest/gpui/struct.AnyView.html Gets the TypeId of the underlying view. ```APIDOC ## AnyView::entity_type ### Description Gets the TypeId of the underlying view. ### Method entity_type ### Signature pub fn entity_type(&self) -> TypeId ### Returns - **TypeId** - The TypeId of the underlying view. ``` -------------------------------- ### Anchor::bits Source: https://docs.rs/gpui-pre/latest/gpui/layer_shell/struct.Anchor.html Get the underlying bits value. ```APIDOC ## Anchor::bits ### Description Get the underlying bits value. The returned value is exactly the bits set in this flags value. ### Method Associated function ### Signature `pub const fn bits(&self) -> u32` ### Parameters - `self` (`&Anchor`) - The flags value. ### Returns - `u32` - The underlying bits value. ``` -------------------------------- ### action_documentation Source: https://docs.rs/gpui-pre/latest/gpui/struct.App.html Returns a map from action names to documentation strings. ```APIDOC ## action_documentation ### Description Get a map from an action name to the documentation. ### Method pub fn action_documentation(&self) -> &HashMap<&'static str, &'static str> ### Returns - **&HashMap<&'static str, &'static str>** - A map from action names to documentation strings. ``` -------------------------------- ### Colors::get_global Source: https://docs.rs/gpui-pre/latest/gpui/colors/struct.Colors.html Get Colors from the global state. ```APIDOC ## Colors::get_global ### Description Get Colors from the global state. ### Method pub fn get_global(cx: &App) -> &Arc ### Parameters - **cx** (&App) - Required - The application context. ### Returns - **&Arc** - A reference to the global Colors instance. ``` -------------------------------- ### Box::pin_in example Source: https://docs.rs/gpui-pre/latest/gpui/type.InspectorRenderer.html Constructs a new Pin>. ```rust #![feature(allocator_api)] use std::alloc::System; let x = Box::pin_in(1, System); ``` -------------------------------- ### Keymap::new Source: https://docs.rs/gpui-pre/latest/gpui/struct.Keymap.html Creates a new keymap with the given bindings. ```APIDOC ## Keymap::new ### Description Creates a new keymap with the given bindings. ### Method new ### Signature pub fn new(bindings: Vec) -> Self ### Parameters - **bindings** (Vec) - Required - The initial key bindings to include in the keymap. ### Returns - **Self** - A new Keymap instance containing the given bindings. ``` -------------------------------- ### current_view Source: https://docs.rs/gpui-pre/latest/gpui/struct.Window.html Gets the entity ID for the currently rendering view. ```APIDOC ## current_view ### Description Gets the entity ID for the currently rendering view. ### Method pub fn current_view(&self) -> EntityId ### Returns - **EntityId** - The entity ID of the currently rendering view. ``` -------------------------------- ### init_visible Source: https://docs.rs/gpui-pre/latest/gpui/struct.SystemWindowTabController.html Initializes the visibility of the system window tab controller. ```APIDOC ## init_visible ### Description Initializes the visibility of the system window tab controller. ### Method init_visible ### Signature pub fn init_visible(cx: &mut App, visible: bool) ### Parameters - **cx** (&mut App) - Required - The application context. - **visible** (bool) - Required - The initial visibility state. ### Returns None ``` -------------------------------- ### Keymap::possible_next_bindings_for_input Source: https://docs.rs/gpui-pre/latest/gpui/struct.Keymap.html Finds the bindings that can follow the current input sequence. ```APIDOC ## Keymap::possible_next_bindings_for_input ### Description Finds the bindings that can follow the current input sequence. ### Method possible_next_bindings_for_input ### Signature pub fn possible_next_bindings_for_input(&self, input: &[Keystroke], context_stack: &[KeyContext]) -> Vec ### Parameters - **input** (&[Keystroke]) - Required - The current input sequence. - **context_stack** (&[KeyContext]) - Required - The stack of key contexts to evaluate bindings against. ### Returns - **Vec** - The bindings that can follow the current input sequence. ``` -------------------------------- ### TextStyle::font Source: https://docs.rs/gpui-pre/latest/gpui/struct.TextStyle.html Gets the font configured for this text style. ```APIDOC ## [Rust] TextStyle::font ### Description Gets the font configured for this text style. ### Method pub fn font(&self) -> Font ### Parameters None. ### Returns - **Font** - The font configured for this text style. ```