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 the data 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 an empty item.

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);

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.

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());

Clear the current item.

Construct a new vector from the current item.

Convert into a vector from the current item.

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.

Implement an iterator.

Test if current item starts with another.

Test if current is immediate super of other.

Get the ancestry of one module to another.

This returns three things:

  • The shared prefix between the current and the other path.
  • The suffix to get to the other path from the shared prefix.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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());

Formats the value using the given formatter. Read more

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.