diff --git a/src/import/mod.rs b/src/import/mod.rs index abac045..910b491 100644 --- a/src/import/mod.rs +++ b/src/import/mod.rs @@ -1,6 +1,6 @@ use self::converters::conv_layer; use self::util::NumberExt; -use crate::parser::{schema, Lottie}; +use crate::parser::{schema, Animation}; use crate::Composition; use std::collections::HashMap; @@ -12,7 +12,7 @@ mod util; pub fn import_composition( source: impl AsRef<[u8]>, ) -> Result> { - let source = Lottie::from_slice(source.as_ref())?; + let source = Animation::from_slice(source.as_ref())?; let mut target = Composition { frames: source.in_point.unwrap_f32()..source.out_point.unwrap_f32(), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 3bce1d6..bfa5e68 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,2 +1,2 @@ pub mod schema; -pub use schema::lottie::Lottie; +pub use schema::animation::animation::Animation; diff --git a/src/parser/schema/lottie.rs b/src/parser/schema/animation/animation.rs similarity index 84% rename from src/parser/schema/lottie.rs rename to src/parser/schema/animation/animation.rs index 10309cf..5205e0f 100644 --- a/src/parser/schema/lottie.rs +++ b/src/parser/schema/animation/animation.rs @@ -1,13 +1,11 @@ -use super::assets::AnyAsset; -use super::layers::AnyLayer; -use crate::parser::schema::helpers::int_boolean::BoolInt; +use crate::parser::schema::{assets::AnyAsset, helpers::int_boolean::BoolInt, layers::AnyLayer}; use serde::{Deserialize, Serialize}; use serde_json::Number; use std::fmt::Display; /// Top level object, describing the animation #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)] -pub struct Lottie { +pub struct Animation { /// Lottie file version #[serde(rename = "v")] #[serde(skip_serializing_if = "Option::is_none")] @@ -44,12 +42,12 @@ pub struct Lottie { pub layers: Vec, } -impl Lottie { - pub fn from_slice(v: &[u8]) -> Result { +impl Animation { + pub fn from_slice(v: &[u8]) -> Result { serde_json::from_slice(v) } - pub fn from_json(v: serde_json::Value) -> Result { + pub fn from_json(v: serde_json::Value) -> Result { serde_json::from_value(v) } @@ -58,7 +56,7 @@ impl Lottie { } } -impl std::str::FromStr for Lottie { +impl std::str::FromStr for Animation { type Err = serde_json::Error; fn from_str(s: &str) -> Result { @@ -66,7 +64,7 @@ impl std::str::FromStr for Lottie { } } -impl Display for Lottie { +impl Display for Animation { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", serde_json::to_string(&self).unwrap()) } diff --git a/src/parser/schema/animation/mod.rs b/src/parser/schema/animation/mod.rs index bdf0c2c..70c0dec 100644 --- a/src/parser/schema/animation/mod.rs +++ b/src/parser/schema/animation/mod.rs @@ -1,5 +1,6 @@ // todo motion-blur -// todo animation +#[allow(clippy::module_inception)] +pub mod animation; // todo user-metadata pub mod composition; // todo metadata diff --git a/src/parser/schema/mod.rs b/src/parser/schema/mod.rs index 84ffec3..7598a90 100644 --- a/src/parser/schema/mod.rs +++ b/src/parser/schema/mod.rs @@ -10,7 +10,6 @@ pub mod constants; // todo effects pub mod helpers; pub mod layers; -pub mod lottie; // this should be "animation" pub mod shapes; pub mod styles; //todo text diff --git a/tests/basic.rs b/tests/basic.rs index 9bceb56..40b3c4e 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -18,7 +18,7 @@ static JSON: Lazy = Lazy::new(|| { } ) }); -static LOTTIE: Lazy = Lazy::new(|| Lottie { +static LOTTIE: Lazy = Lazy::new(|| Animation { version: Some("5.5.2".to_string()), name: Some("Example".to_string()), frame_rate: Number::from(60), @@ -43,7 +43,7 @@ fn test_serde_deserialize() { #[test] fn test_deserialize() { - let actual = Lottie::from_json(JSON.to_owned()); + let actual = Animation::from_json(JSON.to_owned()); match actual { Ok(actual) => assert_eq!(*LOTTIE, actual),