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§
Trait Implementations§
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
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>
fn alloc(self, pr: &mut P) -> DocPtr<'p>
Generic over any Doclike, so you can use this for text as well.
fn concat(self, other: impl Doclike<'p, P>, pr: &mut P) -> DocPtr<'p>
fn nest(self, amt: u32, pr: &mut P) -> DocPtr<'p>
fn nest_line( self, other: impl Doclike<'p, P>, amt: u32, pr: &mut P, ) -> DocPtr<'p>
fn nest_doc( self, other: impl Doclike<'p, P>, amt: u32, pr: &mut P, ) -> DocPtr<'p>
fn nest_doc_zero( self, other: impl Doclike<'p, P>, amt: u32, pr: &mut P, ) -> DocPtr<'p>
fn group(self, pr: &mut P) -> DocPtr<'p>
Source§impl<'p, A> From<A> for StrOrDoc<'p>
Can create a StrOrDoc from anything that can become a Cow string
(so a CowStr, a string slice, or an owned string)
impl<'p, A> From<A> for StrOrDoc<'p>
Can create a StrOrDoc from anything that can become a Cow string
(so a CowStr, a string slice, or an owned string)
impl<'p> Eq for StrOrDoc<'p>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<'p, A> Bracketable<'p> for A
impl<'p, A> Bracketable<'p> for A
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.