### capacity example Source: https://nxjxcx-game.docs.nxjxcx.com/src/async_broadcast/lib.rs.html Shows how to get the channel capacity using the capacity method. The example creates a channel with capacity 5 and asserts the returned capacity. ```rust use async_broadcast::broadcast; let (_s, r) = broadcast::(5); assert_eq!(r.capacity(), 5); ``` -------------------------------- ### set_overflow Example Source: https://nxjxcx-game.docs.nxjxcx.com/src/async_broadcast/lib.rs.html Shows how to set overflow behavior on a sender. The example is incomplete in the source; it only includes the assertion lines and lacks the setup code. ```rust /// assert_eq!(r.try_recv(), Err(TryRecvError::Overflowed(2))); /// assert_eq!(r.try_recv().unwrap(), 3); /// assert_eq!(r.try_recv().unwrap(), 4); /// assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); ``` -------------------------------- ### Bevy Audio Plugin Setup and Usage Example Source: https://nxjxcx-game.docs.nxjxcx.com/src/bevy_audio/lib.rs.html Shows how to set up the AudioPlugin and play background audio in a Bevy app. The example uses MinimalPlugins, AssetPlugin, and AudioPlugin, and spawns an entity with AudioPlayer and PlaybackSettings::LOOP to play an audio file. ```rust fn main() { App::new() .add_plugins((MinimalPlugins, AssetPlugin::default(), AudioPlugin::default())) .add_systems(Startup, play_background_audio) .run(); } fn play_background_audio(asset_server: Res, mut commands: Commands) { commands.spawn(( AudioPlayer::new(asset_server.load("background_audio.ogg")), PlaybackSettings::LOOP, )); } ``` -------------------------------- ### RefreshKind::cpu() example Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.RefreshKind.html Shows how to get the cpu refresh kind, starting from nothing, then setting it to everything, then removing it. ```rust use sysinfo::{RefreshKind, CpuRefreshKind}; let r = RefreshKind::nothing(); assert_eq!(r.cpu().is_some(), false); let r = r.with_cpu(CpuRefreshKind::everything()); assert_eq!(r.cpu().is_some(), true); let r = r.without_cpu(); assert_eq!(r.cpu().is_some(), false); ``` -------------------------------- ### Plugin setup with systems and run conditions Source: https://nxjxcx-game.docs.nxjxcx.com/src/game_loading/lib.rs.html Configures the loading plugin with systems for preparation, handoff, and rendering. Uses run conditions like is_preparing and preparation_started to gate systems. Optionally adds render plugin, disables input during loading, and adds overlay systems. ```rust if self.rendering { app.add_plugins(render::LoadingRenderPlugin); } if !self.input_during_loading { app.configure_sets( Update, game_ui::UiSystems::Input.run_if(loading_input_enabled), ); } if self.overlay { app.add_systems(OnEnter(GameState::Loading), overlay) .add_systems( PostUpdate, draw.after(LoadingSystems) .run_if(is_preparing) .run_if(preparation_started), ) .add_systems(OnEnter(GameState::Menu), remove_overlay) .add_systems(OnExit(GameState::PostLoading), remove_overlay); } } } ``` -------------------------------- ### RefreshKind::memory() example Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.RefreshKind.html Shows how to get the memory refresh kind, starting from nothing, then setting it to everything, then removing it. ```rust use sysinfo::{RefreshKind, MemoryRefreshKind}; let r = RefreshKind::nothing(); assert_eq!(r.memory().is_some(), false); let r = r.with_memory(MemoryRefreshKind::everything()); assert_eq!(r.memory().is_some(), true); let r = r.without_memory(); assert_eq!(r.memory().is_some(), false); ``` -------------------------------- ### Bevy app setup with GameLoadingPlugin and state transitions Source: https://nxjxcx-game.docs.nxjxcx.com/src/game_loading/lib.rs.html Configures a Bevy app with GameLoadingPlugin, sets initial state, and adds a system to transition to Menu when preparation is done. Used in tests to verify loading behavior. ```rust .init_state::() .add_plugins(GameLoadingPlugin { rendering: false, overlay: false, input_during_loading: true, }) .add_systems( Update, (|mut next: ResMut>| next.set(GameState::Menu)) .run_if(is_preparing), ); app.world_mut().resource_mut::().0 = true; app.world_mut() .resource_mut::>() .set(phase); app.update(); assert!(matches!( app.world().resource::>(), NextState::Pending(GameState::Menu) )); app.update(); assert_eq!( *app.world().resource::>().get(), GameState::Menu ); ``` -------------------------------- ### RefreshKind::processes() example Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.RefreshKind.html Shows how to get the processes refresh kind, starting from nothing, then setting it to everything, then removing it. ```rust use sysinfo::{RefreshKind, ProcessRefreshKind}; let r = RefreshKind::nothing(); assert_eq!(r.processes().is_some(), false); let r = r.with_processes(ProcessRefreshKind::everything()); assert_eq!(r.processes().is_some(), true); let r = r.without_processes(); assert_eq!(r.processes().is_some(), false); ``` -------------------------------- ### Create System with everything loaded Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.System.html Creates a new System instance with everything loaded. ```rust use sysinfo::System; let s = System::new_all(); ``` -------------------------------- ### Reverse automaton to find start of match with MatchKind::All Source: https://nxjxcx-game.docs.nxjxcx.com/regex_automata/hybrid/dfa/struct.Config.html Constructs a reverse DFA with MatchKind::All to find the longest possible match, corresponding to the leftmost starting position. The example builds both forward and reverse DFAs, searches forward to get the end offset, then searches reverse on the anchored prefix to find the start. ```rust use regex_automata::{ hybrid::dfa::DFA, nfa::thompson::NFA, Anchored, HalfMatch, Input, MatchKind, }; let input = Input::new("123foobar456"); let pattern = r"[a-z]+r"; let dfa_fwd = DFA::new(pattern)?; let dfa_rev = DFA::builder() .thompson(NFA::config().reverse(true)) .configure(DFA::config().match_kind(MatchKind::All)) .build(pattern)?; let mut cache_fwd = dfa_fwd.create_cache(); let mut cache_rev = dfa_rev.create_cache(); let expected_fwd = HalfMatch::must(0, 9); let expected_rev = HalfMatch::must(0, 3); let got_fwd = dfa_fwd.try_search_fwd(&mut cache_fwd, &input)?.unwrap(); // Here we don't specify the pattern to search for since there's only // one pattern and we're doing a leftmost search. But if this were an // overlapping search, you'd need to specify the pattern that matched // in the forward direction. (Otherwise, you might wind up finding the // starting position of a match of some other pattern.) That in turn // requires building the reverse automaton with starts_for_each_pattern // enabled. let input = input .clone() .range(..got_fwd.offset()) .anchored(Anchored::Yes); let got_rev = dfa_rev.try_search_rev(&mut cache_rev, &input)?.unwrap(); assert_eq!(expected_fwd, got_fwd); assert_eq!(expected_rev, got_rev); ``` -------------------------------- ### WinitPlugin::ready() Source: https://nxjxcx-game.docs.nxjxcx.com/bevy_winit/struct.WinitPlugin.html Has the plugin finished its setup? This can be useful for plugins that need something asynchronous to happen before they can finish their setup, like the initialization of a renderer. Once the plugin is ready, `finish` should be called. ```APIDOC ## WinitPlugin::ready() ### Description Has the plugin finished its setup? This can be useful for plugins that need something asynchronous to happen before they can finish their setup, like the initialization of a renderer. Once the plugin is ready, `finish` should be called. ### Method `ready` ### Signature `fn ready(&self, _app: &App) -> bool` ### Parameters - **self** (`&WinitPlugin`) - The plugin instance. - **_app** (`&App`) - The application to check readiness for. ### Returns - **bool** - Whether the plugin has finished its setup. ``` -------------------------------- ### get method example Source: https://nxjxcx-game.docs.nxjxcx.com/slotmap/struct.DenseSlotMap.html Returns a reference to the value corresponding to the key. The example shows inserting a string, getting a reference, removing the key, and getting None. ```rust let mut sm = DenseSlotMap::new(); let key = sm.insert("bar"); assert_eq!(sm.get(key), Some(&"bar")); sm.remove(key); assert_eq!(sm.get(key), None); ``` -------------------------------- ### new_receiver() example Source: https://nxjxcx-game.docs.nxjxcx.com/src/async_broadcast/lib.rs.html Shows how to create a new receiver with new_receiver(). The new receiver starts with zero messages available and does not re-open a closed channel. After broadcasting two messages and dropping the sender, the original receiver gets both messages, while the new receiver only gets the second message and then receives RecvError::Closed. ```rust # futures_lite::future::block_on(async { use async_broadcast::{broadcast, RecvError}; let (s, mut r1) = broadcast(2); assert_eq!(s.broadcast(1).await, Ok(None)); let mut r2 = s.new_receiver(); assert_eq!(s.broadcast(2).await, Ok(None)); drop(s); assert_eq!(r1.recv().await, Ok(1)); assert_eq!(r1.recv().await, Ok(2)); assert_eq!(r1.recv().await, Err(RecvError::Closed)); assert_eq!(r2.recv().await, Ok(2)); assert_eq!(r2.recv().await, Err(RecvError::Closed)); # }); ``` -------------------------------- ### after Source: https://nxjxcx-game.docs.nxjxcx.com/game_loading/struct.BeginPostLoading.html Configures these systems to run after all systems in the specified set, with deferred operations applied. ```APIDOC ## after ### Description Run after all systems in `set`. If `set` has any systems that produce `Commands` or other `Deferred` operations, all systems in `self` will see their effect. ### Method after ### Signature fn after(self, set: impl IntoSystemSet) -> ScheduleConfigs ### Parameters - **set** (impl IntoSystemSet) - Required - The system set to run after. ### Returns - **ScheduleConfigs** - The updated schedule configuration. ``` -------------------------------- ### Example: Create and sample from PERT distribution Source: https://nxjxcx-game.docs.nxjxcx.com/rand_distr/struct.Pert.html Shows how to create a PERT distribution with min=0, max=5, mode=2.5, and sample a random value. ```rust use rand_distr::{Pert, Distribution}; let d = Pert::new(0., 5.).with_mode(2.5).unwrap(); let v = d.sample(&mut rand::rng()); println!("{} is from a PERT distribution", v); ``` -------------------------------- ### fold: Accumulate a computation over the stream Source: https://nxjxcx-game.docs.nxjxcx.com/futures_lite/stream/trait.StreamExt.html Accumulates a computation over the stream, starting with an initial value and applying a closure to each item. The example sums the numbers 1, 2, and 3 to get 6. ```rust use futures_lite::stream::{self, StreamExt}; let s = stream::iter(vec![1, 2, 3]); let sum = s.fold(0, |acc, x| acc + x).await; assert_eq!(sum, 6); ``` -------------------------------- ### environ: Get environ refresh kind Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.ProcessRefreshKind.html Returns the UpdateKind value of the 'environ' refresh kind. The example starts from ProcessRefreshKind::nothing() (Never), sets it to OnlyIfNotSet with with_environ(), then resets to Never with without_environ(), asserting each step. ```rust use sysinfo::{ProcessRefreshKind, UpdateKind}; let r = ProcessRefreshKind::nothing(); assert_eq!(r.environ(), UpdateKind::Never); let r = r.with_environ(UpdateKind::OnlyIfNotSet); assert_eq!(r.environ(), UpdateKind::OnlyIfNotSet); let r = r.without_environ(); assert_eq!(r.environ(), UpdateKind::Never); ``` -------------------------------- ### root: Get root refresh kind Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.ProcessRefreshKind.html Returns the UpdateKind value of the 'root' refresh kind. The example starts from ProcessRefreshKind::nothing() (Never), sets it to OnlyIfNotSet with with_root(), then resets to Never with without_root(), asserting each step. ```rust use sysinfo::{ProcessRefreshKind, UpdateKind}; let r = ProcessRefreshKind::nothing(); assert_eq!(r.root(), UpdateKind::Never); let r = r.with_root(UpdateKind::OnlyIfNotSet); assert_eq!(r.root(), UpdateKind::OnlyIfNotSet); let r = r.without_root(); assert_eq!(r.root(), UpdateKind::Never); ``` -------------------------------- ### BeginGameLoading and BeginPostLoading system sets Source: https://nxjxcx-game.docs.nxjxcx.com/src/game_loading/lib.rs.html System sets for scheduling game preparation and post-loading handoff. Schedule game preparation after BeginGameLoading and real-scene assembly after BeginPostLoading on state entry. ```rust /// Initial manifest setup inside [`PrepareGameLoading`]; schedule game preparation afterward. #[derive(SystemSet, Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct BeginGameLoading; /// Post-loading handoff set; schedule real-scene assembly after this set on state entry. #[derive(SystemSet, Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct BeginPostLoading; ``` -------------------------------- ### cwd: Get cwd refresh kind Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.ProcessRefreshKind.html Returns the UpdateKind value of the 'cwd' refresh kind. The example starts from ProcessRefreshKind::nothing() (Never), sets it to OnlyIfNotSet with with_cwd(), then resets to Never with without_cwd(), asserting each step. ```rust use sysinfo::{ProcessRefreshKind, UpdateKind}; let r = ProcessRefreshKind::nothing(); assert_eq!(r.cwd(), UpdateKind::Never); let r = r.with_cwd(UpdateKind::OnlyIfNotSet); assert_eq!(r.cwd(), UpdateKind::OnlyIfNotSet); let r = r.without_cwd(); assert_eq!(r.cwd(), UpdateKind::Never); ``` -------------------------------- ### Basic Executor Usage Example Source: https://nxjxcx-game.docs.nxjxcx.com/async_executor/index.html Shows how to create an async executor, spawn a task, and run it until completion using async_executor and futures_lite. The example prints 'Hello world' when the task runs. ```rust use async_executor::Executor; use futures_lite::future; // Create a new executor. let ex = Executor::new(); // Spawn a task. let task = ex.spawn(async { println!("Hello world"); }); // Run the executor until the task completes. future::block_on(ex.run(task)); ``` -------------------------------- ### memory: Get memory refresh kind Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.ProcessRefreshKind.html Returns the boolean value of the 'memory' refresh kind. The example starts from ProcessRefreshKind::nothing(), enables memory with with_memory(), asserts true, then disables with without_memory() and asserts false. ```rust use sysinfo::ProcessRefreshKind; let r = ProcessRefreshKind::nothing(); let r = r.with_memory(); assert_eq!(r.memory(), true); let r = r.without_memory(); assert_eq!(r.memory(), false); ``` -------------------------------- ### Connect to Wayland server and list globals via wl_registry Source: https://nxjxcx-game.docs.nxjxcx.com/wayland_client/index.html Commented example showing how to connect to the Wayland server, create an event queue, and use the wl_registry to list advertised globals. The Dispatch implementation handles the global event and prints the name, interface, and version. The roundtrip method blocks until the server processes the get_registry request and delivers the global events. ```rust use wayland_client::{protocol::wl_registry, Connection, Dispatch, QueueHandle}; // This struct represents the state of our app. This simple app does not // need any state, but this type still supports the `Dispatch` implementations. struct AppData; // Implement `Dispatch for our state. This provides the logic // to be able to process events for the wl_registry interface. // // The second type parameter is the user-data of our implementation. It is a // mechanism that allows you to associate a value to each particular Wayland // object, and allow different dispatching logic depending on the type of the // associated value. // // In this example, we just use () as we don't have any value to associate. See // the `Dispatch` documentation for more details about this. impl Dispatch for AppData { fn event( _state: &mut Self, _: &wl_registry::WlRegistry, event: wl_registry::Event, _: &(), _: &Connection, _: &QueueHandle, ) { // When receiving events from the wl_registry, we are only interested in the // `global` event, which signals a new available global. // When receiving this event, we just print its characteristics in this example. if let wl_registry::Event::Global { name, interface, version } = event { println!("[{}] {} (v{})", name, interface, version); } } } // The main function of our program fn main() { // Create a Wayland connection by connecting to the server through the // environment-provided configuration. let conn = Connection::connect_to_env().unwrap(); // Retrieve the WlDisplay Wayland object from the connection. This object is // the starting point of any Wayland program, from which all other objects will // be created. let display = conn.display(); // Create an event queue for our event processing let mut event_queue = conn.new_event_queue(); // And get its handle to associate new objects to it let qh = event_queue.handle(); // Create a wl_registry object by sending the wl_display.get_registry request. // This method takes two arguments: a handle to the queue that the newly created // wl_registry will be assigned to, and the user-data that should be associated // with this registry (here it is () as we don't need user-data). let _registry = display.get_registry(&qh, ()); // At this point everything is ready, and we just need to wait to receive the events // from the wl_registry. Our callback will print the advertised globals. println!("Advertised globals:"); // To actually receive the events, we invoke the `roundtrip` method. This method // is special and you will generally only invoke it during the setup of your program: // it will block until the server has received and processed all the messages you've // sent up to now. // // In our case, that means it'll block until the server has received our // wl_display.get_registry request, and as a reaction has sent us a batch of // wl_registry.global events. // // `roundtrip` will then empty the internal buffer of the queue it has been invoked // on, and thus invoke our `Dispatch` implementation that prints the list of advertised // globals. event_queue.roundtrip(&mut AppData).unwrap(); } ``` -------------------------------- ### Plugin::ready Source: https://nxjxcx-game.docs.nxjxcx.com/bevy_pbr/struct.GpuMeshPreprocessPlugin.html Has the plugin finished its setup? This can be useful for plugins that need something asynchronous to happen before they can finish their setup, like the initialization of a renderer. Once the plugin is ready, `finish` should be called. ```APIDOC ## Plugin::ready ### Description Has the plugin finished its setup? This can be useful for plugins that need something asynchronous to happen before they can finish their setup, like the initialization of a renderer. Once the plugin is ready, `finish` should be called. ### Method ready ### Parameters - **app** (&App) - Required - The application to check readiness for. ### Returns bool - Whether the plugin has finished its setup. ``` -------------------------------- ### Configure avian3d features in Cargo.toml Source: https://nxjxcx-game.docs.nxjxcx.com/avian3d/index.html Customize Avian by disabling default features and enabling specific ones. This example adds 3D physics with double-precision floating point numbers and XPBD joints. ```toml [dependencies] # Add 3D Avian with double-precision floating point numbers. # `parry-f64` enables collision detection using Parry. avian3d = { version = "0.8", default-features = false, features = ["3d", "f64", "parry-f64", "xpbd_joints"] } ``` -------------------------------- ### is_done example Source: https://nxjxcx-game.docs.nxjxcx.com/regex_automata/struct.Input.html Returns true if the search can never return any more matches, which occurs when the start position is greater than the end position. The example shows that setting start to 6 is not done, but setting start to 7 is done. ```rust use regex_automata::Input; let mut input = Input::new("foobar"); assert!(!input.is_done()); input.set_start(6); assert!(!input.is_done()); input.set_start(7); assert!(input.is_done()); ``` -------------------------------- ### Connect to example.com:80 with timeout using async_io Source: https://nxjxcx-game.docs.nxjxcx.com/async_io/index.html Shows how to use Async and Timer to connect to example.com:80 with a 10-second timeout. Requires the futures-lite crate for FutureExt and io. The example returns an error if the connection times out. ```rust use async_io::{Async, Timer}; use futures_lite::{future::FutureExt, io}; use std::net::{TcpStream, ToSocketAddrs}; use std::time::Duration; let addr = "example.com:80".to_socket_addrs()?.next().unwrap(); let stream = Async::::connect(addr).or(async { Timer::after(Duration::from_secs(10)).await; Err(io::ErrorKind::TimedOut.into()) }) .await?; ``` -------------------------------- ### Get reference with get() Source: https://nxjxcx-game.docs.nxjxcx.com/async_lock/struct.OnceCell.html Example showing how to get a reference to the inner value, returning None if not initialized. ```rust use async_lock::OnceCell; let cell = OnceCell::new(); assert!(cell.get().is_none()); cell.set(1).await; assert_eq!(cell.get(), Some(&1)); ``` -------------------------------- ### Example: Using toml! to Build a Table Source: https://nxjxcx-game.docs.nxjxcx.com/toml/macro.toml.html Shows how to use the `toml!` macro to create a `Table` from TOML syntax, then print it with `println!`. ```rust let cargo_toml = toml::toml! { [package] name = "toml" [dependencies] serde = "1.0" [dev-dependencies] serde_derive = "1.0" serde_json = "1.0" }; println!("{:#?}", cargo_toml); ``` -------------------------------- ### Uri::scheme() - Get scheme from relative URI Source: https://nxjxcx-game.docs.nxjxcx.com/http/uri/struct.Uri.html Gets the scheme of a relative `Uri`. The example parses `/hello/world` and asserts the scheme is none. ```rust let uri: Uri = "/hello/world".parse().unwrap(); assert!(uri.scheme().is_none()); ``` -------------------------------- ### FFI thumbnail example using FlatSamples and SampleLayout Source: https://nxjxcx-game.docs.nxjxcx.com/image/flat/index.html Shows how to accept a raw image buffer via FFI, wrap it in FlatSamples with a SampleLayout, convert to an Rgb view, and create a 64x64 thumbnail saved as output.png. Returns false on invalid layout or save failure. Requires the caller to provide a valid SampleLayout pointer. ```rust use std::ptr; use std::slice; use image::Rgb; use image::flat::{FlatSamples, SampleLayout}; use image::imageops::thumbnail; #[no_mangle] pub extern "C" fn store_rgb8_compressed( data: *const u8, len: usize, layout: *const SampleLayout ) -> bool { let samples = unsafe { slice::from_raw_parts(data, len) }; let layout = unsafe { ptr::read(layout) }; let buffer = FlatSamples { samples, layout, color_hint: None, }; let view = match buffer.as_view::>() { Err(_) => return false, // Invalid layout. Ok(view) => view, }; thumbnail(&view, 64, 64) .save("output.png") .map(|_| true) .unwrap_or_else(|_| false) } ``` -------------------------------- ### start example Source: https://nxjxcx-game.docs.nxjxcx.com/regex_automata/struct.Input.html Returns the start position of the search, which is the start of the span. Shows that the default start is 0 and that a span(2..4) sets start to 2. ```rust use regex_automata::Input; let input = Input::new("foobar"); assert_eq!(0, input.start()); let input = Input::new("foobar").span(2..4); assert_eq!(2, input.start()); ``` -------------------------------- ### Plugin::ready(&self, _app: &App) -> bool Source: https://nxjxcx-game.docs.nxjxcx.com/bevy_sprite_render/struct.Wireframe2dPlugin.html Has the plugin finished its setup? This can be useful for plugins that need something asynchronous to happen before they can finish their setup, like the initialization of a renderer. Once the plugin is ready, `finish` should be called. ```APIDOC ## Plugin::ready(&self, _app: &App) -> bool ### Description Has the plugin finished its setup? This can be useful for plugins that need something asynchronous to happen before they can finish their setup, like the initialization of a renderer. Once the plugin is ready, `finish` should be called. ### Method Trait method ### Parameters - **app** (`&App`) - Required - The application to check. ### Returns - `bool` - Whether the plugin is ready. ``` -------------------------------- ### Builder::method_ref() example Source: https://nxjxcx-game.docs.nxjxcx.com/http/request/struct.Builder.html Gets the HTTP method; returns `None` if the builder has an error. The example asserts the default `GET` and then the updated `POST`. ```rust let mut req = Request::builder(); assert_eq!(req.method_ref(),Some(&Method::GET)); req = req.method("POST"); assert_eq!(req.method_ref(),Some(&Method::POST)); ``` -------------------------------- ### IntoScheduleConfigs::in_set Source: https://nxjxcx-game.docs.nxjxcx.com/game_loading/struct.BeginGameLoading.html Adds the systems to a provided SystemSet. ```APIDOC ## [Rust] IntoScheduleConfigs::in_set ### Description Add these systems to the provided `set`. ### Method in_set ### Signature fn in_set(self, set: impl SystemSet) -> ScheduleConfigs ### Parameters - **self** (S) - Required - The SystemSet to configure. - **set** (impl SystemSet) - Required - The set to add the systems to. ### Returns - **ScheduleConfigs** - The resulting ScheduleConfigs. ``` -------------------------------- ### Uri::path() - Get path from relative URI Source: https://nxjxcx-game.docs.nxjxcx.com/http/uri/struct.Uri.html Gets the path component of a `Uri`. The example parses a relative URI and asserts the path is `/hello/world`. ```rust let uri: Uri = "/hello/world".parse().unwrap(); assert_eq!(uri.path(), "/hello/world"); ``` -------------------------------- ### in_set Source: https://nxjxcx-game.docs.nxjxcx.com/game_loading/struct.BeginPostLoading.html Adds the systems in this collection to the specified system set. ```APIDOC ## in_set ### Description Add these systems to the provided `set`. ### Method in_set ### Signature fn in_set(self, set: impl SystemSet) -> ScheduleConfigs ### Parameters - **set** (impl SystemSet) - Required - The system set to add these systems to. ### Returns - **ScheduleConfigs** - The updated schedule configuration. ``` -------------------------------- ### Uri::scheme() - Get scheme from absolute URI Source: https://nxjxcx-game.docs.nxjxcx.com/http/uri/struct.Uri.html Gets the scheme of an absolute `Uri`. The example parses `http://example.org/hello/world` and asserts the scheme is `Scheme::HTTP`. ```rust use http::uri::{Scheme, Uri}; let uri: Uri = "http://example.org/hello/world".parse().unwrap(); assert_eq!(uri.scheme(), Some(&Scheme::HTTP)); ``` -------------------------------- ### Create new System instance Source: https://nxjxcx-game.docs.nxjxcx.com/sysinfo/struct.System.html Creates a new System instance with nothing loaded. ```rust use sysinfo::System; let s = System::new(); ``` -------------------------------- ### Uri::path() - Get path from absolute URI Source: https://nxjxcx-game.docs.nxjxcx.com/http/uri/struct.Uri.html Gets the path component of an absolute `Uri`. The example parses `http://example.org/hello/world` and asserts the path is `/hello/world`. ```rust let uri: Uri = "http://example.org/hello/world".parse().unwrap(); assert_eq!(uri.path(), "/hello/world"); ``` -------------------------------- ### TOML configuration format example Source: https://nxjxcx-game.docs.nxjxcx.com/toml/index.html Shows a basic TOML document with a package table and dependencies, illustrating the format's readability. ```toml [package] name = "toml" [dependencies] serde = "1.0" ``` -------------------------------- ### IntoScheduleConfigs::after Source: https://nxjxcx-game.docs.nxjxcx.com/game_loading/struct.BeginGameLoading.html Configures the systems to run after all systems in the specified set. ```APIDOC ## [Rust] IntoScheduleConfigs::after ### Description Run after all systems in `set`. If `set` has any systems that produce `Commands` or other `Deferred` operations, all systems in `self` will see their effect. ### Method after ### Signature fn after(self, set: impl IntoSystemSet) -> ScheduleConfigs ### Parameters - **self** (S) - Required - The SystemSet to configure. - **set** (impl IntoSystemSet) - Required - The set to run after. ### Returns - **ScheduleConfigs** - The resulting ScheduleConfigs. ``` -------------------------------- ### start example Source: https://nxjxcx-game.docs.nxjxcx.com/aho_corasick/struct.Input.html Returns the start position of the search, equivalent to get_span().start(). ```rust use aho_corasick::Input; let input = Input::new("foobar"); assert_eq!(0, input.start()); let input = Input::new("foobar").span(2..4); assert_eq!(2, input.start()); ``` -------------------------------- ### When messages get sent with tick Source: https://nxjxcx-game.docs.nxjxcx.com/crossbeam_channel/fn.tick.html Example demonstrating the exact timing of messages sent by a tick channel. Shows that messages are sent at intervals of the duration from the start, and that a receiver blocked on recv() will receive the next scheduled message even if it was sent earlier. ```rust use std::thread; use std::time::{Duration, Instant}; use crossbeam_channel::tick; // Converts a number of milliseconds into a `Duration`. let ms = |ms| Duration::from_millis(ms); // Returns `true` if `a` and `b` are very close `Instant`s. let eq = |a, b| a + ms(65) > b && b + ms(65) > a; let start = Instant::now(); let r = tick(ms(100)); // This message was sent 100 ms from the start and received 100 ms from the start. assert!(eq(r.recv().unwrap(), start + ms(100))); assert!(eq(Instant::now(), start + ms(100))); thread::sleep(ms(500)); // This message was sent 200 ms from the start and received 600 ms from the start. assert!(eq(r.recv().unwrap(), start + ms(200))); assert!(eq(Instant::now(), start + ms(600))); // This message was sent 700 ms from the start and received 700 ms from the start. assert!(eq(r.recv().unwrap(), start + ms(700))); assert!(eq(Instant::now(), start + ms(700))); ``` -------------------------------- ### RenderPlugin build method with render sub-app setup Source: https://nxjxcx-game.docs.nxjxcx.com/src/bevy_render/lib.rs.html Initializes shader assets and loaders, adds render-related plugins, and configures the render sub-app with schedules and systems. Uses feature-gated resources for reflection and tracing. Requires a rendering backend to create the render world. ```rust impl Plugin for RenderPlugin { /// Initializes the renderer, sets up the [`RenderSystems`] and creates the rendering sub-app. fn build(&self, app: &mut App) { app.init_asset::() .init_asset_loader::(); load_shader_library!(app, "utils.wesl"); load_shader_library!(app, "view.wesl"); load_shader_library!(app, "maths.wesl"); load_shader_library!(app, "color_operations.wesl"); load_shader_library!(app, "bindless.wesl"); if insert_future_resources(&self.render_creation, app.world_mut()) { // We only create the render world and set up extraction if we // have a rendering backend available. app.add_plugins(ExtractPlugin::::new( error_handler::update_state, Render::base_schedule, Render.intern(), RenderSystems::ExtractCommands.intern(), RenderSystems::PostCleanup.intern(), )); }; app.add_plugins(( WindowRenderPlugin, CameraPlugin, ViewPlugin, MeshRenderAssetPlugin, GlobalsPlugin, TexturePlugin, BatchingPlugin { debug_flags: self.debug_flags, }, StoragePlugin, GpuReadbackPlugin::default(), OcclusionCullingPlugin, SparseBufferPlugin, MaterialBindGroupPlugin, #[cfg(feature = "tracing-tracy")] diagnostic::RenderDiagnosticsPlugin, )); let (sender, receiver) = bevy_time::create_time_channels(); app.insert_resource(receiver); let asset_server = app.world().resource::().clone(); app.init_resource::() .init_resource::(); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app.init_resource::(); render_app.init_resource::(); render_app.init_gpu_resource::(); render_app.insert_resource(sender); render_app.insert_resource(asset_server); render_app.insert_resource(RenderState::Initializing); render_app.add_systems( ExtractSchedule, ( extract_render_asset_bytes_per_frame, PipelineCache::extract_shaders, ), ); #[cfg(not(feature = "reflect_auto_register"))] render_app.init_resource::(); #[cfg(feature = "reflect_auto_register")] render_app.insert_resource(AppTypeRegistry::new_with_derived_types()); #[cfg(feature = "reflect_functions")] render_app.init_resource::(); render_app.add_schedule(RenderGraph::base_schedule()); render_app.init_schedule(RenderStartup); render_app .get_schedule_mut(RenderStartup) .unwrap() .set_executor(bevy_ecs::schedule::SingleThreadedExecutor::new()); render_app.update_schedule = Some(RenderRecovery.intern()); render_app.add_systems( RenderRecovery, (run_render_schedule.run_if(renderer_is_ready), send_time).chain(), ); render_app.add_systems( Render, ( (PipelineCache::process_pipeline_queue_system, render_system) .chain() .in_set(RenderSystems::Render), reset_render_asset_bytes_per_frame.in_set(RenderSystems::Cleanup), ), ); } } } ``` -------------------------------- ### Sender::capacity() Example Source: https://nxjxcx-game.docs.nxjxcx.com/src/async_broadcast/lib.rs.html Shows how to create a broadcast channel and check its capacity using the capacity() method. ```rust use async_broadcast::broadcast; let (s, r) = broadcast::(5); assert_eq!(s.capacity(), 5); ``` -------------------------------- ### When the message gets sent: verifying timing with after Source: https://nxjxcx-game.docs.nxjxcx.com/crossbeam_channel/fn.after.html Demonstrates that the message is sent exactly 100 ms after the channel creation, even if the receiver is not polled until later. The example sleeps 500 ms and asserts the received instant is close to start + 100 ms. ```rust use std::thread; use std::time::{Duration, Instant}; use crossbeam_channel::after; // Converts a number of milliseconds into a `Duration`. let ms = |ms| Duration::from_millis(ms); // Returns `true` if `a` and `b` are very close `Instant`s. let eq = |a, b| a + ms(60) > b && b + ms(60) > a; let start = Instant::now(); let r = after(ms(100)); thread::sleep(ms(500)); // This message was sent 100 ms from the start and received 500 ms from the start. assert!(eq(r.recv().unwrap(), start + ms(100))); assert!(eq(Instant::now(), start + ms(500))); ``` -------------------------------- ### new example Source: https://nxjxcx-game.docs.nxjxcx.com/bytes/struct.BytesMut.html Shows creating a BytesMut with default capacity, reserving space, and putting a slice. ```rust use bytes::{BytesMut, BufMut}; let mut bytes = BytesMut::new(); assert_eq!(0, bytes.len()); bytes.reserve(2); bytes.put_slice(b"xy"); assert_eq!(&b"xy"[..], &bytes[..]); ``` -------------------------------- ### get example: Look up value by char Source: https://nxjxcx-game.docs.nxjxcx.com/icu_collections/codepointtrie/struct.CodePointTrie.html Shows how to use get to retrieve the value associated with a char. The example uses the planes trie and asserts values for specific characters. ```rust use icu::collections::codepointtrie::planes; let trie = planes::get_planes_trie(); assert_eq!(0, trie.get('A')); // 'A' as u32 assert_eq!(0, trie.get('Ꮰ')); // 'Ꮰ' as u32 assert_eq!(1, trie.get('𐁄')); // '𐁄' as u32 ``` -------------------------------- ### Uri::scheme_str() - Get scheme as &str Source: https://nxjxcx-game.docs.nxjxcx.com/http/uri/struct.Uri.html Gets the scheme of a `Uri` as a `&str`. The example parses `http://example.org/hello/world` and asserts the scheme string is `"http"`. ```rust let uri: Uri = "http://example.org/hello/world".parse().unwrap(); assert_eq!(uri.scheme_str(), Some("http")); ``` -------------------------------- ### before Source: https://nxjxcx-game.docs.nxjxcx.com/game_loading/struct.BeginPostLoading.html Configures these systems to run before all systems in the specified set, with deferred operations applied. ```APIDOC ## before ### Description Runs before all systems in `set`. If `self` has any systems that produce `Commands` or other `Deferred` operations, all systems in `set` will see their effect. ### Method before ### Signature fn before(self, set: impl IntoSystemSet) -> ScheduleConfigs ### Parameters - **set** (impl IntoSystemSet) - Required - The system set to run before. ### Returns - **ScheduleConfigs** - The updated schedule configuration. ``` -------------------------------- ### broadcast_direct example Source: https://nxjxcx-game.docs.nxjxcx.com/src/async_broadcast/lib.rs.html Shows how to use broadcast_direct to send a message directly without waiting for capacity. The example creates a channel with capacity 1 and sends a message. ```rust /// # }); /// ``` pub fn broadcast_direct(&self, msg: T) -> Send<'_, T> { Send::_new(SendInner { sender: self, listener: None, msg: Some(msg), _pin: PhantomPinned, }) } ``` -------------------------------- ### find example: get leftmost match offsets Source: https://nxjxcx-game.docs.nxjxcx.com/regex_automata/hybrid/regex/struct.Regex.html Returns the start and end offset of the leftmost match, or None if no match exists. Panics if the search cannot complete; use Regex::try_search to handle errors. Demonstrates leftmost-first match semantics with alternation. ```rust use regex_automata::{Match, hybrid::regex::Regex}; let re = Regex::new("foo[0-9]+")?; let mut cache = re.create_cache(); assert_eq!( Some(Match::must(0, 3..11)), re.find(&mut cache, "zzzfoo12345zzz"), ); // Even though a match is found after reading the first byte (`a`), // the default leftmost-first match semantics demand that we find the // earliest match that prefers earlier parts of the pattern over latter // parts. let re = Regex::new("abc|a")?; let mut cache = re.create_cache(); assert_eq!(Some(Match::must(0, 0..3)), re.find(&mut cache, "abc")); ``` -------------------------------- ### Plugin implementation for GameLoadingPlugin Source: https://nxjxcx-game.docs.nxjxcx.com/src/game_loading/lib.rs.html Bevy plugin build method that initializes schedules and resources, adds systems for loading state, preparation, and rendering. Includes reset_preparation on entering Loading state, prepare system in AdvanceLoading set, begin in BeginGameLoading set, and chained render::gather and poll systems in LoadingSystems. ```rust impl Plugin for GameLoadingPlugin { fn build(&self, app: &mut App) { app.init_schedule(PrepareGameLoading) .init_resource::() .init_resource::() .init_resource::() .init_resource::() .init_resource::() .add_systems(OnEnter(GameState::Loading), reset_preparation) .add_systems( Update, prepare .in_set(AdvanceLoading) .run_if(in_state(GameState::Loading)), ) .add_systems(PrepareGameLoading, begin.in_set(BeginGameLoading)) .add_systems( PostUpdate, (render::gather, poll) .chain() .in_set(LoadingSystems) ``` -------------------------------- ### get example Source: https://nxjxcx-game.docs.nxjxcx.com/slotmap/struct.HopSlotMap.html Returns a reference to the value for a key. After removal, get returns None. ```rust let mut sm = HopSlotMap::new(); let key = sm.insert("bar"); assert_eq!(sm.get(key), Some(&"bar")); sm.remove(key); assert_eq!(sm.get(key), None); ``` -------------------------------- ### IntoScheduleConfigs::chain Source: https://nxjxcx-game.docs.nxjxcx.com/game_loading/struct.BeginGameLoading.html Treats the collection as a sequence of systems. ```APIDOC ## [Rust] IntoScheduleConfigs::chain ### Description Treat this collection as a sequence of systems. ### Method chain ### Signature fn chain(self) -> ScheduleConfigs ### Parameters - **self** (S) - Required - The SystemSet to configure. ### Returns - **ScheduleConfigs** - The resulting ScheduleConfigs. ``` -------------------------------- ### get() Example: Retrieve Value for Code Point Source: https://nxjxcx-game.docs.nxjxcx.com/icu_properties/struct.CodePointMapDataBorrowed.html Shows how to use the get method to retrieve the value associated with a code point. The example uses GeneralCategory and asserts specific values for '木' and '🎃'. ```rust use icu::properties::CodePointMapData; use icu::properties::props::GeneralCategory; let gc = CodePointMapData::::new(); assert_eq!(gc.get('木'), GeneralCategory::OtherLetter); // U+6728 assert_eq!(gc.get('🎃'), GeneralCategory::OtherSymbol); // U+1F383 JACK-O-LANTERN ``` -------------------------------- ### Method usage example Source: https://nxjxcx-game.docs.nxjxcx.com/http/method/struct.Method.html Shows how to use Method constants and methods: comparing GET with from_bytes, checking idempotency, and converting POST to a string. ```rust use http::Method; assert_eq!(Method::GET, Method::from_bytes(b"GET").unwrap()); assert!(Method::GET.is_idempotent()); assert_eq!(Method::POST.as_str(), "POST"); ``` -------------------------------- ### Load a library for use with get Source: https://nxjxcx-game.docs.nxjxcx.com/libloading/struct.Library.html Loads a library and stores it in a variable so that symbols can be retrieved with the `get` method. The library handle is used in subsequent examples that call `get`. ```rust let lib = unsafe { Library::new("/path/to/awesome.module").unwrap() }; ``` -------------------------------- ### Proxy usage examples Source: https://nxjxcx-game.docs.nxjxcx.com/ureq/struct.Proxy.html Shows three ways to create a Proxy: from a URI string with Proxy::new, using the builder pattern with Proxy::builder for SOCKS5 (including username, password, and resolve_target settings), and reading from environment variables with Proxy::try_from_env. The resolve_target(true) forces local DNS resolution before connecting to the proxy. ```rust use ureq::{Proxy, ProxyProtocol}; // Create a proxy from a URI string let proxy = Proxy::new("http://localhost:8080").unwrap(); // Create a proxy using the builder pattern let proxy = Proxy::builder(ProxyProtocol::Socks5) .host("proxy.example.com") .port(1080) .username("user") .password("pass") .resolve_target(true) // Force local DNS resolution .build() .unwrap(); // Read proxy settings from environment variables if let Some(proxy) = Proxy::try_from_env() { // Use proxy from environment } ``` -------------------------------- ### get example Source: https://nxjxcx-game.docs.nxjxcx.com/aligned_vec/struct.AVec.html Shows how to get a reference to an element or subslice using a position or range index. Returns None if out of bounds. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Renderer usage example Source: https://nxjxcx-game.docs.nxjxcx.com/annotate_snippets/struct.Renderer.html Shows how to create a styled Renderer, render a Report, and print the output using anstream. ```rust let report = // ... let renderer = Renderer::styled(); let output = renderer.render(report); anstream::println!("{output}"); ``` -------------------------------- ### get Source: https://nxjxcx-game.docs.nxjxcx.com/ureq/index.html Makes a GET request. This is used to retrieve data from the specified URL. ```APIDOC ## get ### Description Makes a GET request. This is used to retrieve data from the specified URL. ### Function `get(url: &str) -> RequestBuilder` ### Parameters - **url** (string) - Required - The URL to send the GET request to. ### Returns - **RequestBuilder** - A builder for configuring and sending the request. ``` -------------------------------- ### get with range using IteratorIndex Source: https://nxjxcx-game.docs.nxjxcx.com/src/itertools/lib.rs.html Shows how to use the `get` method with range syntax on an iterator, returning collected values. The examples demonstrate `get(2..)`, `get(..=2)`, and `get(..)` with assertions on the results. ```rust /// range = vec.iter().get(2..).copied().collect(); /// assert_eq!(&range, &[4, 1, 5]); /// /// range = vec.iter().get(..=2).copied().collect(); /// assert_eq!(&range, &[3, 1, 4]); /// /// range = vec.iter().get(..).copied().collect(); /// assert_eq!(range, vec); ``` -------------------------------- ### Play the stream Source: https://nxjxcx-game.docs.nxjxcx.com/cpal/index.html Starts the audio stream. Not all platforms start automatically, so this ensures playback begins. ```rust stream.play().unwrap(); ```