pub struct SyntaxDisplay<'s, 'e, S, E> { /* private fields */ }Expand description
A wrapper that implements Display for types implementing SyntaxFmt.
Implementations§
Source§impl<'s, 'e, S, E> SyntaxDisplay<'s, 'e, S, E>
impl<'s, 'e, S, E> SyntaxDisplay<'s, 'e, S, E>
Sourcepub fn state<'s2, S2>(self, state: &'s2 S2) -> SyntaxDisplay<'s2, 'e, S2, E>
pub fn state<'s2, S2>(self, state: &'s2 S2) -> SyntaxDisplay<'s2, 'e, S2, E>
Set the state to use during formatting (immutable).
See SyntaxFormatter::state for usage examples.
Examples found in repository?
examples/comprehensive.rs (line 146)
117fn main() {
118 // Create example AST
119 let func = Function {
120 name: "calculate",
121 params: vec![
122 Parameter { name: "x", ty: Some("i32") },
123 Parameter { name: "y", ty: Some("i32") },
124 ],
125 return_type: Some("i32"),
126 body: Block {
127 statements: vec![
128 Statement::Expr(Expr::Call(FunctionCall {
129 name: "println",
130 args: vec![Expr::Literal(42)],
131 })),
132 Statement::Return {
133 value: Some(Expr::Binary {
134 left: Box::new(Expr::Literal(1)),
135 op: "+",
136 right: Box::new(Expr::Literal(2)),
137 }),
138 },
139 ],
140 },
141 };
142
143 let config = TypeConfig { show_types: true };
144
145 println!("Normal - with types:");
146 println!("{}", syntax_fmt(&func).state(&config));
147 println!();
148
149 println!("Pretty - with types:");
150 println!("{}", syntax_fmt(&func).state(&config).pretty());
151 println!();
152
153 let config_no_types = TypeConfig { show_types: false };
154
155 println!("Normal - without types:");
156 println!("{}", syntax_fmt(&func).state(&config_no_types));
157 println!();
158
159 println!("Pretty - without types:");
160 println!("{}", syntax_fmt(&func).state(&config_no_types).pretty());
161}Sourcepub fn state_mut<'s2, S2>(
self,
state: &'s2 mut S2,
) -> SyntaxDisplay<'s2, 'e, S2, E>
pub fn state_mut<'s2, S2>( self, state: &'s2 mut S2, ) -> SyntaxDisplay<'s2, 'e, S2, E>
Set the state to use during formatting (mutable).
See SyntaxFormatter::state_mut for usage examples.
Sourcepub fn pretty(self) -> Self
pub fn pretty(self) -> Self
Enable pretty printing mode.
Examples found in repository?
examples/comprehensive.rs (line 150)
117fn main() {
118 // Create example AST
119 let func = Function {
120 name: "calculate",
121 params: vec![
122 Parameter { name: "x", ty: Some("i32") },
123 Parameter { name: "y", ty: Some("i32") },
124 ],
125 return_type: Some("i32"),
126 body: Block {
127 statements: vec![
128 Statement::Expr(Expr::Call(FunctionCall {
129 name: "println",
130 args: vec![Expr::Literal(42)],
131 })),
132 Statement::Return {
133 value: Some(Expr::Binary {
134 left: Box::new(Expr::Literal(1)),
135 op: "+",
136 right: Box::new(Expr::Literal(2)),
137 }),
138 },
139 ],
140 },
141 };
142
143 let config = TypeConfig { show_types: true };
144
145 println!("Normal - with types:");
146 println!("{}", syntax_fmt(&func).state(&config));
147 println!();
148
149 println!("Pretty - with types:");
150 println!("{}", syntax_fmt(&func).state(&config).pretty());
151 println!();
152
153 let config_no_types = TypeConfig { show_types: false };
154
155 println!("Normal - without types:");
156 println!("{}", syntax_fmt(&func).state(&config_no_types));
157 println!();
158
159 println!("Pretty - without types:");
160 println!("{}", syntax_fmt(&func).state(&config_no_types).pretty());
161}Trait Implementations§
Auto Trait Implementations§
impl<'s, 'e, S, E> !Freeze for SyntaxDisplay<'s, 'e, S, E>
impl<'s, 'e, S, E> !RefUnwindSafe for SyntaxDisplay<'s, 'e, S, E>
impl<'s, 'e, S, E> Send for SyntaxDisplay<'s, 'e, S, E>
impl<'s, 'e, S, E> !Sync for SyntaxDisplay<'s, 'e, S, E>
impl<'s, 'e, S, E> Unpin for SyntaxDisplay<'s, 'e, S, E>
impl<'s, 'e, S, E> !UnwindSafe for SyntaxDisplay<'s, 'e, S, E>
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