Skip to content

Commit

Permalink
Clippy Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Nov 13, 2024
1 parent fe614ee commit 7578c1d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 75 deletions.
34 changes: 34 additions & 0 deletions fastn-type/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ pub struct Loop {
pub line_number: usize,
}

impl Loop {
pub fn new(
on: fastn_type::PropertyValue,
alias: &str,
loop_counter_alias: Option<String>,
line_number: usize,
) -> fastn_type::Loop {
fastn_type::Loop {
on,
alias: alias.to_string(),
line_number,
loop_counter_alias,
}
}
}

#[derive(Debug, Clone, PartialEq, Default, serde::Deserialize, serde::Serialize)]
pub enum ComponentSource {
#[default]
Expand Down Expand Up @@ -117,4 +133,22 @@ pub struct ComponentDefinition {
pub line_number: usize,
}

impl fastn_type::ComponentDefinition {
pub fn new(
name: &str,
arguments: Vec<fastn_type::Argument>,
definition: fastn_type::Component,
css: Option<fastn_type::PropertyValue>,
line_number: usize,
) -> fastn_type::ComponentDefinition {
fastn_type::ComponentDefinition {
name: name.to_string(),
arguments,
definition,
css,
line_number,
}
}
}

pub type Argument = fastn_type::Field;
6 changes: 3 additions & 3 deletions ftd/src/executor/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl ImageSrc {
.resolve(&doc.itdoc(), line_number)?
.string(doc.name, line_number)?,
Some(line_number),
vec![value.into_property(fastn_type::PropertySource::header("light"))],
vec![value.to_property(fastn_type::PropertySource::header("light"))],
)
};

Expand All @@ -314,7 +314,7 @@ impl ImageSrc {
.resolve(&doc.itdoc(), line_number)?
.string(doc.name, line_number)?,
Some(line_number),
vec![value.into_property(fastn_type::PropertySource::header("dark"))],
vec![value.to_property(fastn_type::PropertySource::header("dark"))],
)
} else {
light.clone()
Expand Down Expand Up @@ -405,7 +405,7 @@ impl RawImage {
.resolve(&doc.itdoc(), line_number)?
.string(doc.name, line_number)?,
Some(line_number),
vec![value.into_property(fastn_type::PropertySource::header("src"))],
vec![value.to_property(fastn_type::PropertySource::header("src"))],
)
};

Expand Down
4 changes: 2 additions & 2 deletions ftd/src/executor/fastn_type_functions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub(crate) trait PropertyValueExt {
fn into_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property;
fn to_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property;
}

impl PropertyValueExt for fastn_type::PropertyValue {
fn into_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property {
fn to_property(&self, source: fastn_type::PropertySource) -> fastn_type::Property {
fastn_type::Property {
value: self.clone(),
source,
Expand Down
46 changes: 22 additions & 24 deletions ftd/src/executor/styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl BreakpointWidth {
.integer(doc.name, line_number)?,
Some(line_number),
vec![get_property_value("mobile")?
.into_property(fastn_type::PropertySource::header("mobile"))],
.to_property(fastn_type::PropertySource::header("mobile"))],
);

Ok(BreakpointWidth { mobile })
Expand Down Expand Up @@ -955,9 +955,7 @@ impl BackgroundImage {
line_number,
)?,
Some(line_number),
vec![
get_property_value("src")?.into_property(fastn_type::PropertySource::header("src"))
],
vec![get_property_value("src")?.to_property(fastn_type::PropertySource::header("src"))],
);

let repeat = ftd::executor::Value::new(
Expand All @@ -968,7 +966,7 @@ impl BackgroundImage {
)?,
Some(line_number),
vec![get_property_value("repeat")?
.into_property(fastn_type::PropertySource::header("repeat"))],
.to_property(fastn_type::PropertySource::header("repeat"))],
);

let size = ftd::executor::Value::new(
Expand All @@ -978,8 +976,9 @@ impl BackgroundImage {
line_number,
)?,
Some(line_number),
vec![get_property_value("size")?
.into_property(fastn_type::PropertySource::header("size"))],
vec![
get_property_value("size")?.to_property(fastn_type::PropertySource::header("size"))
],
);

let position = ftd::executor::Value::new(
Expand All @@ -990,7 +989,7 @@ impl BackgroundImage {
)?,
Some(line_number),
vec![get_property_value("position")?
.into_property(fastn_type::PropertySource::header("position"))],
.to_property(fastn_type::PropertySource::header("position"))],
);

