### Trim start matches example Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Demonstrates removing a set of characters from the start of a string. ```rust let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12"); ``` -------------------------------- ### String Method Examples Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.ForceDispositionName.html Examples demonstrating the usage of methods inherited from String via Deref. ```rust let s = String::from("foo"); assert_eq!("foo", s.as_str()); ``` ```rust let s = String::with_capacity(10); assert!(s.capacity() >= 10); ``` ```rust let s = String::from("hello"); assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes()); ``` ```rust let a = String::from("foo"); assert_eq!(a.len(), 3); let fancy_f = String::from("ƒoo"); assert_eq!(fancy_f.len(), 4); assert_eq!(fancy_f.chars().count(), 3); ``` ```rust let mut v = String::new(); assert!(v.is_empty()); v.push('a'); assert!(!v.is_empty()); ``` -------------------------------- ### Strip prefix and suffix examples Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.SecondaryCardAwardsItemVariant0ExclusiveGroup.html Examples for removing prefixes and suffixes from strings, returning Option<&str>. ```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")); ``` ```rust assert_eq!("bar:foo".strip_suffix(":foo"), Some("bar")); assert_eq!("bar:foo".strip_suffix("bar"), None); assert_eq!("foofoo".strip_suffix("foo"), Some("foo")); ``` -------------------------------- ### Trim prefix and suffix nightly examples Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.SecondaryCardAwardsItemVariant0ExclusiveGroup.html Examples for the nightly-only trim_prefix and trim_suffix methods, which return &str for chaining. ```rust #![feature(trim_prefix_suffix)] // Prefix present - removes it assert_eq!("foo:bar".trim_prefix("foo:"), "bar"); assert_eq!("foofoo".trim_prefix("foo"), "foo"); // Prefix absent - returns original string assert_eq!("foo:bar".trim_prefix("bar"), "foo:bar"); // Method chaining example assert_eq!("".trim_prefix('<').trim_suffix('>'), "https://example.com/"); ``` ```rust #![feature(trim_prefix_suffix)] // Suffix present - removes it assert_eq!("bar:foo".trim_suffix(":foo"), "bar"); assert_eq!("foofoo".trim_suffix("foo"), "foo"); // Suffix absent - returns original string assert_eq!("bar:foo".trim_suffix("bar"), "bar:foo"); ``` -------------------------------- ### Check Vector Capacity Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Examples demonstrating how to check the capacity of a vector. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` ```rust #[derive(Clone)] struct ZeroSized; fn main() { assert_eq!(std::mem::size_of::(), 0); let v = vec![ZeroSized; 0]; assert_eq!(v.capacity(), usize::MAX); } ``` -------------------------------- ### Trim start matches Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Removes prefixes that match a specified pattern. ```rust assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123"); ``` -------------------------------- ### starts_with

