Skip to content

Commit

Permalink
fix book examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pchampin committed Sep 15, 2023
1 parent d955bc1 commit 3315774
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions book/src/01_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ sophia = "0.8.0-alpha.1"
```


Add these lines of code and run the programm.
```rust
Add these lines of code and run the program.
```rust,noplayground
# extern crate sophia;
use sophia::api::prelude::*;
use sophia::api::ns::Namespace;
use sophia::inmem::graph::LightGraph;
Expand Down
13 changes: 9 additions & 4 deletions book/src/90_changes_since_07.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Sophia has been heavily refactored between version 0.7 and 0.8. This refactoring

## The benefit of GATs

The main benefit of GATs is to get rid of [odd patterns](https://docs.rs/sophia/0.7.2/sophia/triple/streaming_mode/index.html) that were introduced in Sophia in order to keep it genetic enough to support multiple implementation choices. The drawback of this approach was that implementing Sophia's traits (especially `Graph` and `Dataset`) could be cumbersome.
The main benefit of GATs is to get rid of [odd patterns](https://docs.rs/sophia/0.7.2/sophia/triple/streaming_mode/index.html) that were introduced in Sophia in order to keep it generic enough to support multiple implementation choices. The drawback of this approach was that implementing Sophia's traits (especially `Graph` and `Dataset`) could be cumbersome.

As an example, the [`Graph`](https://docs.rs/sophia/0.7.2/sophia/graph/trait.Graph.html) trait used to be
```rust,noplayground
```rust,noplayground,ignore
pub trait Graph {
type Triple: TripleStreamingMode;
// ...
Expand All @@ -17,7 +17,7 @@ pub trait Graph {
Given a type `MyGraph` implementing that trait, the actual type of triples yielded by [`MyGraph::triples`](https://docs.rs/sophia/0.7.2/sophia/graph/trait.Graph.html#tymethod.triples) could not be immediately determined, and was [quite intricate](https://docs.rs/sophia/latest/sophia/graph/type.GTriple.html). This could be inconvenient for some users of `MyGraph`, and was usually cumbersome for the implementer.

Compare to the new definition of the `Graph` trait:
```rust,noplayground
```rust,noplayground,ignore
pub trait Graph {
type Triple<'x>: Triple where Self: 'x;
// ...
Expand Down Expand Up @@ -68,13 +68,18 @@ or [`triples_with_po`](https://docs.rs/sophia_api/0.7.2/sophia_api/graph/trait.G

All these methods have disappeared in favor of `triples_matching`,
so that instead of:
```rust,noplayground
```rust,noplayground,ignore
for t in g.triples_with_s(mys) {
// ...
}
```
one should now write
```rust,noplayground
# extern crate sophia;
# use sophia::api::graph::Graph;
# use sophia::api::term::matcher::Any;
# let g: Vec<[i32; 3]> = vec![]; // dummy graph type
# let mys = 42;
for t in g.triples_matching([mys], Any, Any) {
// ...
}
Expand Down

0 comments on commit 3315774

Please sign in to comment.