pub struct Builder {
pub no_space_after_empty: bool,
/* private fields */
}Expand description
Builds and modifies a Text, based on replacements applied
to it.
This struct is meant to be used alongside the [txt!] macro, as
you can just push more Text to the Builder py pushing
another Builder, which can be returned by the [txt!] macro:
fn is_more_than_two(num: usize) -> Text {
let mut builder = Text::builder();
builder.push(txt!("The number [a]{num}[] is"));
if num > 2 {
builder.push(txt!("[a]more[] than 2."));
} else {
builder.push(txt!("[a]not more[] than 2."));
}
builder.build()
}In the above call, you can see that num was interpolated, just
like with println!, there are also Forms being applied to
the Text. Each [] pair denotes a Form. These pairs
follow the following rule:
Fields§
§no_space_after_empty: boolWether to collapse " "s after an empty element is pushed
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new() -> Self
pub fn new() -> Self
Returns a new instance of Builder
Use Text::builder if you don’t want to bring Builder
into scope.
Sourcepub fn push<D: Display, _T>(&mut self, part: impl Into<BuilderPart<D, _T>>)
pub fn push<D: Display, _T>(&mut self, part: impl Into<BuilderPart<D, _T>>)
Pushes a part of the text
This can be an impl Display type, an impl Tag, a
FormId, a PathBuf, or even std::process::Output.
Sourcepub fn last_was_empty(&self) -> bool
pub fn last_was_empty(&self) -> bool
Sourcepub fn push_str<D: Display>(&mut self, d: D)
pub fn push_str<D: Display>(&mut self, d: D)
Pushes an impl Display to the Text
If builder.no_space_after_empty is set to true and
the argument is equal to " ", then it won’t be added if
the previous argument was empty. This is useful especially
in situations where you expect to be constructing a Text
with spaces in between the elements (like in a status line),
but you don’t want an empty element to just leave to space
wide gap in between two non empty elements.
Sourcepub fn reset_form(&mut self)
pub fn reset_form(&mut self)
Resets the Form
This is equivalent to pushing the default Form.
Sourcepub fn reset_alignment(&mut self)
pub fn reset_alignment(&mut self)
Resets the Form
This is equivalent to pushing the default Form.
Trait Implementations§
Source§impl From<Builder> for BuilderPart
impl From<Builder> for BuilderPart
Auto Trait Implementations§
impl Freeze for Builder
impl !RefUnwindSafe for Builder
impl Send for Builder
impl !Sync for Builder
impl Unpin for Builder
impl !UnwindSafe for Builder
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
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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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.