Skip to content

Commit

Permalink
Rust: update everest-framework (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Dima Dorezyuk <[email protected]>
Signed-off-by: Evgeny Petrov <[email protected]>
  • Loading branch information
Dima Dorezyuk authored and golovasteek committed Jan 27, 2024
1 parent c1df782 commit fa1d1aa
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions modules/rust_examples/Cargo.lock

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

4 changes: 2 additions & 2 deletions modules/rust_examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ members = [
]

[workspace.dependencies]
everestrs = { git = "https://github.com/qwello/everest-framework.git", rev = "64411bbc78b94e9d1d28f421bf0f3a8adb0dca92" }
everestrs-build = { git = "https://github.com/qwello/everest-framework.git", rev = "64411bbc78b94e9d1d28f421bf0f3a8adb0dca92" }
everestrs = { git = "https://github.com/qwello/everest-framework.git", rev = "06983df646695303017137d00eea9f63b808fd71" }
everestrs-build = { git = "https://github.com/qwello/everest-framework.git", rev = "06983df646695303017137d00eea9f63b808fd71" }
35 changes: 16 additions & 19 deletions modules/rust_examples/RsExample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
include!(concat!(env!("OUT_DIR"), "/generated.rs"));

use generated::{
get_config, ExampleServiceSubscriber, KvsClientSubscriber, KvsServiceSubscriber, Module,
ModulePublisher, OnReadySubscriber,
get_config, Context, ExampleServiceSubscriber, KvsClientSubscriber, KvsServiceSubscriber,
Module, ModulePublisher, OnReadySubscriber,
};
use std::sync::Arc;
use std::{thread, time};
Expand All @@ -15,47 +15,44 @@ pub struct OneClass {}
impl KvsServiceSubscriber for OneClass {
fn store(
&self,
pub_impl: &ModulePublisher,
context: &Context,
key: String,
value: serde_json::Value,
) -> ::everestrs::Result<()> {
pub_impl.their_store.store(key, value)
context.publisher.their_store.store(key, value)
}

fn load(
&self,
pub_impl: &ModulePublisher,
key: String,
) -> ::everestrs::Result<serde_json::Value> {
pub_impl.their_store.load(key)
fn load(&self, context: &Context, key: String) -> ::everestrs::Result<serde_json::Value> {
context.publisher.their_store.load(key)
}

fn delete(&self, pub_impl: &ModulePublisher, key: String) -> ::everestrs::Result<()> {
pub_impl.their_store.delete(key)
fn delete(&self, context: &Context, key: String) -> ::everestrs::Result<()> {
context.publisher.their_store.delete(key)
}

fn exists(&self, pub_impl: &ModulePublisher, key: String) -> ::everestrs::Result<bool> {
pub_impl.their_store.exists(key)
fn exists(&self, context: &Context, key: String) -> ::everestrs::Result<bool> {
context.publisher.their_store.exists(key)
}
}

impl ExampleServiceSubscriber for OneClass {
fn uses_something(&self, pub_impl: &ModulePublisher, key: String) -> ::everestrs::Result<bool> {
if !pub_impl.their_store.exists(key.clone())? {
fn uses_something(&self, context: &Context, key: String) -> ::everestrs::Result<bool> {
if !context.publisher.their_store.exists(key.clone())? {
println!("IT SHOULD NOT AND DOES NOT EXIST");
}

let test_array = vec![1, 2, 3];
pub_impl
context
.publisher
.their_store
.store(key.clone(), test_array.clone().into())?;

let exi = pub_impl.their_store.exists(key.clone())?;
let exi = context.publisher.their_store.exists(key.clone())?;
if exi {
println!("IT ACTUALLY EXISTS");
}

let ret: Vec<i32> = serde_json::from_value(pub_impl.their_store.load(key)?)
let ret: Vec<i32> = serde_json::from_value(context.publisher.their_store.load(key)?)
.expect("Wanted an array as return value");

println!("loaded array: {ret:?}, original array: {test_array:?}");
Expand Down
9 changes: 5 additions & 4 deletions modules/rust_examples/RsExampleUser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex};
use std::{thread, time};

use generated::{
ExampleClientSubscriber, ExampleUserServiceSubscriber, Module, ModulePublisher,
Context, ExampleClientSubscriber, ExampleUserServiceSubscriber, Module, ModulePublisher,
OnReadySubscriber,
};

Expand All @@ -26,16 +26,17 @@ impl ExampleClient {
}

impl ExampleClientSubscriber for ExampleClient {
fn on_max_current(&self, publishers: &ModulePublisher, value: f64) {
fn on_max_current(&self, context: &Context, value: f64) {
println!("Received the value {value}");
let _ = publishers
let _ = context
.publisher
.their_example
.uses_something("hello_there".to_string());
*self.max_current.lock().unwrap() = Some(value);

// Example where we start a thread with the publisher. The cloning is
// only done if the user wants to offload the publisher into a thread.
let clone = publishers.clone();
let clone = context.publisher.clone();
*self.thread.lock().unwrap() = Some(thread::spawn(move || {
let _ = clone.another_example.uses_something("foo".to_string());
}))
Expand Down
6 changes: 3 additions & 3 deletions third-party/bazel/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def everest_core_repos():
maybe(
http_archive,
name = "everest-framework",
url = "https://github.com/qwello/everest-framework/archive/64411bbc78b94e9d1d28f421bf0f3a8adb0dca92.tar.gz",
strip_prefix = "everest-framework-64411bbc78b94e9d1d28f421bf0f3a8adb0dca92",
)
url = "https://github.com/qwello/everest-framework/archive/06983df646695303017137d00eea9f63b808fd71.tar.gz",
strip_prefix = "everest-framework-06983df646695303017137d00eea9f63b808fd71",
)

0 comments on commit fa1d1aa

Please sign in to comment.