pub struct Item { /* private fields */ }Expand description
The reference to an ItemBuf.
Implementations§
source§impl Item
impl Item
sourcepub const fn new() -> &'static Self
pub const fn new() -> &'static Self
sourcepub fn as_crate(&self) -> Option<&str>
pub fn as_crate(&self) -> Option<&str>
Get the crate corresponding to the item.
Examples
use rune::compile::ItemBuf;
let item = ItemBuf::with_crate("std")?;
assert_eq!(item.as_crate(), Some("std"));
let item = ItemBuf::with_item(["local"])?;
assert_eq!(item.as_crate(), None);sourcepub fn first(&self) -> Option<ComponentRef<'_>>
pub fn first(&self) -> Option<ComponentRef<'_>>
Access the first component of this item.
Examples
use rune::compile::{ComponentRef, ItemBuf};
let item = ItemBuf::with_item(["foo", "bar"])?;
assert_eq!(item.first(), Some(ComponentRef::Str("foo")));sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the item is empty.
Examples
use rune::compile::ItemBuf;
let item = ItemBuf::new();
assert!(item.is_empty());
let item = ItemBuf::with_crate("std")?;
assert!(!item.is_empty());sourcepub fn as_local(&self) -> Option<&str>
pub fn as_local(&self) -> Option<&str>
If the item only contains one element, return that element.
sourcepub fn join<I>(&self, other: I) -> Result<ItemBuf>
pub fn join<I>(&self, other: I) -> Result<ItemBuf>
Return an owned and joined variant of this item.
Examples
use rune::compile::{Item, ComponentRef};
let item = Item::new();
assert!(item.is_empty());
let item2 = item.join(["hello", "world"])?;
assert_eq!(item2.first(), Some(ComponentRef::Str("hello")));
assert_eq!(item2.last(), Some(ComponentRef::Str("world")));sourcepub fn extended<C>(&self, part: C) -> Result<ItemBuf>where
C: IntoComponent,
pub fn extended<C>(&self, part: C) -> Result<ItemBuf>where
C: IntoComponent,
Return an owned and extended variant of this item.
Examples
use rune::compile::{Item, ComponentRef};
let item = Item::new();
assert!(item.is_empty());
let item2 = item.extended("hello")?;
assert_eq!(item2.first(), Some(ComponentRef::Str("hello")));sourcepub fn last(&self) -> Option<ComponentRef<'_>>
pub fn last(&self) -> Option<ComponentRef<'_>>
Access the last component in the path.
sourcepub fn iter(&self) -> Iter<'_>
pub fn iter(&self) -> Iter<'_>
An iterator over the Components that constitute this item.
Examples
use rune::compile::{ComponentRef, IntoComponent, ItemBuf};
let mut item = ItemBuf::new();
item.push("start")?;
item.push(ComponentRef::Id(1))?;
item.push(ComponentRef::Id(2))?;
item.push("middle")?;
item.push(ComponentRef::Id(3))?;
item.push("end")?;
let mut it = item.iter();
assert_eq!(it.next(), Some("start".as_component_ref()));
assert_eq!(it.next(), Some(ComponentRef::Id(1)));
assert_eq!(it.next(), Some(ComponentRef::Id(2)));
assert_eq!(it.next(), Some("middle".as_component_ref()));
assert_eq!(it.next(), Some(ComponentRef::Id(3)));
assert_eq!(it.next(), Some("end".as_component_ref()));
assert_eq!(it.next(), None);
assert!(!item.is_empty());sourcepub fn starts_with<U>(&self, other: U) -> bool
pub fn starts_with<U>(&self, other: U) -> bool
Test if current item starts with another.
sourcepub fn is_super_of<U>(&self, other: U, n: usize) -> bool
pub fn is_super_of<U>(&self, other: U, n: usize) -> bool
Test if current is immediate super of other.
Examples
use rune::compile::{Item, ItemBuf};
assert!(Item::new().is_super_of(Item::new(), 1));
assert!(!ItemBuf::with_item(["a"])?.is_super_of(Item::new(), 1));
assert!(!ItemBuf::with_item(["a", "b"])?.is_super_of(ItemBuf::with_item(["a"])?, 1));
assert!(ItemBuf::with_item(["a", "b"])?.is_super_of(ItemBuf::with_item(["a", "b"])?, 1));
assert!(!ItemBuf::with_item(["a"])?.is_super_of(ItemBuf::with_item(["a", "b", "c"])?, 1));sourcepub fn ancestry<U>(&self, other: U) -> Result<(ItemBuf, ItemBuf)>
pub fn ancestry<U>(&self, other: U) -> Result<(ItemBuf, ItemBuf)>
Get the ancestry of one module to another.
This returns three things:
- The shared prefix between the current and the
otherpath. - The suffix to get to the
otherpath from the shared prefix.
Examples
use rune::compile::{Item, ItemBuf};
assert_eq!(
(ItemBuf::new(), ItemBuf::new()),
Item::new().ancestry(Item::new())?
);
assert_eq!(
(ItemBuf::new(), ItemBuf::with_item(["a"])?),
Item::new().ancestry(ItemBuf::with_item(["a"])?)?
);
assert_eq!(
(ItemBuf::new(), ItemBuf::with_item(["a", "b"])?),
Item::new().ancestry(ItemBuf::with_item(["a", "b"])?)?
);
assert_eq!(
(ItemBuf::with_item(["a"])?, ItemBuf::with_item(["b"])?),
ItemBuf::with_item(["a", "c"])?.ancestry(ItemBuf::with_item(["a", "b"])?)?
);
assert_eq!(
(ItemBuf::with_item(["a", "b"])?, ItemBuf::with_item(["d", "e"])?),
ItemBuf::with_item(["a", "b", "c"])?.ancestry(ItemBuf::with_item(["a", "b", "d", "e"])?)?
);Trait Implementations§
source§impl Display for Item
impl Display for Item
Format implementation for an ItemBuf.
An empty item is formatted as {root}, because it refers to the topmost
root module.
Examples
use rune::compile::{ComponentRef, ItemBuf};
use rune::alloc::prelude::*;
let root = ItemBuf::new().try_to_string()?;
assert_eq!("{root}", root);
let hello = ItemBuf::with_item(&[ComponentRef::Str("hello"), ComponentRef::Id(0)])?;
assert_eq!("hello::$0", hello.try_to_string()?);source§impl<'a> IntoIterator for &'a Item
impl<'a> IntoIterator for &'a Item
source§impl<A: Allocator> PartialEq<&Item> for ItemBuf<A>
impl<A: Allocator> PartialEq<&Item> for ItemBuf<A>
source§impl<A: Allocator> PartialEq<Item> for &ItemBuf<A>
impl<A: Allocator> PartialEq<Item> for &ItemBuf<A>
source§impl<A: Allocator> PartialEq<Item> for ItemBuf<A>
impl<A: Allocator> PartialEq<Item> for ItemBuf<A>
source§impl PartialEq<ItemBuf> for &Item
impl PartialEq<ItemBuf> for &Item
source§impl PartialEq<ItemBuf> for Item
impl PartialEq<ItemBuf> for Item
source§impl PartialEq for Item
impl PartialEq for Item
source§impl PartialOrd for Item
impl PartialOrd for Item
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read more