pub struct NodeNetworkItem {
pub connections: NodeNetwork,
/* private fields */
}
Expand description
§NodeNetworkItem
A NodeNetworkItem define the string representation of an FBP node.
A JSON string can be created from this class to be used to create a node.
§Example
// Assuming FBP Nodes NodeA and NodeB and neither of these nodes
// requires configurations.
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;
use async_trait::async_trait;
use std::sync::atomic::{Ordering, AtomicBool};
use futures::future::*;
use std::ops::{Deref};
use fbp::fbp_node_network::*;
use fbp::fbp_node_context::*;
use fbp::fbp_node_trait::*;
use fbp::fbp_iidmessage::*;
use fbp::fbp_node_error::*;
#[derive(Clone, Serialize, Deserialize)]
pub struct NodeA {
data: Box<FBPNodeContext>,
}
impl NodeA {
#[allow(dead_code)]
pub fn new() -> Self {
let result = NodeA {
data: Box::new(FBPNodeContext::new("NodeA")),
};
result.node_data().set_node_is_configured(true);
result.clone().start();
result
}
}
#[async_trait]
impl FBPNodeTrait for NodeA {
fn node_data_clone(&self) -> FBPNodeContext {
self.data.deref().clone()
}
fn node_data(&self) -> &FBPNodeContext { &self.data }
fn node_data_mut(&mut self) -> &mut FBPNodeContext { &mut self.data }
fn process_message(&mut self, msg: IIDMessage) -> std::result::Result<IIDMessage, NodeError> {
Ok(msg.clone())
}
}
#[derive(Clone, Serialize, Deserialize)]
pub struct NodeB {
data: Box<FBPNodeContext>,
}
impl NodeB {
#[allow(dead_code)]
pub fn new() -> Self {
let result = NodeB {
data: Box::new(FBPNodeContext::new("NodeB")),
};
result.node_data().set_node_is_configured(true);
result.clone().start();
result
}
}
#[async_trait]
impl FBPNodeTrait for NodeB {
fn node_data_clone(&self) -> FBPNodeContext {
self.data.deref().clone()
}
fn node_data(&self) -> &FBPNodeContext { &self.data }
fn node_data_mut(&mut self) -> &mut FBPNodeContext { &mut self.data }
fn process_message(&mut self, msg: IIDMessage) -> std::result::Result<IIDMessage, NodeError> {
Ok(msg.clone())
}
}
let mut nni = NodeNetworkItem::new("NodeA".to_string());
nni.add_connection(&"NodeB".to_string(), None);
let json_string = serde_json::to_string(&nni).unwrap();
// Subsequently, the NodeNetworkItem can be 'reconstructed' as follows:
let a_nni: NodeNetworkItem = serde_json::from_str(json_string.as_str()).unwrap();
// With a NodeNetworkItem, the node can be created as follows:
let net_config_op: Option<NetworkConfiguration> = a_nni.create_node();
// A NetworkConfiguration is a struct which contains all of the ndoes that
// were constructed. Please the see the documentation for the NetworkConfiguration
// struct
Fields§
§connections: NodeNetwork
Implementations§
Source§impl NodeNetworkItem
impl NodeNetworkItem
pub fn new(node_name: String) -> Self
pub fn name(&self) -> String
pub fn add_configuration(&mut self, config_str: String)
pub fn add_connection(&mut self, node_name: &String, key: Option<String>)
pub fn add_node_connection( &mut self, node: NodeNetworkItem, key: Option<String>, )
pub fn create_node(&self) -> Option<NetworkConfiguration>
Trait Implementations§
Source§impl Clone for NodeNetworkItem
impl Clone for NodeNetworkItem
Source§fn clone(&self) -> NodeNetworkItem
fn clone(&self) -> NodeNetworkItem
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for NodeNetworkItem
impl Debug for NodeNetworkItem
Source§impl<'de> Deserialize<'de> for NodeNetworkItem
impl<'de> Deserialize<'de> for NodeNetworkItem
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for NodeNetworkItem
impl PartialEq for NodeNetworkItem
Source§impl Serialize for NodeNetworkItem
impl Serialize for NodeNetworkItem
impl Eq for NodeNetworkItem
Auto Trait Implementations§
impl Freeze for NodeNetworkItem
impl RefUnwindSafe for NodeNetworkItem
impl Send for NodeNetworkItem
impl Sync for NodeNetworkItem
impl Unpin for NodeNetworkItem
impl UnwindSafe for NodeNetworkItem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more