Struct Tag

Source
pub struct Tag {
    pub namespace: Option<String>,
    pub name: String,
    pub values: Vec<Value>,
    pub attrs: Vec<Attribute>,
    pub tags: Vec<Tag>,
}
Expand description

A series of values and attributes, with a name (and namespace), and optionally a subtree of tags.

All data in SDLang is stored through these.

Fields§

§namespace: Option<String>

The namespace (if any) of the tag.

§name: String

The name of the tag. "" if none was given.

§values: Vec<Value>

A list of values.

§attrs: Vec<Attribute>

A list of attributes.

§tags: Vec<Tag>

A list of subtags (empty vector if none exist).

Implementations§

Source§

impl Tag

Source

pub fn new(name: String) -> Self

Creates a new tag.

Note that no allocation is performed. Everything is initialised to a default empty state.

Source

pub fn namespace(self, namespace: String) -> Self

Sets the namespace.

Source

pub fn values(self, values: Vec<Value>) -> Self

Sets the value list.

Source

pub fn attrs(self, attrs: Vec<Attribute>) -> Self

Sets the attribute list from a list of Attributes.

Source

pub fn tags(self, tags: Vec<Tag>) -> Self

Sets the child tags.

Source

pub fn attr<'a, 'b>(&'a self, name: &'b str) -> Option<&'a Attribute>

Finds the given attribute by name.

Source

pub fn attr_mut<'a, 'b>( &'a mut self, name: &'b str, ) -> Option<&'a mut Attribute>

Finds the given attribute by name, returning a mutable reference.

Source

pub fn tag<'a, 'b>(&'a self, name: &'b str) -> Option<&'a Tag>

Finds the given subtag by name.

Source

pub fn tag_mut<'a, 'b>(&'a mut self, name: &'b str) -> Option<&'a mut Tag>

Finds the given tag by name, returning a mutable reference.

Trait Implementations§

Source§

impl Debug for Tag

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Tag

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Returns a human-readable representation of the tag. The format is roughly this:

tag "<namespace>:<name>": <values>, <attributes>
* <subtag_1>
  * <subtag_1_subtag>
  * ...
* <subtag_2>
* ...
Source§

impl FromStr for Tag

Source§

fn from_str(s: &str) -> Result<Self>

Parses the text for a Tag, returning a parse error on failure.

Source§

type Err = Error<Rule>

The associated error which can be returned from parsing.
Source§

impl PartialEq for Tag

Source§

fn eq(&self, other: &Tag) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Tag

Auto Trait Implementations§

§

impl Freeze for Tag

§

impl RefUnwindSafe for Tag

§

impl Send for Tag

§

impl Sync for Tag

§

impl Unpin for Tag

§

impl UnwindSafe for Tag

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.