mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Add BoolExt
trait with flip
method
This commit is contained in:
parent
18190f377a
commit
87e776fceb
@ -5,6 +5,7 @@ use crate::diag::TypResult;
|
|||||||
use crate::geom::Gen;
|
use crate::geom::Gen;
|
||||||
use crate::layout::{ParChild, ParNode, StackChild, StackNode};
|
use crate::layout::{ParChild, ParNode, StackChild, StackNode};
|
||||||
use crate::syntax::*;
|
use crate::syntax::*;
|
||||||
|
use crate::util::BoolExt;
|
||||||
|
|
||||||
/// Walk a syntax node and fill the currently built template.
|
/// Walk a syntax node and fill the currently built template.
|
||||||
pub trait Walk {
|
pub trait Walk {
|
||||||
@ -27,8 +28,8 @@ impl Walk for SyntaxNode {
|
|||||||
Self::Space => ctx.template.space(),
|
Self::Space => ctx.template.space(),
|
||||||
Self::Linebreak(_) => ctx.template.linebreak(),
|
Self::Linebreak(_) => ctx.template.linebreak(),
|
||||||
Self::Parbreak(_) => ctx.template.parbreak(),
|
Self::Parbreak(_) => ctx.template.parbreak(),
|
||||||
Self::Strong(_) => ctx.template.modify(|s| s.font_mut().strong ^= true),
|
Self::Strong(_) => ctx.template.modify(|s| s.font_mut().strong.flip()),
|
||||||
Self::Emph(_) => ctx.template.modify(|s| s.font_mut().emph ^= true),
|
Self::Emph(_) => ctx.template.modify(|s| s.font_mut().emph.flip()),
|
||||||
Self::Text(text) => ctx.template.text(text),
|
Self::Text(text) => ctx.template.text(text),
|
||||||
Self::Raw(raw) => raw.walk(ctx)?,
|
Self::Raw(raw) => raw.walk(ctx)?,
|
||||||
Self::Heading(heading) => heading.walk(ctx)?,
|
Self::Heading(heading) => heading.walk(ctx)?,
|
||||||
|
@ -11,6 +11,18 @@ use std::cmp::Ordering;
|
|||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::path::{Component, Path, PathBuf};
|
use std::path::{Component, Path, PathBuf};
|
||||||
|
|
||||||
|
/// Additional methods for booleans.
|
||||||
|
pub trait BoolExt {
|
||||||
|
/// Toggle the value of the bool in place.
|
||||||
|
fn flip(&mut self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BoolExt for bool {
|
||||||
|
fn flip(&mut self) {
|
||||||
|
*self = !*self;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Additional methods for options.
|
/// Additional methods for options.
|
||||||
pub trait OptionExt<T> {
|
pub trait OptionExt<T> {
|
||||||
/// Replace `self` with `other` if `self` is `Some`.
|
/// Replace `self` with `other` if `self` is `Some`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user