Start implementing Rust
This commit is contained in:
14
templates/Rust/Cargo.toml
Normal file
14
templates/Rust/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "${NAME}"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
int-enum = "0.4.0"
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
|
||||
# These might not have to be included, since the serialization could be implementation dependent and having a dependency less is always a good thing.
|
||||
# serde_json = "1.0.79"
|
||||
# rmp-serde = "1.0.0"
|
@ -4,13 +4,24 @@ export class VerificationError extends Error {
|
||||
public readonly field?: string,
|
||||
public readonly value?: any
|
||||
) {
|
||||
super("Parameter verification failed! " +(type ? "Expected " + type + "! " :"") + (field ? "At: " + field + "! " : ""));
|
||||
super(
|
||||
"Parameter verification failed! " +
|
||||
(type ? "Expected " + type + "! " : "") +
|
||||
(field ? "At: " + field + "! " : "")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function apply_number(data: any) {
|
||||
export function apply_int(data: any) {
|
||||
data = Math.floor(Number(data));
|
||||
if (Number.isNaN(data)) throw new VerificationError("int", undefined, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
export function apply_float(data: any) {
|
||||
data = Number(data);
|
||||
if(Number.isNaN(data)) throw new VerificationError("number", undefined, data);
|
||||
if (Number.isNaN(data))
|
||||
throw new VerificationError("float", undefined, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user