Struct runestick::Item [−][src]
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
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]
I: IntoIterator,
I::Item: IntoComponent,
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]
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);
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]
C: IntoComponent,
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]
I: IntoIterator,
I::Item: IntoComponent,
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]
I: IntoIterator,
I::Item: IntoComponent,
Join this path with another.
pub fn extended<C>(&self, part: C) -> Self where
C: IntoComponent,
[src]
C: IntoComponent,
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]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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.
fn into_iter(self) -> Self::IntoIter
[src]
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.
fn into_iter(self) -> Self::IntoIter
[src]
impl Ord for Item
[src]
fn cmp(&self, other: &Item) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Item> for Item
[src]
impl PartialOrd<Item> for Item
[src]
fn partial_cmp(&self, other: &Item) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for Item
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CallHasher for T where
T: Hash,
T: Hash,
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,