Struct runestick::Item[][src]

pub struct Item { /* fields omitted */ }

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

impl Item[src]

pub const fn new() -> Self[src]

Construct an empty item.

pub fn with_item<I>(iter: I) -> Self where
    I: IntoIterator,
    I::Item: IntoComponent
[src]

Construct a new item path.

pub fn with_crate(name: &str) -> Self[src]

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
[src]

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

pub fn as_crate(&self) -> Option<&str>[src]

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

pub fn first(&self) -> Option<ComponentRef<'_>>[src]

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

pub fn push<C>(&mut self, c: C) where
    C: IntoComponent
[src]

Push the given component to the current item.

pub fn pop(&mut self) -> Option<Component>[src]

Push the given component to the current item.

pub fn extend<I>(&mut self, i: I) where
    I: IntoIterator,
    I::Item: IntoComponent
[src]

Extend the current item with an iterator.

pub fn is_empty(&self) -> bool[src]

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

pub fn clear(&mut self)[src]

Clear the current item.

pub fn as_vec(&self) -> Vec<Component>[src]

Construct a new vector from the current item.

pub fn into_vec(self) -> Vec<Component>[src]

Convert into a vector from the current item.

pub fn as_local(&self) -> Option<&str>[src]

If the item only contains one element, return that element.

pub fn join<I>(&self, other: I) -> Self where
    I: IntoIterator,
    I::Item: IntoComponent
[src]

Join this path with another.

pub fn extended<C>(&self, part: C) -> Self where
    C: IntoComponent
[src]

Clone and extend the item path.

pub fn last(&self) -> Option<ComponentRef<'_>>[src]

Access the last component in the path.

pub fn iter(&self) -> Iter<'_>[src]

Implement an iterator.

pub fn starts_with(&self, other: &Self) -> bool[src]

Test if current item starts with another.

pub fn is_super_of(&self, other: &Self, n: usize) -> bool[src]

Test if current is immediate super of other.

pub fn ancestry(&self, other: &Self) -> (Self, Self)[src]

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

impl Clone for Item[src]

impl Debug for Item[src]

impl Default for Item[src]

impl<'de> Deserialize<'de> for Item[src]

impl Display for Item[src]

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

impl Eq for Item[src]

impl From<Item> for CompileItem[src]

impl Hash for Item[src]

impl<'a> IntoIterator for Item[src]

type IntoIter = IntoIter<Component>

Which kind of iterator are we turning this into?

type Item = Component

The type of the elements being iterated over.

impl<'a> IntoIterator for &'a Item[src]

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?

type Item = ComponentRef<'a>

The type of the elements being iterated over.

impl Ord for Item[src]

impl PartialEq<Item> for Item[src]

impl PartialOrd<Item> for Item[src]

impl Serialize for Item[src]

impl StructuralEq for Item[src]

impl StructuralPartialEq for Item[src]

Auto Trait Implementations

impl RefUnwindSafe for Item

impl Send for Item

impl Sync for Item

impl Unpin for Item

impl UnwindSafe for Item

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CallHasher for T where
    T: Hash

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.