Ok(ftd::executor::BackgroundImage {
Expand Down Expand Up @@ -1139,7 +1138,7 @@ impl LinearGradientColor {
)?,
Some(line_number),
vec![get_property_value("start")?
.into_property(fastn_type::PropertySource::header("start"))],
.to_property(fastn_type::PropertySource::header("start"))],
);

let end = ftd::executor::Value::new(
Expand All @@ -1149,9 +1148,7 @@ impl LinearGradientColor {
line_number,
)?,
Some(line_number),
vec![
get_property_value("end")?.into_property(fastn_type::PropertySource::header("end"))
],
vec![get_property_value("end")?.to_property(fastn_type::PropertySource::header("end"))],
);

let stop_position = ftd::executor::Value::new(
Expand All @@ -1162,7 +1159,7 @@ impl LinearGradientColor {
)?,
Some(line_number),
vec![get_property_value("stop-position")?
.into_property(fastn_type::PropertySource::header("stop-position"))],
.to_property(fastn_type::PropertySource::header("stop-position"))],
);

Ok(ftd::executor::LinearGradientColor {
Expand Down Expand Up @@ -1353,7 +1350,7 @@ impl LinearGradient {
)?,
Some(line_number),
vec![get_property_value("direction")?
.into_property(fastn_type::PropertySource::header("direction"))],
.to_property(fastn_type::PropertySource::header("direction"))],
);

let colors = ftd::executor::Value::new(
Expand All @@ -1364,7 +1361,7 @@ impl LinearGradient {
)?,
Some(line_number),
vec![get_property_value("colors")?
.into_property(fastn_type::PropertySource::header("colors"))],
.to_property(fastn_type::PropertySource::header("colors"))],
);

Ok(ftd::executor::LinearGradient { direction, colors })
Expand Down Expand Up @@ -1841,35 +1838,36 @@ impl Shadow {
Length::from_value(get_property_value("x-offset")?.clone(), doc, line_number)?,
Some(line_number),
vec![get_property_value("x-offset")?
.into_property(fastn_type::PropertySource::header("x-offset"))],
.to_property(fastn_type::PropertySource::header("x-offset"))],
);

let y_offset = ftd::executor::Value::new(
Length::from_value(get_property_value("y-offset")?.clone(), doc, line_number)?,
Some(line_number),
vec![get_property_value("y-offset")?
.into_property(fastn_type::PropertySource::header("y-offset"))],
.to_property(fastn_type::PropertySource::header("y-offset"))],
);

let blur = ftd::executor::Value::new(
Length::from_value(get_property_value("blur")?.clone(), doc, line_number)?,
Some(line_number),
vec![get_property_value("blur")?
.into_property(fastn_type::PropertySource::header("blur"))],
vec![
get_property_value("blur")?.to_property(fastn_type::PropertySource::header("blur"))
],
);

let spread = ftd::executor::Value::new(
Length::from_value(get_property_value("spread")?.clone(), doc, line_number)?,
Some(line_number),
vec![get_property_value("spread")?
.into_property(fastn_type::PropertySource::header("spread"))],
.to_property(fastn_type::PropertySource::header("spread"))],
);

let color = ftd::executor::Value::new(
Color::from_value(get_property_value("color")?.clone(), doc, line_number)?,
Some(line_number),
vec![get_property_value("color")?
.into_property(fastn_type::PropertySource::header("color"))],
.to_property(fastn_type::PropertySource::header("color"))],
);

let inset = ftd::executor::Value::new(
Expand All @@ -1879,7 +1877,7 @@ impl Shadow {
.bool(doc.name, line_number)?,
Some(line_number),
vec![get_property_value("inset")?
.into_property(fastn_type::PropertySource::header("inset"))],
.to_property(fastn_type::PropertySource::header("inset"))],
);

