SyntaxDisplay

Struct SyntaxDisplay 

Source
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>

Source

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}
Source

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.

Source

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}
Source

pub fn indent(self, indent: Strs) -> Self

Set the indentation string (default is “” for Normal mode and “ “ for Pretty mode).

Source

pub fn newline(self, newline: Strs) -> Self

Set the newline strings (default is “” for Normal mode and “\n” for Pretty mode).

Trait Implementations§

Source§

impl<'s, 'e, S, E> Display for SyntaxDisplay<'s, 'e, S, E>
where E: SyntaxFmt<S>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more

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>
where E: Sync, S: Sync + Send,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.