Struct runestick::Item [−][src]
pub struct Item { /* fields omitted */ }
Expand description
The name of an item.
This is made up of a collection of strings, like ["foo", "bar"]
.
This is indicated in rune as foo::bar
.
Panics
The max length of a string component is is 2**15 = 32768. Attempting to add a string larger than that will panic.
Component encoding
A component is encoded as:
- A two byte tag as a u16 in native endianess, indicating its type (least significant 2 bits) and data (most significant 15 bits).
- If the type is a
STRING
, the data is treated as the length of the string. Any other type this thedata
is treated as the numeric id of the component. - If the type is a
STRING
, the tag is repeated at the end of it to allow for seeking backwards. This is not the case for other types. Since they are fixed size its not necessary.
So all in all, a string is encoded as:
dddddddd dddddddt *string content* dddddddd dddddddt
And any other component is just the two bytes:
dddddddd dddddddt
Implementations
Construct a new item path.
Construct item for a crate.
Examples
use runestick::{Item, ComponentRef}; let item = Item::with_crate("std"); assert_eq!(item.as_crate(), Some("std")); let mut it = item.iter(); assert_eq!(it.next(), Some(ComponentRef::Crate("std"))); assert_eq!(it.next(), None);
pub fn with_crate_item<I>(name: &str, iter: I) -> Self where
I: IntoIterator,
I::Item: IntoComponent,
pub fn with_crate_item<I>(name: &str, iter: I) -> Self where
I: IntoIterator,
I::Item: IntoComponent,
Create a crated item with the given name.
Examples
use runestick::{Item, ComponentRef}; let item = Item::with_crate_item("std", &["option"]); assert_eq!(item.as_crate(), Some("std")); let mut it = item.iter(); assert_eq!(it.next(), Some(ComponentRef::Crate("std"))); assert_eq!(it.next(), Some(ComponentRef::Str("option"))); assert_eq!(it.next(), None);
Get the crate corresponding to the item.
Examples
use runestick::Item; let item = Item::with_crate("std"); assert_eq!(item.as_crate(), Some("std")); let item = Item::with_item(&["local"]); assert_eq!(item.as_crate(), None);
Access the first component of this item.
Examples
use runestick::{ComponentRef, Item}; let item = Item::with_item(&["foo", "bar"]); assert_eq!(item.first(), Some(ComponentRef::Str("foo")));
Push the given component to the current item.
Extend the current item with an iterator.
Check if the item is empty.
Examples
use runestick::Item; let item = Item::new(); assert!(item.is_empty()); let item = Item::with_crate("std"); assert!(!item.is_empty());
If the item only contains one element, return that element.
Join this path with another.
Clone and extend the item path.
Access the last component in the path.
Test if current item starts with another.
Test if current is immediate super of other
.
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Format implementation for item.
An empty item is formatted as {root}
, because it refers to the topmost
root module.
Examples
use runestick::{Item, ComponentRef::*}; assert_eq!("{root}", Item::new().to_string()); assert_eq!("hello::$0", Item::with_item(&[Str("hello"), Id(0)]).to_string());
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Item
impl UnwindSafe for Item
Blanket Implementations
Mutably borrows from an owned value. Read more