This library aims to provide a simple interface for developing event-sourced occasionally-connected-computing experiences.
A port of libocc-ts (the TypeScript version of libocc)
See the docs at https://docs.rs/libocc/
See the TODO section below.
```Rust fn testprojector() { // Create a new book let mut mybook = book::Book { uuid: Uuid::newv4(), somenumber: 42, author: person::Person { uuid: Uuid::newv4(), firstname: String::from("Alex"), last_name: String::from("Example"), }, };
// Create a new projector of type `Book`
let mut books = crate::Projector::<book::Book>::new();
// So far, the projector is empty.
println!("Empty projector:");
println!("{:?}\n", books.get_projection());
assert_eq!(books.get_projection().len(), 0);
// Add a new book
books.push(crate::Event::create(my_book.clone())).unwrap();
// The projector now contains the new book in its initial state
println!("Projector after creating new book:");
println!("{:?}\n", books.get_projection());
assert_eq!(books.get_projection().get(0).unwrap().some_number, 42);
// This timestamp will be used in the future to get a previous state of the book
let timestamp: crate::Timestamp = Utc::now();
// Some time later ... (simulated delay)
thread::sleep(time::Duration::from_millis(1));
// Modify the book and save it in the projector
my_book.some_number = 123;
books.push(crate::Event::update(my_book.clone())).unwrap();
// The projector now contains the new version of the book
println!("Projector after updating the book:");
println!("{:?}\n", books.get_projection());
assert_eq!(books.get_projection().get(0).unwrap().some_number, 123);
// We can still retrieve the old version of the book (using the timestamp)
println!("Projector before the book was updated:");
println!("{:?}\n", books.project_at(×tamp));
assert_eq!(
books
.project_at(×tamp)
.unwrap()
.get(0)
.unwrap()
.some_number,
42
);
} ```
Copyright (c) 2020-2021 Bernd-L. All rights reserved.
libocc-rs is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
libocc-rs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with libocc-rs. If not, see https://www.gnu.org/licenses/.
This project (including its source code and its documentation) is released under the terms of the GNU Affero General Public License.