# HG changeset patch # User ellis # Date 1682907858 14400 # Node ID e4f8df713d55fea589b6a38541303212d5954bc1 # Parent eb8ed24e8a76b657f3af4e6c5af63ba8e29f12df scaffolding from lives past diff -r eb8ed24e8a76 -r e4f8df713d55 build.rs --- a/build.rs Sun Apr 30 22:01:32 2023 -0400 +++ b/build.rs Sun Apr 30 22:24:18 2023 -0400 @@ -5,10 +5,10 @@ let crate_dir: PathBuf = env::var("CARGO_MANIFEST_DIR") .expect("CARGO_MANIFEST_DIR env var is not defined") .into(); - let mpk_py = "build.py"; + // let mpk_py = "build.py"; let config = cbindgen::Config::from_file("cbindgen.toml") .expect("Unable to find cbindgen.toml configuration file"); - let build_dir = crate_dir.join("build/"); + let build_dir = crate_dir.join("ffi/"); if !build_dir.exists() { create_dir(&build_dir).unwrap(); } diff -r eb8ed24e8a76 -r e4f8df713d55 cfg/Cargo.toml --- a/cfg/Cargo.toml Sun Apr 30 22:01:32 2023 -0400 +++ b/cfg/Cargo.toml Sun Apr 30 22:24:18 2023 -0400 @@ -3,4 +3,5 @@ version = "0.1.0" edition = "2021" [dependencies] -serde_dhall = "0.12.1" \ No newline at end of file +obj = {version = "0.1.0",path = "../obj"} +serde_dhall = "0.12.1" diff -r eb8ed24e8a76 -r e4f8df713d55 cfg/src/lib.rs --- a/cfg/src/lib.rs Sun Apr 30 22:01:32 2023 -0400 +++ b/cfg/src/lib.rs Sun Apr 30 22:24:18 2023 -0400 @@ -1,14 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} +//! cfg/src/lib.rs --- Configuration types #[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} +mod tests; diff -r eb8ed24e8a76 -r e4f8df713d55 cfg/src/tests.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cfg/src/tests.rs Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,6 @@ +//! cfg/src/tests --- unit tests +use crate::*; +#[test] +fn test_hello() { + println!("looks good chief"); +} diff -r eb8ed24e8a76 -r e4f8df713d55 makefile --- a/makefile Sun Apr 30 22:01:32 2023 -0400 +++ b/makefile Sun Apr 30 22:24:18 2023 -0400 @@ -3,8 +3,8 @@ .PHONY:build $(O):;mkdir -p $@ clean:;rm -rf out *.fasl;cargo clean -build:;ros/build.ros -docs:;ros/docs.ros -test:;ros/test.ros -pack:;ros/pack.ros +build:;scripts/build.ros +docs:;scripts/docs.ros +test:;scripts/test.ros +pack:;scripts/pack.ros ci:clean build docs test pack; diff -r eb8ed24e8a76 -r e4f8df713d55 obj/Cargo.toml --- a/obj/Cargo.toml Sun Apr 30 22:01:32 2023 -0400 +++ b/obj/Cargo.toml Sun Apr 30 22:24:18 2023 -0400 @@ -2,7 +2,15 @@ name = "obj" version = "0.1.0" edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] +ron = "0.7.0" +bincode = "1.3.3" +serde_json = "1.0.68" +serde = { version = "1.0.130", features = ["derive"] } +chrono = { version = "0.4.19", features = ["serde"] } +mime = "0.3.16" +regex = "1.5.4" +rusty_ulid = "0.11.0" +uuid = { version = "0.8", features = ["serde"] } +[target.'cfg(target_arch = "wasm32")'.dependencies] +uuid = { version = "0.8", features = ["wasm-bindgen"] } diff -r eb8ed24e8a76 -r e4f8df713d55 obj/src/err.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/obj/src/err.rs Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,81 @@ +//! obj errors +use std::{fmt, io}; + +/// obj Result wrapper +pub type Result = std::result::Result; + +/// obj Error type +#[derive(Debug)] +pub enum Error { + Message(String), + Ron(ron::error::Error), + Json(serde_json::error::Error), + Io(io::Error), + Bincode(bincode::Error), + Utf8(std::string::FromUtf8Error), + Parse(std::string::ParseError), +} + +impl serde::ser::Error for Error { + fn custom(msg: T) -> Self { + Error::Message(msg.to_string()) + } +} + +impl serde::de::Error for Error { + fn custom(msg: T) -> Self { + Error::Message(msg.to_string()) + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Error::Message(msg) => f.write_str(msg), + Error::Io(ref err) => write!(f, "obj IO error: {}", err), + Error::Ron(ref err) => write!(f, "obj Ron error: {}", err), + Error::Json(ref err) => write!(f, "obj Json error: {}", err), + Error::Bincode(ref err) => write!(f, "obj Bincode error: {}", err), + Error::Utf8(ref err) => write!(f, "obj Utf8 error: {}", err), + Error::Parse(ref err) => write!(f, "obj Parse error: {}", err), + } + } +} + +impl From for Error { + fn from(e: io::Error) -> Self { + Error::Io(e) + } +} + +impl From for Error { + fn from(e: std::string::ParseError) -> Self { + Error::Parse(e) + } +} + +impl From for Error { + fn from(err: std::string::FromUtf8Error) -> Self { + Error::Utf8(err) + } +} + +impl From for Error { + fn from(e: ron::Error) -> Self { + Error::Ron(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Json(e) + } +} + +impl From for Error { + fn from(e: bincode::Error) -> Self { + Error::Bincode(e) + } +} + +impl std::error::Error for Error {} diff -r eb8ed24e8a76 -r e4f8df713d55 obj/src/lib.rs --- a/obj/src/lib.rs Sun Apr 30 22:01:32 2023 -0400 +++ b/obj/src/lib.rs Sun Apr 30 22:24:18 2023 -0400 @@ -1,14 +1,125 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +//! obj/src/lib.rs --- Objective type library +mod err; +pub use err::{Error,Result}; + +pub use ron; + +use ron::extensions::Extensions; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use std::io; + +/// common trait for all config modules. This trait provides functions +/// for de/serializing to/from RON, updating fields, and formatting. +pub trait Configure: Objective { + fn update(&self) -> Result<()> { + Ok(()) + } } -#[cfg(test)] -mod tests { - use super::*; +/// Objective trait +/// Define Object behaviors, implemented by Objects +pub trait Objective { + fn encode(&self) -> Result> + where + Self: Serialize, + { + Ok(bincode::serialize(self)?) + } + + fn encode_into(&self, writer: W) -> Result<()> + where + W: io::Write, + Self: Serialize, + { + Ok(bincode::serialize_into(writer, self)?) + } + + fn decode<'a>(&self, bytes: &'a [u8]) -> Result + where + Self: Deserialize<'a>, + { + Ok(bincode::deserialize(bytes)?) + } + + fn decode_from(&self, rdr: R) -> Result + where + R: io::Read, + Self: DeserializeOwned, + { + Ok(bincode::deserialize_from(rdr)?) + } + + fn to_ron_writer(&self, writer: W) -> Result<()> + where + W: io::Write, + Self: Serialize, + { + Ok(ron::ser::to_writer_pretty( + writer, + &self, + ron::ser::PrettyConfig::new() + .indentor(" ".to_owned()) + .extensions(Extensions::all()), + )?) + } - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } + fn to_ron_string(&self) -> Result + where + Self: Serialize, + { + Ok(ron::ser::to_string_pretty( + &self, + ron::ser::PrettyConfig::new().indentor(" ".to_owned()), + )?) + } + + fn from_ron_reader(&self, mut rdr: R) -> Result + where + R: io::Read, + Self: DeserializeOwned, + { + let mut bytes = Vec::new(); + rdr.read_to_end(&mut bytes)?; + Ok(ron::de::from_bytes(&bytes)?) + } + + fn from_ron_str<'a>(s: &'a str) -> Result + where + Self: Deserialize<'a>, + { + Ok(ron::de::from_bytes(s.as_bytes())?) + } + + fn to_json_writer(&self, writer: W) -> Result<()> + where + W: io::Write, + Self: Serialize, + { + // let formatter = serde_json::ser::PrettyFormatter::with_indent(b" "); + Ok(serde_json::ser::to_writer_pretty(writer, &self)?) + } + + fn to_json_string(&self) -> Result + where + Self: Serialize, + { + Ok(serde_json::ser::to_string_pretty(&self)?) + } + + fn from_json_reader(&self, mut rdr: R) -> Result + where + R: io::Read, + Self: DeserializeOwned, + { + let mut bytes = Vec::new(); + rdr.read_to_end(&mut bytes)?; + Ok(serde_json::de::from_slice(&bytes)?) + } + + fn from_json_str<'a>(s: &'a str) -> Result + where + Self: Deserialize<'a>, + { + Ok(serde_json::de::from_slice(s.as_bytes())?) + } } diff -r eb8ed24e8a76 -r e4f8df713d55 ros/build.ros --- a/ros/build.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# -(progn ;;init forms - (ros:ensure-asdf) - #+quicklisp(ql:quickload '() :silent t) - ) - -(defpackage :ros.script.build.3891893519 - (:use :cl)) -(in-package :ros.script.build.3891893519) - -(defun main (&rest argv) - (declare (ignorable argv)) - (asdf:load-asd "cl-demo.asd") - (asdf:load-system "cl-demo") - (asdf:make :cl-demo)) -;;; vim: set ft=lisp lisp: diff -r eb8ed24e8a76 -r e4f8df713d55 ros/clean.ros --- a/ros/clean.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" ; -|# - -;; clean:;rm -rf out *.fasl;pushd rust;cargo clean;popd - -(progn ;;init forms - (ros:ensure-asdf) - #+quicklisp(ql:quickload '() :silent t) - ) - -(defpackage :ros.script.clean.3891893753 - (:use :cl)) -(in-package :ros.script.clean.3891893753) - -(defun main (&rest argv) - (declare (ignorable argv))) -;;; vim: set ft=lisp lisp: diff -r eb8ed24e8a76 -r e4f8df713d55 ros/compile.ros --- a/ros/compile.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# -(progn ;;init forms - (in-package :cl-user) - (ros:ensure-asdf) - (asdf:load-asd #P"~/dev/cl-demo/cl-demo.asd") - (asdf:load-asd #P"~/quicklisp/local-projects/cl-rocksdb/cl-rocksdb.asd") - #+quicklisp(ql:quickload '(cl-demo) :silent t)) - -;; TODO 2023-02-25: opts (system, config, user input) -(defun main (&rest argv) - (declare (ignorable argv))) diff -r eb8ed24e8a76 -r e4f8df713d55 ros/db.ros --- a/ros/db.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# -(progn ;;init forms - (ros:ensure-asdf) - #+quicklisp(ql:quickload '() :silent t)) - -(defun main (&rest argv) - (declare (ignorable argv)) - (format t "hello world")) diff -r eb8ed24e8a76 -r e4f8df713d55 ros/demo.ros --- a/ros/demo.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# -(progn ;;init forms - (ros:ensure-asdf) - #+quicklisp(ql:quickload '() :silent t)) - -(defun main (&rest argv) - (declare (ignorable argv)) - (format t "hello world")) \ No newline at end of file diff -r eb8ed24e8a76 -r e4f8df713d55 ros/docs.ros --- a/ros/docs.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# -(progn ;;init forms - (ros:ensure-asdf) - #+quicklisp(ql:quickload '() :silent t)) - -(defun main (&rest argv) - (declare (ignorable argv)) - (format t "hello world")) diff -r eb8ed24e8a76 -r e4f8df713d55 ros/pack.ros --- a/ros/pack.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# -(progn ;;init forms - (ros:ensure-asdf) - #+quicklisp(ql:quickload '() :silent t) - ) - -(defpackage :ros.script.pack.3891893796 - (:use :cl)) -(in-package :ros.script.pack.3891893796) - -(defun main (&rest argv) - (declare (ignorable argv))) -;;; vim: set ft=lisp lisp: diff -r eb8ed24e8a76 -r e4f8df713d55 ros/test.ros --- a/ros/test.ros Sun Apr 30 22:01:32 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# -(progn ;;init forms - (ros:ensure-asdf) - #+quicklisp(ql:quickload '() :silent t)) - -(defun main (&rest argv) - (declare (ignorable argv)) - (format t "hello world")) diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/build.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/build.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,20 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# +(progn ;;init forms + (ros:ensure-asdf) + #+quicklisp(ql:quickload '() :silent t) + ) + +(defpackage :ros.script.build.3891893519 + (:use :cl)) +(in-package :ros.script.build.3891893519) + +(defun main (&rest argv) + (declare (ignorable argv)) + (asdf:load-asd "cl-demo.asd") + (asdf:load-system "cl-demo") + (asdf:make :cl-demo)) +;;; vim: set ft=lisp lisp: diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/clean.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/clean.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,20 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" ; +|# + +;; clean:;rm -rf out *.fasl;pushd rust;cargo clean;popd + +(progn ;;init forms + (ros:ensure-asdf) + #+quicklisp(ql:quickload '() :silent t) + ) + +(defpackage :ros.script.clean.3891893753 + (:use :cl)) +(in-package :ros.script.clean.3891893753) + +(defun main (&rest argv) + (declare (ignorable argv))) +;;; vim: set ft=lisp lisp: diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/compile.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/compile.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,15 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# +(progn ;;init forms + (in-package :cl-user) + (ros:ensure-asdf) + (asdf:load-asd #P"~/dev/cl-demo/cl-demo.asd") + (asdf:load-asd #P"~/quicklisp/local-projects/cl-rocksdb/cl-rocksdb.asd") + #+quicklisp(ql:quickload '(cl-demo) :silent t)) + +;; TODO 2023-02-25: opts (system, config, user input) +(defun main (&rest argv) + (declare (ignorable argv))) diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/db.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/db.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,12 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# +(progn ;;init forms + (ros:ensure-asdf) + #+quicklisp(ql:quickload '() :silent t)) + +(defun main (&rest argv) + (declare (ignorable argv)) + (format t "hello world")) diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/demo.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/demo.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,12 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# +(progn ;;init forms + (ros:ensure-asdf) + #+quicklisp(ql:quickload '() :silent t)) + +(defun main (&rest argv) + (declare (ignorable argv)) + (format t "hello world")) \ No newline at end of file diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/docs.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/docs.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,12 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# +(progn ;;init forms + (ros:ensure-asdf) + #+quicklisp(ql:quickload '() :silent t)) + +(defun main (&rest argv) + (declare (ignorable argv)) + (format t "hello world")) diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/pack.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/pack.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,17 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# +(progn ;;init forms + (ros:ensure-asdf) + #+quicklisp(ql:quickload '() :silent t) + ) + +(defpackage :ros.script.pack.3891893796 + (:use :cl)) +(in-package :ros.script.pack.3891893796) + +(defun main (&rest argv) + (declare (ignorable argv))) +;;; vim: set ft=lisp lisp: diff -r eb8ed24e8a76 -r e4f8df713d55 scripts/test.ros --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test.ros Sun Apr 30 22:24:18 2023 -0400 @@ -0,0 +1,12 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# +(progn ;;init forms + (ros:ensure-asdf) + #+quicklisp(ql:quickload '() :silent t)) + +(defun main (&rest argv) + (declare (ignorable argv)) + (format t "hello world"))