Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "scaffolding-core"
version = "0.8.0"
version = "1.0.0"
authors = ["dsietz <davidsietz@yahoo.com>"]
categories = ["development-tools"]
description = "A software development kit that provides the scaffolding for building applications and services."
categories = ["data-structures","development-tools","rust-patterns"]
description = "A software development kit that provides the scaffolding for building applications and services using OOP."
documentation = "https://docs.rs/scaffolding-core"
edition = "2021"
exclude = [
Expand Down Expand Up @@ -31,7 +31,7 @@ person = []
[dependencies]
chrono = "0.4.35"
regex = "1.10.5"
scaffolding-macros = {path = "./scaffolding-macros", version = "0.8.0"}
scaffolding-macros = {path = "./scaffolding-macros", version = "1.0.0"}
serde = "1.0.197"
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ For software development teams who appreciate a kick-start to their object orien
---

## What's New
| :warning: Please Note! |
| ----------------------------------------------------------------------------- |
| This crate is in an `beta` release phase and is only intended as experimental.|
| :star: General Release |
| ------------------------------------------------------------------------------ |
| This crate is in `general release` and is treated as the initial release. |

**0.8.0**
**1.0.0**
+ [Bug - trait Scaffolding is not object safe](https://github.com/dsietz/scaffolding-core/issues/33)

## Usage
Expand Down Expand Up @@ -103,6 +103,41 @@ assert_eq!(entity.b, "You said it is true");
/* custom behavior */
assert_eq!(entity.my_func(), "my function");
```
__Serializing__
```rust
let json_string = entity.serialize();
println!("{}", json_string);
```
__Deserializing__
```rust
let json = r#"{
"id":"b4d6c6db-7468-400a-8536-a5e83b1f2bdc",
"created_dtm":1711802687,
"modified_dtm":1711802687,
"inactive_dtm":1719578687,
"expired_dtm":1806410687,
"activity":[
{
"created_dtm":1711802687,
"action":"updated",
"description":"The object has been updated"
},
{
"created_dtm":1711802687,
"action":"updated",
"description":"The object has been updated"
},
{
"created_dtm":1711802687,
"action":"cancelled",
"description":"The object has been cancelled"
}
]
}"#;
let entity = MyEntity::deserialized(json.as_bytes()).unwrap();

assert_eq!(entity.get_activity("cancelled".to_string()).len(), 1);
```
---
There are additional Scaffolding features that can be applied.

Expand Down
2 changes: 1 addition & 1 deletion scaffolding-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scaffolding-macros"
version = "0.8.0"
version = "1.0.0"
authors = ["dsietz <davidsietz@yahoo.com>"]
edition = "2021"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions scaffolding-macros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
| ----------------------------------------------------------------------------- |
| This crate is published as a dependency for the [scaffolding-core](https://crates.io/crates/scaffolding-core) crate. |

**0.5.0**
+ [Provide the ability to manage entities](https://github.com/dsietz/scaffolding-core/issues/32)
**1.0.0**
+ [Bug - trait Scaffolding is not object safe](https://github.com/dsietz/scaffolding-core/issues/33)
1 change: 0 additions & 1 deletion scaffolding-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ fn impl_scaffolding(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
let gen = quote! {
impl Scaffolding for #name {
type Item = #name;
fn get_activity(&self, name: String) -> Vec<ActivityItem>{
self.activity.iter().filter(|a| a.action == name).cloned().collect()
}
Expand Down
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
//! // expires in 3 years
//! assert_eq!(entity.expired_dtm, defaults::add_years(defaults::now(), 3));
//!
//! /* serialization */
//! let json_string = entity.serialize();
//! println!("{}", json_string);
//!
//! /* use the activity log functionality */
//! // (1) Log an activity
//! entity.log_activity("cancelled".to_string(), "The customer has cancelled their service".to_string());
Expand Down Expand Up @@ -903,7 +907,6 @@ impl PhoneNumber {

/// The core behavior of a Scaffolding object
pub trait Scaffolding {
type Item;
/// This function adds a ActivityItem to the activity log
///
/// #Example
Expand Down Expand Up @@ -1007,14 +1010,17 @@ pub trait Scaffolding {
/// }
/// ]
/// }"#;
/// let deserialized = MyEntity::deserialized::<MyEntity>(json.as_bytes()).unwrap();
/// let deserialized = MyEntity::deserialized(json.as_bytes()).unwrap();
///
/// assert_eq!(deserialized.id, "b4d6c6db-7468-400a-8536-a5e83b1f2bdc");
/// assert_eq!(deserialized.activity.len(), 3);
///
/// ```
fn deserialized<Item: DeserializeOwned>(serialized: &[u8]) -> Result<Item, DeserializeError> {
match serde_json::from_slice::<Item>(&serialized) {
fn deserialized(serialized: &[u8]) -> Result<Self, DeserializeError>
where
Self: DeserializeOwned,
{
match serde_json::from_slice::<Self>(&serialized) {
Ok(item) => Ok(item),
Err(err) => {
println!("{}", err);
Expand Down
2 changes: 1 addition & 1 deletion tests/all_features_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod tests {
let mut json =
fs::read_to_string("./tests/entity.json").expect("Cannot read the entity.json file");
json.retain(|c| !c.is_whitespace());
let mut entity = MyEntity::deserialized::<MyEntity>(json.as_bytes()).unwrap();
let mut entity = MyEntity::deserialized(json.as_bytes()).unwrap();

assert_eq!(entity.my_func(), "The answer is true".to_string());
assert_eq!(entity.get_activity("updated".to_string()).len(), 2);
Expand Down
2 changes: 1 addition & 1 deletion tests/core_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod tests {
}
]
}"#;
let deserialized = MyEntity::deserialized::<MyEntity>(json.as_bytes()).unwrap();
let deserialized = MyEntity::deserialized(json.as_bytes()).unwrap();
assert_eq!(deserialized.id, "b4d6c6db-7468-400a-8536-a5e83b1f2bdc");
assert_eq!(deserialized.activity.len(), 3);
assert_eq!(deserialized.b, true);
Expand Down