mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 17:08:13 +00:00
dimensions wip
This commit is contained in:
1 parent
ce0fb4bf9e
commit
9cb2d3f74e
8 files changed
+182
-4
No files matched your search
Generated
+8
@@ -1994,6 +1994,14 @@ dependencies = [
|
||||
"chrono",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dimensions"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"errors",
|
||||
"my-workspace-hack",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "displaydoc"
|
||||
version = "0.2.4"
|
||||
|
||||
@@ -40,6 +40,7 @@ members = [
|
||||
"crates/lib/deprecated/config", # TODO(bt, 2023-02-13): Deprecate or repurpose
|
||||
"crates/lib/deprecated/container_common", # TODO(bt, 2023-02-13): Pull apart and rehome pieces
|
||||
"crates/lib/deprecated/http_server_common", # TODO(bt, 2023-03-20): Move useful pieces to actix_helpers
|
||||
"crates/lib/dimensions",
|
||||
"crates/lib/easyenv", # NB: Vendored version of https://github.com/echelon/easyenv.rs that we'll improve.
|
||||
"crates/lib/elasticsearch_schema",
|
||||
"crates/lib/email_sender",
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod premium_product;
|
||||
pub mod style_transfer;
|
||||
pub mod style_transfer;
|
||||
pub mod video_dimensions;
|
||||
@@ -0,0 +1 @@
|
||||
mod video_dimensions;
|
||||
@@ -0,0 +1,117 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[cfg(test)]
|
||||
use strum::EnumCount;
|
||||
#[cfg(test)]
|
||||
use strum::EnumIter;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
/// This enum is not backed by a particular database table.
|
||||
/// This is used to determine the video generation size.
|
||||
#[cfg_attr(test, derive(EnumIter, EnumCount))]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum VideoDimensions {
|
||||
Landscape,
|
||||
Portrait,
|
||||
Square,
|
||||
}
|
||||
|
||||
// TODO(bt, 2022-12-21): This desperately needs MySQL integration tests!
|
||||
impl_enum_display_and_debug_using_to_str!(VideoDimensions);
|
||||
//impl_mysql_enum_coders!(VideoDimensions);
|
||||
//impl_mysql_from_row!(VideoDimensions);
|
||||
|
||||
/// NB: Legacy API for older code.
|
||||
impl VideoDimensions {
|
||||
pub fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Landscape => "landscape",
|
||||
Self::Portrait => "portrait",
|
||||
Self::Square => "square",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_str(value: &str) -> Result<Self, String> {
|
||||
match value {
|
||||
"landscape" => Ok(Self::Landscape),
|
||||
"portrait" => Ok(Self::Portrait),
|
||||
"square" => Ok(Self::Square),
|
||||
_ => Err(format!("Unknown VideoDimensions: {}", value)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn all_variants() -> BTreeSet<Self> {
|
||||
// NB: BTreeSet is sorted
|
||||
// NB: BTreeSet::from() isn't const, but not worth using LazyStatic, etc.
|
||||
BTreeSet::from([
|
||||
Self::Landscape,
|
||||
Self::Portrait,
|
||||
Self::Square,
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::no_table::video_dimensions::video_dimensions::VideoDimensions;
|
||||
use crate::test_helpers::assert_serialization;
|
||||
|
||||
mod serde {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_serialization() {
|
||||
assert_serialization(VideoDimensions::Landscape, "landscape");
|
||||
assert_serialization(VideoDimensions::Portrait, "portrait");
|
||||
assert_serialization(VideoDimensions::Square, "square");
|
||||
}
|
||||
|
||||
mod impl_methods {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn to_str() {
|
||||
assert_eq!(VideoDimensions::Landscape.to_str(), "landscape");
|
||||
assert_eq!(VideoDimensions::Portrait.to_str(), "portrait");
|
||||
assert_eq!(VideoDimensions::Square.to_str(), "square");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_str() {
|
||||
assert_eq!(VideoDimensions::from_str("landscape").unwrap(), VideoDimensions::Landscape);
|
||||
assert_eq!(VideoDimensions::from_str("portrait").unwrap(), VideoDimensions::Portrait);
|
||||
assert_eq!(VideoDimensions::from_str("square").unwrap(), VideoDimensions::Square);
|
||||
}
|
||||
}
|
||||
|
||||
mod manual_variant_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn all_variants() {
|
||||
let variants = VideoDimensions::all_variants();
|
||||
assert_eq!(variants.len(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn variant_length() {
|
||||
use strum::IntoEnumIterator;
|
||||
assert_eq!(VideoDimensions::all_variants().len(), VideoDimensions::iter().len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip() {
|
||||
for variant in VideoDimensions::all_variants() {
|
||||
assert_eq!(variant, VideoDimensions::from_str(variant.to_str()).unwrap());
|
||||
assert_eq!(variant, VideoDimensions::from_str(&format!("{}", variant)).unwrap());
|
||||
assert_eq!(variant, VideoDimensions::from_str(&format!("{:?}", variant)).unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
[package]
|
||||
name = "dimensions"
|
||||
edition = "2018"
|
||||
version = "0.0.1"
|
||||
authors = [
|
||||
"Brandon Thomas <bt@brand.io>",
|
||||
"Brandon Thomas <echelon@gmail.com>",
|
||||
]
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
# NB: Public "dimensions" crate is not relevant / abandoned, so we're fine to use this internally.
|
||||
name = "dimensions"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[package.metadata.cargo-udeps.ignore]
|
||||
normal = ["my-workspace-hack"]
|
||||
|
||||
[dependencies]
|
||||
# Workspace hack (faster compile times)
|
||||
my-workspace-hack = { version = "0.1", path = "../../my-workspace-hack" }
|
||||
|
||||
# Internal
|
||||
errors = { path = "../errors" }
|
||||
|
||||
# External
|
||||
# (None Yet)
|
||||
|
||||
[dev-dependencies]
|
||||
# None yet
|
||||
@@ -0,0 +1,20 @@
|
||||
//! dimensions
|
||||
//!
|
||||
//! The purpose of this library is to specify common dimensions for video and
|
||||
//! to do aspect ratio calculations in a reusable manner.
|
||||
//!
|
||||
|
||||
// Never allow these
|
||||
#![forbid(private_bounds)]
|
||||
#![forbid(private_interfaces)]
|
||||
#![forbid(unused_must_use)] // NB: It's unsafe to not close/check some things
|
||||
|
||||
// Okay to toggle
|
||||
#![forbid(unreachable_patterns)]
|
||||
#![forbid(unused_imports)]
|
||||
#![forbid(unused_mut)]
|
||||
#![forbid(unused_variables)]
|
||||
|
||||
// Always allow
|
||||
#![allow(dead_code)]
|
||||
#![allow(non_snake_case)]
|
||||
@@ -17,12 +17,12 @@ path = "src/lib.rs"
|
||||
normal = ["my-workspace-hack"]
|
||||
|
||||
[dependencies]
|
||||
# Internal
|
||||
errors = { path = "../errors" }
|
||||
|
||||
# Workspace hack (faster compile times)
|
||||
my-workspace-hack = { version = "0.1", path = "../../my-workspace-hack" }
|
||||
|
||||
# Internal
|
||||
errors = { path = "../errors" }
|
||||
|
||||
# External
|
||||
bcrypt = "0.15" # password hashes
|
||||
#hmac = "0.10.0" # jwt signing
|
||||
|
||||
Reference in new issue
Block a user