### Rust WikiLink Struct and Example
Source: https://docs.rs/parsoid/latest/parsoid/node/struct
Defines the `WikiLink` struct for representing internal wiki links (e.g., `[[Foo|bar]]`). Includes an example demonstrating its creation and usage, showing how to extract raw target, display text, and the rendered HTML.
```Rust
pub struct WikiLink(/* private fields */);
// Example usage:
let text = Wikicode::new_text("baz");
let link = WikiLink::new("Foo bar", &text);
assert_eq!(
link.raw_target(),
"./Foo_bar".to_string()
);
assert_eq!(
link.target(),
"Foo bar".to_string()
);
assert_eq!(
link.text_contents(), "baz".to_string()
);
assert_eq!(
link.to_string(),
"baz".to_string()
);
```
--------------------------------
### IndexMap Struct Definition and Usage Example (Rust)
Source: https://docs.rs/parsoid/latest/parsoid/map/struct
Defines the IndexMap struct, a hash map that preserves insertion order and offers indexed access. Includes an example demonstrating its use for counting character frequencies in a string.
```Rust
pub struct IndexMap { /* private fields */ }
use indexmap::IndexMap;
// count the frequency of each letter in a sentence.
let mut letters = IndexMap::new();
for ch in "a short treatise on fungi".chars() {
*letters.entry(ch).or_insert(0) += 1;
}
assert_eq!(letters[&'s'], 2);
assert_eq!(letters[&'t'], 3);
assert_eq!(letters[&'u'], 1);
assert_eq!(letters.get(&'y'), None);
```
--------------------------------
### IndexMap Get Methods
Source: https://docs.rs/parsoid/latest/parsoid/map/struct
Provides methods to retrieve values from the IndexMap based on a key.
```APIDOC
## GET /indexmap/get
### Description
Retrieves a reference to the value associated with a given key.
### Method
GET
### Endpoint
`/indexmap/get`
### Parameters
#### Query Parameters
- **key** (Q) - Required - The key to look up.
### Response
#### Success Response (200)
- **value** (V) - The value associated with the key, if found.
#### Response Example
```json
{
"value": "example_value"
}
```
```
```APIDOC
## GET /indexmap/get_key_value
### Description
Retrieves references to both the key and the value for a given key.
### Method
GET
### Endpoint
`/indexmap/get_key_value`
### Parameters
#### Query Parameters
- **key** (Q) - Required - The key to look up.
### Response
#### Success Response (200)
- **key** (K) - The key found.
- **value** (V) - The value associated with the key.
#### Response Example
```json
{
"key": "example_key",
"value": "example_value"
}
```
```
```APIDOC
## GET /indexmap/get_full
### Description
Retrieves the index, key, and value for a given key.
### Method
GET
### Endpoint
`/indexmap/get_full`
### Parameters
#### Query Parameters
- **key** (Q) - Required - The key to look up.
### Response
#### Success Response (200)
- **index** (usize) - The index of the key-value pair.
- **key** (K) - The key found.
- **value** (V) - The value associated with the key.
#### Response Example
```json
{
"index": 0,
"key": "example_key",
"value": "example_value"
}
```
```
```APIDOC
## GET /indexmap/get_index_of
### Description
Retrieves the index of a key if it exists in the map.
### Method
GET
### Endpoint
`/indexmap/get_index_of`
### Parameters
#### Query Parameters
- **key** (Q) - Required - The key to look up.
### Response
#### Success Response (200)
- **index** (usize) - The index of the key, if found.
#### Response Example
```json
{
"index": 0
}
```
```
```APIDOC
## GET /indexmap/get_mut
### Description
Retrieves a mutable reference to the value associated with a given key.
### Method
GET
### Endpoint
`/indexmap/get_mut`
### Parameters
#### Query Parameters
- **key** (Q) - Required - The key to look up.
### Response
#### Success Response (200)
- **value** (&mut V) - A mutable reference to the value, if found.
#### Response Example
```json
{
"value": "&mut example_value"
}
```
```
```APIDOC
## GET /indexmap/get_full_mut
### Description
Retrieves mutable references to the index, key, and value for a given key.
### Method
GET
### Endpoint
`/indexmap/get_full_mut`
### Parameters
#### Query Parameters
- **key** (Q) - Required - The key to look up.
### Response
#### Success Response (200)
- **index** (usize) - The index of the key-value pair.
- **key** (&K) - A reference to the key.
- **value** (&mut V) - A mutable reference to the value.
#### Response Example
```json
{
"index": 0,
"key": "&example_key",
"value": "&mut example_value"
}
```
```
```APIDOC
## POST /indexmap/get_disjoint_mut
### Description
Retrieves mutable references to the values for multiple keys. Panics if any key is duplicated.
### Method
POST
### Endpoint
`/indexmap/get_disjoint_mut`
### Parameters
#### Request Body
- **keys** ([&Q; N]) - Required - An array of keys to look up.
### Response
#### Success Response (200)
- **values** ([Option<&mut V>; N]) - An array of mutable references to the values, if found.
#### Response Example
```json
{
"values": ["&mut example_value1", "&mut example_value2"]
}
```
```
--------------------------------
### Import Parsoid Prelude in Rust
Source: https://docs.rs/parsoid/latest/parsoid/prelude/index
Imports essential traits and types from the parsoid crate's prelude for general use. This is a common starting point for interacting with the parsoid library in Rust projects.
```rust
use parsoid::prelude::*;
```
--------------------------------
### Rust WikinodeIterator: Filtering Categories
Source: https://docs.rs/parsoid/latest/parsoid/trait
Filters and returns a vector of all category links found within the current Wikinode. These are typically formatted as `[[Category:Example]]`.
```rust
fn filter_categories(&self) -> Vec { ... }
```
--------------------------------
### Get First Key-Value Pair (Rust)
Source: https://docs.rs/parsoid/latest/parsoid/map/struct
Retrieves the first key-value pair from the map. This operation is efficient, taking O(1) time.
```rust
pub fn first(&self) -> Option<(&K, &V)>
```
--------------------------------
### IndexMap Key Access (Immutable - Panic Example)
Source: https://docs.rs/parsoid/latest/parsoid/map/struct
Illustrates a scenario where immutable key-based access to an IndexMap results in a panic. This occurs when attempting to access a key that does not exist in the map. Dependencies include the `indexmap` crate.
```Rust
use indexmap::IndexMap;
let mut map = IndexMap::new();
map.insert("foo", 1);
println!("{:?}", map["bar"]); // panics!
```
--------------------------------
### Get First Entry for In-Place Manipulation (Rust)
Source: https://docs.rs/parsoid/latest/parsoid/map/struct
Returns the first entry of the map, allowing for in-place modifications. This operation has a time complexity of O(1).
```rust
pub fn first_entry(&mut self) -> Option>
```
--------------------------------
### Rust WikinodeIterator: Filtering Comments
Source: https://docs.rs/parsoid/latest/parsoid/trait
Filters and returns a vector of all HTML comments found within the current Wikinode. Comments are typically formatted as ``.
```rust
fn filter_comments(&self) -> Vec { ... }
```
--------------------------------
### Rust: Accessing and Manipulating MediaWiki Templates
Source: https://docs.rs/parsoid/latest/parsoid/prelude/struct
Demonstrates how to extract values from an existing MediaWiki template by converting HTML to a mutable code representation. It shows how to get the template's name, raw name, wikitext name, and specific parameters. This functionality requires the `parsoid` crate and its associated client for HTML transformation.
```rust
let code = client.transform_to_html("{{1x|test}}").await?.into_mutable();
// Get the `Template` instance
let template = code.filter_templates()?[0].clone();
assert_eq!(template.name(), "Template:1x".to_string());
assert_eq!(template.raw_name(), "./Template:1x".to_string());
assert_eq!(template.name_in_wikitext(), "1x".to_string());
assert_eq!(template.param("1"), Some("test".to_string()));
```
--------------------------------
### Rust: Get All Template Parameters
Source: https://docs.rs/parsoid/latest/parsoid/prelude/struct
The `params` method returns a map containing all parameters associated with a `Template` instance, including both named and unnamed parameters. The map uses `String` keys and values, providing access to the template's arguments.
```rust
pub fn params(&self) -> IndexMap
```
--------------------------------
### Rust Get Redirect Information
Source: https://docs.rs/parsoid/latest/parsoid/struct
Retrieves redirect information if the HTML document represents a redirect. This is important for handling navigation and content resolution in web contexts.
```rust
pub fn redirect(&self) -> Option
```
--------------------------------
### Rust WikinodeIterator: Filtering External Links
Source: https://docs.rs/parsoid/latest/parsoid/trait
Filters and returns a vector of all external links found within the current Wikinode. External links are typically formatted as `[https://example.org/ Example]`.
```rust
fn filter_external_links(&self) -> Vec { ... }
```
--------------------------------
### IndexMap Key Access (Mutable - Panic Example)
Source: https://docs.rs/parsoid/latest/parsoid/map/struct
Illustrates a scenario where mutable key-based access to an IndexMap results in a panic. This occurs when attempting to assign a value to a key that does not exist in the map. Dependencies include the `indexmap` crate.
```Rust
use indexmap::IndexMap;
let mut map = IndexMap::new();
map.insert("foo", 1);
map["bar"] = 1; // panics!
```
--------------------------------
### Identity Conversion for Generic Types
Source: https://docs.rs/parsoid/latest/parsoid/cite/struct
The From for T implementation for generic types provides a simple identity conversion. The `from` function takes a value and returns it unchanged, serving as a basic example of the From trait.
```rust
### impl From for T
Source§
#### fn from(t: T) -> T
Returns the argument unchanged.
Source§
```
--------------------------------
### IndexMap Indexed Access (Immutable - Panic Example)
Source: https://docs.rs/parsoid/latest/parsoid/map/struct
Illustrates a scenario where immutable indexed access to an IndexMap results in a panic. This occurs when attempting to access an index that is outside the bounds of the map. Dependencies include the `indexmap` crate.
```Rust
use indexmap::IndexMap;
let mut map = IndexMap::new();
map.insert("foo", 1);
println!("{:?}", map[10]); // panics!
```
--------------------------------
### Rust Methods for Node Traversal Edges
Source: https://docs.rs/parsoid/latest/parsoid/node/enum
The `traverse` and `traverse_inclusive` methods provide iterators over the start and end edges of a node and its descendants. This allows for fine-grained control over iterating through the document tree, distinguishing between entering and exiting nodes. These methods are useful for advanced parsing and serialization tasks.
```rust
pub fn traverse_inclusive(&self) -> Traverse
pub fn traverse(&self) -> Traverse
```
--------------------------------
### Rust: Get Parameter Name as in Wikitext
Source: https://docs.rs/parsoid/latest/parsoid/prelude/struct
The `param_in_wikitext` method retrieves the exact name of a parameter as it appears in the wikitext, including any comments within the name. For example, given `{{1x|paramname=value}}`, looking up `paramname` would return `Some("paramname=value}}` looking up `paramname` would return `Some("param