Implement From conversion for style detector-to-generator (#1678)

This commit is contained in:
Charlie Marsh
2023-01-05 21:47:48 -05:00
committed by GitHub
parent 8caa73df6a
commit fe67a0d239
15 changed files with 38 additions and 116 deletions

View File

@@ -9,7 +9,7 @@ use rustpython_parser::ast::{
Operator, Stmt, StmtKind,
};
use crate::source_code_style::{Indentation, LineEnding, Quote};
use crate::source_code_style::{Indentation, LineEnding, Quote, SourceCodeStyleDetector};
use crate::vendor::{bytes, str};
mod precedence {
@@ -43,6 +43,20 @@ pub struct SourceCodeGenerator<'a> {
initial: bool,
}
impl<'a> From<&'a SourceCodeStyleDetector<'a>> for SourceCodeGenerator<'a> {
fn from(stylist: &'a SourceCodeStyleDetector<'a>) -> Self {
Self {
indent: stylist.indentation(),
quote: stylist.quote(),
line_ending: stylist.line_ending(),
buffer: Vec::new(),
indent_depth: 0,
num_newlines: 0,
initial: true,
}
}
}
impl<'a> SourceCodeGenerator<'a> {
pub fn new(indent: &'a Indentation, quote: &'a Quote, line_ending: &'a LineEnding) -> Self {
SourceCodeGenerator {