(pat: P) Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Checks if the string starts with the given pattern. ```APIDOC ## pub fn starts_with

(&self, pat: P) -> bool ### Description Returns `true` if the given pattern matches a prefix of this string slice. ``` -------------------------------- ### Example Usage of Roster Import Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/import/fn.resolve.html Demonstrates importing a roster using Listforge format and the embedded dataset. ```rust use wh40kdc::Dataset; use wh40kdc::import::{import_roster, decode_listforge, RosterFormat}; let payload = decode_listforge(r#"{ "name": "Demo", "roster": { "name": "Demo", "forces": [] } }"#).unwrap(); let roster = import_roster(&payload, Dataset::embedded()).unwrap(); assert_eq!(roster.source.format, RosterFormat::Listforge); ``` -------------------------------- ### Check slice prefix with starts_with Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Determines if a slice starts with a given prefix. ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` -------------------------------- ### Partitioning a slice Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Examples demonstrating the use of partition_point to find the index where a predicate changes from true to false. ```rust assert_eq!(i, 4); assert!(v[..i].iter().all(|&x| x < 5)); assert!(v[i..].iter().all(|&x| !(x < 5))); ``` ```rust let a = [2, 4, 8]; assert_eq!(a.partition_point(|x| x < &100), a.len()); let a: [i32; 0] = []; assert_eq!(a.partition_point(|x| x < &100), 0); ``` ```rust let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; let num = 42; let idx = s.partition_point(|&x| x <= num); s.insert(idx, num); assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]); ``` -------------------------------- ### Retrieve match indices in strings Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.RiskRewardEffectRiskTest.html Use match_indices or rmatch_indices to get both the start index and the matched content. ```rust let v: Vec<_> = "abcXXXabcYYYabc".match_indices("abc").collect(); assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); let v: Vec<_> = "1abcabc2".match_indices("abc").collect(); assert_eq!(v, [(1, "abc"), (4, "abc")]); let v: Vec<_> = "ababa".match_indices("aba").collect(); assert_eq!(v, [(0, "aba")]); // only the first `aba` ``` ```rust let v: Vec<_> = "abcXXXabcYYYabc".rmatch_indices("abc").collect(); assert_eq!(v, [(12, "abc"), (6, "abc"), (0, "abc")]); let v: Vec<_> = "1abcabc2".rmatch_indices("abc").collect(); assert_eq!(v, [(4, "abc"), (1, "abc")]); let v: Vec<_> = "ababa".rmatch_indices("aba").collect(); assert_eq!(v, [(2, "aba")]); // only the last `aba` ``` -------------------------------- ### Check if string starts with a pattern Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Returns true if the pattern matches the prefix of the string. ```rust let bananas = "bananas"; assert!(bananas.starts_with("bana")); assert!(!bananas.starts_with("nana")); ``` ```rust let bananas = "bananas"; // Note that both of these assert successfully. assert!(bananas.starts_with(&['b', 'a', 'n', 'a'])); assert!(bananas.starts_with(&['a', 'b', 'c', 'd'])); ``` -------------------------------- ### Check prefix and suffix Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.DeploymentPatternSource.html Verifies if a string slice starts or ends with a given pattern. ```rust let bananas = "bananas"; assert!(bananas.starts_with("bana")); assert!(!bananas.starts_with("nana")); ``` ```rust let bananas = "bananas"; // Note that both of these assert successfully. assert!(bananas.starts_with(&['b', 'a', 'n', 'a'])); assert!(bananas.starts_with(&['a', 'b', 'c', 'd'])); ``` ```rust let bananas = "bananas"; assert!(bananas.ends_with("anas")); assert!(!bananas.ends_with("nana")); ``` -------------------------------- ### pub fn starts_with

