Skip to main content

KdlString

Struct KdlString 

Source
pub struct KdlString<'a> { /* private fields */ }
Expand description

A KDL string, parsed from an identifier, escaped string, or raw string. Exists in either Owned or Borrowed form, depending on whether there were escapes in the string. Doesn’t track the origin of the string (identifier, escaped, or raw), because KDL semantics treat them all identically.

Implementations§

Source§

impl<'a> KdlString<'a>

Source

pub fn new() -> Self

Create a new, empty KDL String

Source

pub fn from_cow(cow: Cow<'a, str>) -> Self

Create a KDL string from a Cow<str>.

Source

pub fn from_borrowed(s: &'a str) -> Self

Create a borrowed KDL string

Source

pub fn from_string(s: String) -> Self

Create an owned KDL string

Source

pub fn into_string(self) -> String

Convert this unconditionally into an owned string.

Source

pub fn as_str(&self) -> &str

Get the &str contained in this string.

Source

pub fn visit_to<V, E>(self, visitor: V) -> Result<V::Value, E>
where V: Visitor<'a>, E: Error,

Apply a KDL string to a visitor

Methods from Deref<Target = Cow<'a, str>>§

1.0.0 · Source

pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned

Acquires a mutable reference to the owned form of the data.

Clones the data if it is not already owned.

§Examples
use std::borrow::Cow;

let mut cow = Cow::Borrowed("foo");
cow.to_mut().make_ascii_uppercase();

assert_eq!(
  cow,
  Cow::Owned(String::from("FOO")) as Cow<'_, str>
);

Trait Implementations§

Source§

impl AsRef<str> for KdlString<'_>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Clone for KdlString<'a>

Source§

fn clone(&self) -> KdlString<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for KdlString<'a>

Source§

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

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

impl Default for KdlString<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> Deref for KdlString<'a>

Source§

type Target = Cow<'a, str>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Cow<'a, str>

Dereferences the value.
Source§

impl DerefMut for KdlString<'_>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'de> Deserialize<'de> for KdlString<'de>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, 'b> Extend<&'b char> for KdlString<'a>

Source§

fn extend<T: IntoIterator<Item = &'b char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a> Extend<&'a str> for KdlString<'a>

Source§

fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<char> for KdlString<'_>

Source§

fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> FromIterator<T> for KdlString<'_>
where Self: Extend<T>,

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for KdlString<'_>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: AsRef<str>> PartialEq<T> for KdlString<'_>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for KdlString<'_>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'a> StringBuilder<'a> for KdlString<'a>

Source§

fn push_str(&mut self, s: &'a str)

Add a borrowed string to the back of this string
Source§

fn push_char(&mut self, c: char)

Add a char to the back of this string
Source§

fn from_str(s: &'a str) -> Self

Create a new instance from a borrowed string
Source§

fn empty() -> Self

Create a new empty instance
Source§

impl<'a> Eq for KdlString<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for KdlString<'a>

§

impl<'a> RefUnwindSafe for KdlString<'a>

§

impl<'a> Send for KdlString<'a>

§

impl<'a> Sync for KdlString<'a>

§

impl<'a> Unpin for KdlString<'a>

§

impl<'a> UnsafeUnpin for KdlString<'a>

§

impl<'a> UnwindSafe for KdlString<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<I, T> ExtractContext<I, ()> for T

Source§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<I> RecreateContext<I> for I

Source§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.