Skip to main content

StrOrDoc

Enum StrOrDoc 

Source
pub enum StrOrDoc<'p> {
    S(Cow<'p, str>),
    D(DocPtr<'p>),
}
Expand description

A tagged union of either a Cow string, or a DocPtr. By using this type in conjuction with the Doclike trait, we get a pretty large amount of code reuse while cutting down on syntax noise since in many cases we can treat string slices, owned strings, and DocPtr items in the exact same way with the only overhead being that of dealing with the enum (IE there are no extra allocations or clones).

Variants§

§

S(Cow<'p, str>)

§

D(DocPtr<'p>)

Trait Implementations§

Source§

impl<'p> Clone for StrOrDoc<'p>

Source§

fn clone(&self) -> StrOrDoc<'p>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'p> Debug for StrOrDoc<'p>

Source§

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

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

impl<'p, P: HasPrinter<'p>> Doclike<'p, P> for StrOrDoc<'p>

StrOrDoc is doclike; in the case of a doc, you just get the doc back. In the case of a Cow string, we allocate defer to the implementation that’s generic over any A such that A can become a Cow string

Source§

fn alloc(self, pr: &mut P) -> DocPtr<'p>

Generic over any Doclike, so you can use this for text as well.
Source§

fn concat(self, other: impl Doclike<'p, P>, pr: &mut P) -> DocPtr<'p>

Source§

fn nest(self, amt: u32, pr: &mut P) -> DocPtr<'p>

Source§

fn nest_line( self, other: impl Doclike<'p, P>, amt: u32, pr: &mut P, ) -> DocPtr<'p>

Source§

fn nest_doc( self, other: impl Doclike<'p, P>, amt: u32, pr: &mut P, ) -> DocPtr<'p>

Source§

fn nest_doc_zero( self, other: impl Doclike<'p, P>, amt: u32, pr: &mut P, ) -> DocPtr<'p>

Source§

fn group(self, pr: &mut P) -> DocPtr<'p>

Source§

impl<'p, A> From<A> for StrOrDoc<'p>
where Cow<'p, str>: From<A>,

Can create a StrOrDoc from anything that can become a Cow string (so a CowStr, a string slice, or an owned string)

Source§

fn from(a: A) -> StrOrDoc<'p>

Converts to this type from the input type.
Source§

impl<'p> From<DocPtr<'p>> for StrOrDoc<'p>

Can create a StrOrDoc from a DocPtr

Source§

fn from(d: DocPtr<'p>) -> StrOrDoc<'p>

Converts to this type from the input type.
Source§

impl<'p> Hash for StrOrDoc<'p>

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<'p> PartialEq for StrOrDoc<'p>

Source§

fn eq(&self, other: &StrOrDoc<'p>) -> 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<'p> Eq for StrOrDoc<'p>

Source§

impl<'p> StructuralPartialEq for StrOrDoc<'p>

Auto Trait Implementations§

§

impl<'p> Freeze for StrOrDoc<'p>

§

impl<'p> RefUnwindSafe for StrOrDoc<'p>

§

impl<'p> Send for StrOrDoc<'p>

§

impl<'p> Sync for StrOrDoc<'p>

§

impl<'p> Unpin for StrOrDoc<'p>

§

impl<'p> UnsafeUnpin for StrOrDoc<'p>

§

impl<'p> UnwindSafe for StrOrDoc<'p>

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<'p, A> Bracketable<'p> for A
where StrOrDoc<'p>: From<A>,

Source§

fn bracket(self, prio: u16) -> Brackets<'p>

Source§

fn bracket_never(self) -> Brackets<'p>

Source§

fn bracket_always(self) -> Brackets<'p>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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.