(&self, pat: P) -> bool Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.MissionName.html Checks 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. Returns `false` if it does not. ``` -------------------------------- ### Check Vector Length Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Example of checking the length of a vector. ```rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Extract Vector Slice Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Example of extracting a slice from a vector. ```rust use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap(); ``` -------------------------------- ### Get slice length Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Returns the number of elements in the slice. ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### pub fn repeat(&self, n: usize) -> String Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.DetachmentName.html Creates a new String by repeating the original string n times. ```APIDOC ## pub fn repeat(&self, n: usize) -> String ### Description Creates a new String by repeating a string n times. ### Parameters - **n** (usize) - The number of times to repeat the string. ### Panics - Panics if the resulting capacity would overflow. ``` -------------------------------- ### Trim start of a string Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Removes leading whitespace from a string slice. ```rust let s = " עברית "; assert!(Some('ע') == s.trim_start().chars().next()); ``` -------------------------------- ### Execute damage projection with crunch Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/cruncher/index.html Demonstrates initializing a dataset, defining an engine input with attacker and target profiles, and executing the crunch function to calculate damage stages. ```rust use wh40kdc::{Dataset, Phase}; use wh40kdc::cruncher::{ crunch, AttackProfileRef, EngineContext, EngineInput, TargetProfileRef, }; let ds = Dataset::embedded(); let weapon = ds.find_weapon("bolt-rifle").expect("bolt-rifle is bundled"); let target = ds.find_unit("intercessor-squad").expect("intercessor-squad is bundled"); let input = EngineInput { attacker: AttackProfileRef { weapon, profile_index: 0 }, target: TargetProfileRef { unit: target, profile_index: 0, model_count: None }, models_firing: 5, buffs: Vec::new(), context: EngineContext { phase: Phase::Shooting, attacker_stationary: Some(false), attacker_charged: None, within_half_range: Some(false), distance_inches: None, attacker_in_cover: None, target_in_cover: None, attacker_keywords: None, target_keywords: None, timing: None, attacker_attached: None, }, }; let out = crunch(&input, None).expect("crunch succeeds"); assert_eq!(out.stages.len(), 7); ``` -------------------------------- ### Check if Vector is Empty Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Example of checking if a vector contains no elements. ```rust let mut v = Vec::new(); assert!(v.is_empty()); v.push(1); assert!(!v.is_empty()); ``` -------------------------------- ### Get string length with len Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Returns the length of the String in bytes. ```rust let a = String::from("foo"); assert_eq!(a.len(), 3); let fancy_f = String::from("ƒoo"); assert_eq!(fancy_f.len(), 4); assert_eq!(fancy_f.chars().count(), 3); ``` -------------------------------- ### Lookup and Filter Units and Abilities Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/data/struct.Dataset.html Demonstrates initializing the dataset, performing a fuzzy unit lookup, and filtering abilities by phase. ```rust use wh40kdc::{Dataset, Phase}; let ds = Dataset::embedded(); let kharn = ds.find_unit("Kharn").expect("Khârn is in the dataset"); let shooting_abilities: Vec<&str> = ds .abilities_of(kharn) .into_iter() .filter(|a| ds.phases_of(a).contains(&Phase::Shooting)) .map(|a| a.ability_id.as_str()) .collect(); assert_eq!(shooting_abilities, ["berzerker-frenzy"]); assert_eq!(ds.faction_of(kharn).unwrap().id.as_str(), "world-eaters"); ``` -------------------------------- ### Accessing Embedded Dataset and Unit Abilities Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/data/index.html Demonstrates initializing the embedded dataset and iterating through a unit's abilities and their associated phases. ```rust use wh40kdc::Dataset; let ds = Dataset::embedded(); let kharn = ds.find_unit("Kharn").unwrap(); for ability in ds.abilities_of(kharn) { let phases = ds.phases_of(ability); println!("{} acts in {:?}", ability.ability_id.as_str(), phases); } ``` -------------------------------- ### Find matches with indices Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Returns an iterator over disjoint matches and their starting indices. ```rust let v: Vec<_> = "abcXXXabcYYYabc".match_indices("abc").collect(); assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); let v: Vec<_> = "1abcabc2".match_indices("abc").collect(); assert_eq!(v, [(1, "abc"), (4, "abc")]); let v: Vec<_> = "ababa".match_indices("aba").collect(); assert_eq!(v, [(0, "aba")]); // only the first `aba` ``` -------------------------------- ### pub fn windows(&self, size: usize) -> Windows<'_, T> Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.PhaseList.html Returns an iterator over all contiguous windows of length size. ```APIDOC ## pub fn windows(&self, size: usize) -> Windows<'_, T> ### Description Returns an iterator over all contiguous windows of length `size`. The windows overlap. If the slice is shorter than `size`, the iterator returns no values. ### Panics Panics if `size` is zero. ``` -------------------------------- ### Initialize a new PlayerGame Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/scoring/fn.empty_player_game.html Creates a fresh player game instance using the specified scoring approach. ```rust pub fn empty_player_game(approach: ScoringMode) -> PlayerGame ``` -------------------------------- ### DeploymentPatternZonesItemName Definition and Schema Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.DeploymentPatternZonesItemName.html The struct definition and its corresponding JSON schema constraints. ```rust pub struct DeploymentPatternZonesItemName(/* private fields */); ``` ```json { "type": "string", "maxLength": 128, "minLength": 1 } ``` -------------------------------- ### Get last element Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Returns the last element of the slice, or None if it is empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); ``` -------------------------------- ### pub fn describe_ability(a: &Ability) -> String Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/translate/fn.describe_ability.html Generates a full text description for an ability. ```APIDOC ## describe_ability ### Description Generates a full text description for an ability. This function mirrors the `describeAbility` functionality. ### Signature `pub fn describe_ability(a: &Ability) -> String` ### Parameters - **a** (&Ability) - Required - A reference to the Ability object to describe. ### Returns - **String** - The generated text description of the ability. ``` -------------------------------- ### Get first element Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Returns the first element of the slice, or None if it is empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); ``` -------------------------------- ### Get string capacity with capacity Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Returns the String's capacity in bytes. ```rust let s = String::with_capacity(10); assert!(s.capacity() >= 10); ``` -------------------------------- ### pub fn trim_start_matches

