Skip to content

Commit

Permalink
Move more types into this lib
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Dec 8, 2023
1 parent 611473f commit fb6b8f4
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 1 deletion.
63 changes: 63 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions modeling-cmds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ license = "MIT"

[dependencies]
chrono = "0.4.31"
cxx = "1.0"
data-encoding = "2.5.0"
diesel = { version = "2.1.1", features = ["serde_json", "mysql", "chrono", "r2d2", "uuid", "numeric"] }
diesel_derives = "2.1.2"
enum-iterator = "1.4.1"
enum-iterator-derive = "1.2.1"
euler = "0.4.1"
http = "0.2.9"
kittycad-unit-conversion-derive = { path = "../unit-conversion-derive" }
measurements = "0.11.0"
parse-display = "0.8.2"
Expand Down
18 changes: 18 additions & 0 deletions modeling-cmds/src/impl_extern_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! A little macro for easy implementation of cxx::ExternType
/// This tells the c++ interop what the native c++ names are
/// from https://docs.rs/cxx/latest/src/cxx/extern_type.rs.html
#[macro_export]
macro_rules! impl_extern_type {
($([$kind:ident] $($(#[$($attr:tt)*])* $ty:path = $cxxpath:literal)*)*) => {
$($(
$(#[$($attr)*])*
unsafe impl cxx::ExternType for $ty {
#[allow(unused_attributes)] // incorrect lint; this doc(hidden) attr *is* respected by rustdoc
#[doc(hidden)]
type Id = cxx::type_id!($cxxpath);
type Kind = cxx::kind::$kind;
}
)*)*
};
}
1 change: 1 addition & 0 deletions modeling-cmds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod format;
/// Modeling command IDs, used to associated requests and responses.
/// Also used to construct commands which refer to previous commands.
pub mod id;
pub mod impl_extern_type;
mod impl_traits;
/// When a modeling command is successful, these responses could be returned.
pub mod ok_response;
Expand Down
51 changes: 50 additions & 1 deletion modeling-cmds/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use parse_display_derive::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::units::UnitAngle;
use crate::{impl_extern_type, units::UnitAngle};

// A helper macro for allowing enums of only strings to be saved to the database.
macro_rules! impl_string_enum_sql {
Expand Down Expand Up @@ -700,4 +700,53 @@ pub enum FileImportFormat {
Stl,
}

/// The type of error sent by the KittyCAD graphics engine.
/// A subset of [`ErrorCode`].
#[derive(Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd)]
#[serde(rename_all = "snake_case")]
pub enum EngineErrorCode {
/// User requested something geometrically or graphically impossible.
/// Don't retry this request, as it's inherently impossible. Instead, read the error message
/// and change your request.
BadRequest = 1,
/// Graphics engine failed to complete request, consider retrying
InternalEngine,
}

impl From<EngineErrorCode> for http::StatusCode {
fn from(e: EngineErrorCode) -> Self {
match e {
EngineErrorCode::BadRequest => Self::BAD_REQUEST,
EngineErrorCode::InternalEngine => Self::INTERNAL_SERVER_ERROR,
}
}
}

impl_string_enum_sql! {FileImportFormat}

// Enum: Connect Rust Enums to Cpp
// add our native c++ names for our cxx::ExternType implementation
impl_extern_type! {
[Trivial]
// File
FileImportFormat = "Enums::_FileImportFormat"
FileExportFormat = "Enums::_FileExportFormat"
// Camera
CameraDragInteractionType = "Enums::_CameraDragInteractionType"
// Scene
SceneSelectionType = "Enums::_SceneSelectionType"
SceneToolType = "Enums::_SceneToolType"
EntityType = "Enums::_EntityType"
AnnotationType = "Enums::_AnnotationType"
AnnotationTextAlignmentX = "Enums::_AnnotationTextAlignmentX"
AnnotationTextAlignmentY = "Enums::_AnnotationTextAlignmentY"
AnnotationLineEnd = "Enums::_AnnotationLineEnd"

CurveType = "Enums::_CurveType"
PathCommand = "Enums::_PathCommand"
PathComponentConstraintBound = "Enums::_PathComponentConstraintBound"
PathComponentConstraintType = "Enums::_PathComponentConstraintType"

// Utils
EngineErrorCode = "Enums::_ErrorCode"
}

0 comments on commit fb6b8f4

Please sign in to comment.