[][src]Struct rna::Namespace

pub struct Namespace {
    pub prefix: String,
    pub suffix: String,
}

Namespace consist of 'prefix' and 'suffix'. where 'prefix' is any string before : and 'suffix' is any string after that

Example Namespaces

  • minecraft:test -> prefix: minecraft, suffix: test
  • megumin:explosion -> prefix: megumin, suffix: explosion
  • boomber:hello_world -> prefix: boomber, suffix: hello_world

Examples

Creating Namespace

This method will create new namespace without any check for invalid character in namespace.

let namespace = Namespace::new("megumin", "explosion");
assert_eq!(namespace.prefix, "megumin");
assert_eq!(namespace.suffix, "explosion");

Decode Namespace

This method will create new namespace while also check of any invalid syntax in namespace and will return DecodeError if that happened.

let namespace = Namespace::decode("megumin:explosion").unwrap();
assert_eq!(namespace.prefix, "megumin");
assert_eq!(namespace.suffix, "explosion");

Fields

prefix: String

String that come before :

suffix: String

String that come after :

Methods

impl Namespace[src]

pub fn new(prefix: impl Into<String>, suffix: impl Into<String>) -> Namespace[src]

Manually create new Namespace

pub fn decode(value: impl Into<String>) -> Result<Namespace, DecodeError>[src]

Create Namespace from a given string.

Errors

This method can error when:

  • Input contain invalid characters for namespace
  • Input contain too many colons (:)
  • There's an error inside regex crate

Examples

assert_eq!(
   Namespace::decode("boomber:hello_world").unwrap(),
   Namespace::new("boomber", "hello_world")
);

If no colon is provided, 'minecraft' prefix will be used.

assert_eq!(
   Namespace::decode("without_prefix").unwrap(),
   Namespace::new("minecraft", "without_prefix")
);

Trait Implementations

impl Clone for Namespace[src]

impl Debug for Namespace[src]

impl Eq for Namespace[src]

impl<'_> From<&'_ str> for Namespace[src]

Create Namespace from &str.
This will unwrap() error emit from Namespace::decode() function.

impl Hash for Namespace[src]

impl PartialEq<Namespace> for Namespace[src]

impl StructuralEq for Namespace[src]

impl StructuralPartialEq for Namespace[src]

Auto Trait Implementations

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> 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, 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.