(&self, pat: P) -> &str Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.DetachmentName.html Returns a string slice with all prefixes that match a pattern repeatedly removed. ```APIDOC ## pub fn trim_start_matches

(&self, pat: P) -> &str ### Description Returns a string slice with all prefixes that match a pattern repeatedly removed. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches. ``` -------------------------------- ### chunks_exact_mut Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.KeywordList.html Returns an iterator over mutable chunk_size elements of the slice at a time, starting at the beginning. ```APIDOC ## pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are mutable slices and do not overlap. ### Parameters - **chunk_size** (usize) - Required - The size of each chunk. ### Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### Demonstrate split_inclusive behavior Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.LeaderAttachmentEligibleBodyguardKeywordsItem.html Shows how split_inclusive retains the matched pattern as the terminator of each substring. ```rust assert_eq!(d, &["a", "b", "c"]); ``` ```rust let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb." .split_inclusive('\n').collect(); assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb."]); ``` ```rust let v: Vec<&str> = "Mary had a little lamb\nlittle lamb\nlittle lamb.\n" .split_inclusive('\n').collect(); assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb.\n"]); ``` -------------------------------- ### DeploymentPatternName Definition and Schema Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.DeploymentPatternName.html The struct definition and its corresponding JSON schema validation rules. ```rust pub struct DeploymentPatternName(/* private fields */); ``` ```json { "type": "string", "maxLength": 128, "minLength": 1 } ``` -------------------------------- ### Get byte slice with as_bytes Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Returns a byte slice of the String's contents. ```rust let s = String::from("hello"); assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes()); ``` -------------------------------- ### trim_start(&self) -> &str Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.DeploymentPatternName.html Returns a string slice with leading whitespace removed. ```APIDOC ## pub fn trim_start(&self) -> &str ### Description Returns a string slice with leading whitespace removed. Whitespace is defined according to the Unicode Derived Core Property White_Space. ``` -------------------------------- ### Check character boundaries Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Verifies if an index corresponds to the start of a UTF-8 code point sequence. ```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)); ``` -------------------------------- ### Swapping Elements in a Slice Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Provides examples for both safe and unchecked element swapping within a slice. ```rust let mut v = ["a", "b", "c", "d", "e"]; v.swap(2, 4); assert!(v == ["a", "b", "e", "d", "c"]); ``` ```rust #![feature(slice_swap_unchecked)] let mut v = ["a", "b", "c", "d"]; // SAFETY: we know that 1 and 3 are both indices of the slice unsafe { v.swap_unchecked(1, 3) }; assert!(v == ["a", "d", "c", "b"]); ``` -------------------------------- ### Identify ranges of matching items using partition_point Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Shows how to find the range of indices for matching elements and handle cases where an item is not found. ```rust let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; let low = s.partition_point(|x| x < &1); assert_eq!(low, 1); let high = s.partition_point(|x| x <= &1); assert_eq!(high, 5); let r = s.binary_search(&1); assert!((low..high).contains(&r.unwrap())); assert!(s[..low].iter().all(|&x| x < 1)); assert!(s[low..high].iter().all(|&x| x == 1)); assert!(s[high..].iter().all(|&x| x > 1)); // For something not found, the "range" of equal items is empty assert_eq!(s.partition_point(|x| x < &11), 9); assert_eq!(s.partition_point(|x| x <= &11), 9); assert_eq!(s.binary_search(&11), Err(9)); ``` -------------------------------- ### Into Trait Implementation Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.UnitCompositionModelsItemName.html Conversion implementation based on the From trait. ```rust impl Into for T where U: From, ``` ```rust fn into(self) -> U ``` -------------------------------- ### Access Raw Vector Pointer Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Examples of using raw pointers to access vector data. ```rust let x = vec![1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(*x_ptr.add(i), 1 << i); } } ``` ```rust unsafe { let mut v = vec![0, 1, 2]; let ptr1 = v.as_ptr(); let _ = ptr1.read(); let ptr2 = v.as_mut_ptr().offset(2); ptr2.write(2); // Notably, the write to `ptr2` did *not* invalidate `ptr1` // because it mutated a different element: let _ = ptr1.read(); } ``` -------------------------------- ### Get raw pointer Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.AlliedRuleName.html Converts a string slice to a raw pointer pointing to the first byte. ```rust let s = "Hello"; let ptr = s.as_ptr(); ``` -------------------------------- ### import_listforge Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/import/index.html Imports a ListForge army-list export into a resolved 40kdc Roster. ```APIDOC ## import_listforge ### Description Imports a ListForge army-list export into a resolved 40kdc Roster. ``` -------------------------------- ### pub fn iter(&self) -> Iter<'_, T> Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.PhaseList.html Returns an iterator over the slice, yielding all items from start to end. ```APIDOC ## pub fn iter(&self) -> Iter<'_, T> ### Description Returns an iterator over the slice. The iterator yields all items from start to end. ``` -------------------------------- ### wh40kdc::translate::describe_applies_to Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/translate/fn.describe_applies_to.html Generates a human-readable string describing the target units for an ability. ```APIDOC ## Function: describe_applies_to ### Signature `pub fn describe_applies_to(filter: Option<&AbilityAppliesTo>) -> String` ### Description Returns a string description of the units an ability applies to (e.g., "Applies to: units with Possessed."). This function mirrors the behavior of `describeAppliesTo`. ### Parameters - **filter** (Option<&AbilityAppliesTo>) - Optional - The filter criteria defining which units the ability applies to. ### Returns - **String** - A descriptive string indicating the target units. ``` -------------------------------- ### Split slice from the end with rsplitn Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Splits a slice into at most n subslices starting from the end based on a predicate. ```rust let v = [10, 40, 30, 20, 60, 50]; for group in v.rsplitn(2, |num| *num % 3 == 0) { println!("{group:?}"); } ``` -------------------------------- ### Using Pointer Ranges for Slices Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Shows how to obtain a range of pointers spanning a slice and verify if a specific pointer falls within that range. ```rust let a = [1, 2, 3]; let x = &a[1] as *const _; let y = &5 as *const _; assert!(a.as_ptr_range().contains(&x)); assert!(!a.as_ptr_range().contains(&y)); ``` -------------------------------- ### Create sliding windows from a slice Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Demonstrates creating overlapping windows of a specific size from a slice. ```rust let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.windows(3); assert_eq!(iter.next().unwrap(), &['l', 'o', 'r']); assert_eq!(iter.next().unwrap(), &['o', 'r', 'e']); assert_eq!(iter.next().unwrap(), &['r', 'e', 'm']); assert!(iter.next().is_none()); ``` ```rust let slice = ['f', 'o', 'o']; let mut iter = slice.windows(4); assert!(iter.next().is_none()); ``` ```rust use std::cell::Cell; let mut array = ['R', 'u', 's', 't', ' ', '2', '0', '1', '5']; let slice = &mut array[..]; let slice_of_cells: &[Cell] = Cell::from_mut(slice).as_slice_of_cells(); for w in slice_of_cells.windows(3) { Cell::swap(&w[0], &w[2]); } assert_eq!(array, ['s', 't', ' ', '2', '0', '1', '5', 'u', 'R']); ``` -------------------------------- ### Reverse split slice by predicate Source: https://docs.rs/wh40kdc/1.2.0/wh40kdc/struct.GameModes.html Splits a slice into subslices starting from the end, excluding the matched elements. ```rust let slice = [11, 22, 33, 0, 44, 55]; let mut iter = slice.rsplit(|num| *num == 0); assert_eq!(iter.next().unwrap(), &[44, 55]); assert_eq!(iter.next().unwrap(), &[11, 22, 33]); assert_eq!(iter.next(), None); ``` ```rust let v = &[0, 1, 1, 2, 3, 5, 8]; let mut it = v.rsplit(|n| *n % 2 == 0); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next().unwrap(), &[3, 5]); assert_eq!(it.next().unwrap(), &[1, 1]); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next(), None); ```