pub struct NetdocEncoder {
built: Result<String, Bug>,
}Expand description
Encoder, representing a partially-built document.
For example usage, see the tests in this module, or a descriptor building
function in tor-netdoc (such as hsdesc::build::inner::HsDescInner::build_sign).
Fields§
§built: Result<String, Bug>The being-built document, with everything accumulated so far
If an ItemEncoder exists, it will add a newline when it’s dropped.
Err means bad values passed to some builder function.
Such errors are accumulated here for the benefit of handwritten document encoders.
Implementations§
Source§impl NetdocEncoder
impl NetdocEncoder
Sourcepub fn item(&mut self, keyword: impl KeywordEncodable) -> ItemEncoder<'_>
pub fn item(&mut self, keyword: impl KeywordEncodable) -> ItemEncoder<'_>
Adds an item to the being-built document
The item can be further extended with arguments or an object,
using the returned ItemEncoder.
Sourcefn write_with(&mut self, f: impl FnOnce(&mut String) -> Result<(), Bug>)
fn write_with(&mut self, f: impl FnOnce(&mut String) -> Result<(), Bug>)
Extend the being-built document with a fallible function f
Doesn’t call f if the building has already failed,
and handles the error if f fails.
Sourcepub fn push_raw_string(&mut self, s: &dyn Display)
pub fn push_raw_string(&mut self, s: &dyn Display)
Adds raw text to the being-built document
s is added as raw text, after the newline ending the previous item.
If item is subsequently called, the start of that item
will immediately follow s.
It is the responsibility of the caller to obey the metadocument syntax.
In particular, s should end with a newline.
No checks are performed.
Incorrect use might lead to malformed documents, or later errors.
Sourcepub fn slice(&self, begin: Cursor, end: Cursor) -> Result<&str, Bug>
pub fn slice(&self, begin: Cursor, end: Cursor) -> Result<&str, Bug>
Obtain the text of a section of the document
Useful for making a signature.
Sourcepub fn text_sofar(&self) -> Result<&str, Bug>
pub fn text_sofar(&self) -> Result<&str, Bug>
Obtain the document so far in textual form
Trait Implementations§
Source§impl Clone for NetdocEncoder
impl Clone for NetdocEncoder
Source§fn clone(&self) -> NetdocEncoder
fn clone(&self) -> NetdocEncoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NetdocEncoder
impl Debug for NetdocEncoder
Auto Trait Implementations§
impl Freeze for NetdocEncoder
impl !RefUnwindSafe for NetdocEncoder
impl Send for NetdocEncoder
impl Sync for NetdocEncoder
impl Unpin for NetdocEncoder
impl UnsafeUnpin for NetdocEncoder
impl !UnwindSafe for NetdocEncoder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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