pub struct Sodg { /* private fields */ }
Expand description
This struct represents a Surging Object DiGraph (SODG). You add vertices to it, bind them one to one with edges, put data into some of them, and read data back:
use sodg::Sodg;
let mut sodg = Sodg::empty();
sodg.add(0).unwrap();
sodg.add(1).unwrap();
sodg.bind(0, 1, "a").unwrap();
sodg.add(2).unwrap();
sodg.bind(1, 2, "b").unwrap();
assert_eq!(2, sodg.find(0, "a.b").unwrap());
This package is used in reo project, as a memory model for objects and dependencies between them.
Implementations
sourceimpl Sodg
impl Sodg
sourcepub fn add(&mut self, v1: u32) -> Result<()>
pub fn add(&mut self, v1: u32) -> Result<()>
Add a new vertex v1
to the Sodg:
use sodg::Sodg;
let mut sodg = Sodg::empty();
sodg.add(0).unwrap();
sodg.add(42).unwrap();
sodg.bind(0, 42, "hello").unwrap();
sourcepub fn bind(&mut self, v1: u32, v2: u32, a: &str) -> Result<()>
pub fn bind(&mut self, v1: u32, v2: u32, a: &str) -> Result<()>
Makes an edge e1
from vertex v1
to vertex v2
and puts a
label on it. If the
label is not equal to "ρ"
, makes two backward edges from v2
to v1
and label them as "ρ"
an "𝜎"
.
use sodg::Sodg;
let mut sodg = Sodg::empty();
sodg.add(0).unwrap();
sodg.add(42).unwrap();
sodg.bind(0, 42, "forward").unwrap();
sodg.bind(42, 0, "backward").unwrap();
sourcepub fn put(&mut self, v: u32, d: Hex) -> Result<()>
pub fn put(&mut self, v: u32, d: Hex) -> Result<()>
Set vertex data.
use sodg::Hex;
use sodg::Sodg;
let mut sodg = Sodg::empty();
sodg.add(42).unwrap();
sodg.put(42, Hex::from_str("hello, world!")).unwrap();
sourcepub fn data(&self, v: u32) -> Result<Hex>
pub fn data(&self, v: u32) -> Result<Hex>
Read vertex data.
use sodg::Hex;
use sodg::Sodg;
let mut sodg = Sodg::empty();
sodg.add(42).unwrap();
let data = Hex::from_str("hello, world!");
sodg.put(42, data.clone()).unwrap();
assert_eq!(data, sodg.data(42).unwrap());
sourcepub fn kid(&self, v: u32, a: &str) -> Option<u32>
pub fn kid(&self, v: u32, a: &str) -> Option<u32>
Find a kid of a vertex, by its edge name.
use sodg::Sodg;
let mut sodg = Sodg::empty();
sodg.add(0).unwrap();
sodg.add(42).unwrap();
sodg.bind(0, 42, "k").unwrap();
assert_eq!(42, sodg.kid(0, "k").unwrap());
assert!(sodg.kid(0, "another").is_none());
sourcepub fn find(&self, v1: u32, loc: &str) -> Result<u32>
pub fn find(&self, v1: u32, loc: &str) -> Result<u32>
Find a vertex in the Sodg by its locator.
use sodg::Sodg;
let mut sodg = Sodg::empty();
sodg.add(0).unwrap();
sodg.add(1).unwrap();
sodg.bind(0, 1, "a").unwrap();
sodg.add(2).unwrap();
sodg.bind(1, 2, "b").unwrap();
assert_eq!(2, sodg.find(0, "a.b").unwrap());
sourceimpl Sodg
impl Sodg
sourceimpl Sodg
impl Sodg
sourcepub fn to_xml(&self) -> Result<String>
pub fn to_xml(&self) -> Result<String>
Make XML graph. For example, for this code:
use sodg::Hex;
use sodg::Sodg;
let mut g = Sodg::empty();
g.add(0).unwrap();
g.put(0, Hex::from_str("hello")).unwrap();
g.add(1).unwrap();
g.bind(0, 1, "foo").unwrap();
g.bind(0, 1, "bar").unwrap();
let xml = g.to_xml().unwrap();
println!("{}", xml);
The printout will look like this:
<?xml version="1.1" encoding="UTF-8"?>
<sodg>
<v id="0">
<e a="foo" to="1" />
<e a="bar" to="1" />
<data>68 65 6C 6C 6F</data>
</v>
<v id="1" />
</sodg>
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Sodg
impl<'de> Deserialize<'de> for Sodg
sourcefn 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
Auto Trait Implementations
impl RefUnwindSafe for Sodg
impl Send for Sodg
impl Sync for Sodg
impl Unpin for Sodg
impl UnwindSafe for Sodg
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more