Skip to content

Commit

Permalink
refactor: rename schema Lottie to Animation
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Mar 10, 2024
1 parent 5df4075 commit 1b4322d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/import/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -12,7 +12,7 @@ mod util;
pub fn import_composition(
source: impl AsRef<[u8]>,
) -> Result<Composition, Box<dyn std::error::Error>> {
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(),
Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod schema;
pub use schema::lottie::Lottie;
pub use schema::animation::animation::Animation;
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -44,12 +42,12 @@ pub struct Lottie {
pub layers: Vec<AnyLayer>,
}

impl Lottie {
pub fn from_slice(v: &[u8]) -> Result<Lottie, serde_json::Error> {
impl Animation {
pub fn from_slice(v: &[u8]) -> Result<Animation, serde_json::Error> {
serde_json::from_slice(v)
}

pub fn from_json(v: serde_json::Value) -> Result<Lottie, serde_json::Error> {
pub fn from_json(v: serde_json::Value) -> Result<Animation, serde_json::Error> {
serde_json::from_value(v)
}

Expand All @@ -58,15 +56,15 @@ 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<Self, Self::Err> {
serde_json::from_str(s)
}
}

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())
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser/schema/animation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// todo motion-blur
// todo animation
#[allow(clippy::module_inception)]
pub mod animation;
// todo user-metadata
pub mod composition;
// todo metadata
1 change: 0 additions & 1 deletion src/parser/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static JSON: Lazy<serde_json::Value> = Lazy::new(|| {
}
)
});
static LOTTIE: Lazy<Lottie> = Lazy::new(|| Lottie {
static LOTTIE: Lazy<Animation> = Lazy::new(|| Animation {
version: Some("5.5.2".to_string()),
name: Some("Example".to_string()),
frame_rate: Number::from(60),
Expand All @@ -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),
Expand Down

0 comments on commit 1b4322d

Please sign in to comment.