Ok(ftd::executor::Shadow {
Expand Down Expand Up @@ -2022,7 +2020,7 @@ impl Color {
line_number,
)?,
Some(line_number),
vec![value.into_property(fastn_type::PropertySource::header("light"))],
vec![value.to_property(fastn_type::PropertySource::header("light"))],
)
};

Expand All @@ -2038,7 +2036,7 @@ impl Color {
line_number,
)?,
Some(line_number),
vec![value.into_property(fastn_type::PropertySource::header("dark"))],
vec![value.to_property(fastn_type::PropertySource::header("dark"))],
)
} else {
light.clone()
Expand Down
50 changes: 4 additions & 46 deletions ftd/src/interpreter/things/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ use ftd::interpreter::things::function::FunctionCallExt;
use ftd::interpreter::things::record::FieldExt;

pub trait ComponentDefinitionExt {
fn new(
name: &str,
arguments: Vec<fastn_type::Argument>,
definition: fastn_type::Component,
css: Option<fastn_type::PropertyValue>,
line_number: usize,
) -> fastn_type::ComponentDefinition;
fn scan_ast(
ast: ftd_ast::Ast,
doc: &mut ftd::interpreter::TDoc,
Expand All @@ -22,22 +15,6 @@ pub trait ComponentDefinitionExt {
}

impl ComponentDefinitionExt for fastn_type::ComponentDefinition {
fn new(
name: &str,
arguments: Vec<fastn_type::Argument>,
definition: fastn_type::Component,
css: Option<fastn_type::PropertyValue>,
line_number: usize,
) -> fastn_type::ComponentDefinition {
fastn_type::ComponentDefinition {
name: name.to_string(),
arguments,
definition,
css,
line_number,
}
}

fn scan_ast(
ast: ftd_ast::Ast,
doc: &mut ftd::interpreter::TDoc,
Expand Down Expand Up @@ -1019,8 +996,8 @@ pub trait ComponentExt {
condition: &Option<fastn_type::Expression>,
loop_object_name_and_kind: &Option<(String, fastn_type::Argument, Option<String>)>,
events: &[fastn_type::Event],
ast_properties: &Vec<ftd_ast::Property>,
ast_children: &Vec<ftd_ast::ComponentInvocation>,
ast_properties: &[ftd_ast::Property],
ast_children: &[ftd_ast::ComponentInvocation],
line_number: usize,
) -> ftd::interpreter::Result<ftd::interpreter::StateWithThing<Option<fastn_type::Component>>>;
}
Expand Down Expand Up @@ -1352,8 +1329,8 @@ impl ComponentExt for fastn_type::Component {
condition: &Option<fastn_type::Expression>,
loop_object_name_and_kind: &Option<(String, fastn_type::Argument, Option<String>)>,
events: &[fastn_type::Event],
ast_properties: &Vec<ftd_ast::Property>,
ast_children: &Vec<ftd_ast::ComponentInvocation>,
ast_properties: &[ftd_ast::Property],
ast_children: &[ftd_ast::ComponentInvocation],
line_number: usize,
) -> ftd::interpreter::Result<ftd::interpreter::StateWithThing<Option<fastn_type::Component>>>
{
Expand Down Expand Up @@ -1455,12 +1432,6 @@ impl ComponentExt for fastn_type::Component {
}

pub trait LoopExt {
fn new(
on: fastn_type::PropertyValue,
alias: &str,
loop_counter_alias: Option<String>,
line_number: usize,
) -> fastn_type::Loop;
fn from_ast_loop(
ast_loop: ftd_ast::Loop,
definition_name_with_arguments: &mut Option<(&str, &mut [fastn_type::Argument])>,
Expand All @@ -1483,19 +1454,6 @@ pub trait LoopExt {
}

impl LoopExt for fastn_type::Loop {
fn new(
on: fastn_type::PropertyValue,
alias: &str,
loop_counter_alias: Option<String>,
line_number: usize,
) -> fastn_type::Loop {
fastn_type::Loop {
on,
alias: alias.to_string(),
line_number,
loop_counter_alias,
}
}
fn from_ast_loop(
ast_loop: ftd_ast::Loop,
definition_name_with_arguments: &mut Option<(&str, &mut [fastn_type::Argument])>,
Expand Down

0 comments on commit 7578c1d

Please sign in to comment.