Skip to content

Commit 435010c

Browse files
authored
Update documentation (#229)
* Remove the await from new/connect on doc examples * Export the conversion error types for duration and point * Remove references to removed summary methods * Fix type create -> crate * Add the getting started guide to the readme
1 parent 2b35176 commit 435010c

File tree

8 files changed

+71
-71
lines changed

8 files changed

+71
-71
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ Only the latest 5.x version is supported, following the [Neo4j Version support p
1616

1717
## API Documentation: [![Docs.rs][docs-badge]][docs-url]
1818

19+
## [Getting Started](https://neo4j.com/docs/getting-started/languages-guides/community-drivers/#neo4j-rust)
20+
21+
1922
## Example
2023

2124
```rust
2225
// concurrent queries
2326
let uri = "127.0.0.1:7687";
2427
let user = "neo4j";
2528
let pass = "neo";
26-
let graph = Graph::new(&uri, user, pass).await.unwrap();
29+
let graph = Graph::new(&uri, user, pass).unwrap();
2730
for _ in 1..=42 {
2831
let graph = graph.clone();
2932
tokio::spawn(async move {
3033
let mut result = graph.execute(
31-
query("MATCH (p:Person {name: $name}) RETURN p").param("name", "Mark")
32-
).await.unwrap();
33-
while let Ok(Some(row)) = result.next().await {
34-
let node: Node = row.get("p").unwrap();
35-
let name: String = node.get("name").unwrap();
34+
query("MATCH (p:Person {name: $name}) RETURN p").param("name", "Mark")
35+
).await.unwrap();
36+
while let Some(row) = result.next().await.unwrap() {
37+
let node: Node = row.get("p").unwrap();
38+
let name: String = node.get("name").unwrap();
3639
println!("{}", name);
3740
}
3841
});

lib/src/bolt/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ pub use request::{
1818
};
1919
pub use structs::{
2020
Bolt, BoltRef, Date, DateDuration, DateTime, DateTimeZoneId, DateTimeZoneIdRef, Duration,
21-
LegacyDateTime, LegacyDateTimeZoneId, LegacyDateTimeZoneIdRef, LocalDateTime, LocalTime, Node,
22-
NodeRef, Path, PathRef, Point2D, Point3D, Relationship, RelationshipRef, Segment, Time,
21+
DurationConversionError, LegacyDateTime, LegacyDateTimeZoneId, LegacyDateTimeZoneIdRef,
22+
LocalDateTime, LocalTime, Node, NodeRef, Path, PathRef, Point2D, Point3D, PointConversionError,
23+
Relationship, RelationshipRef, Segment, Time,
2324
};
2425
pub use summary::{Failure, Success, Summary};
2526

lib/src/bolt/structs/duration.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ impl Duration {
4141
}
4242

4343
/// Returns the duration as [`std::time::Duration`], or an error if the conversion failed.
44-
/// The error can be recovered using [`ConversionError::recover`].
45-
pub fn as_duration(self) -> Result<StdDuration, ConversionError> {
44+
/// The error can be recovered using [`DurationConversionError::recover`].
45+
pub fn as_duration(self) -> Result<StdDuration, DurationConversionError> {
4646
if self.months == 0 {
4747
calculate_duration([0, self.days, self.seconds], self.nanoseconds)
4848
} else {
49-
Err(ConversionError::EstimationRequired(DurationUnits {
49+
Err(DurationConversionError::EstimationRequired(DurationUnits {
5050
months: self.months,
5151
days: self.days,
5252
seconds: self.seconds,
@@ -56,7 +56,7 @@ impl Duration {
5656
}
5757

5858
/// Returns the duration as [`std::time::Duration`], while recovering from any error.
59-
/// See [`ConversionError::recover`] for more details.
59+
/// See [`DurationConversionError::recover`] for more details.
6060
pub fn force_as_duration(self) -> StdDuration {
6161
self.as_duration().unwrap_or_else(|e| e.deep_recover())
6262
}
@@ -90,7 +90,7 @@ pub struct DurationUnits {
9090
}
9191

9292
#[derive(Copy, Clone, Debug, PartialEq, Eq, Error)]
93-
pub enum ConversionError {
93+
pub enum DurationConversionError {
9494
/// The [`Duration`] contained a month part.
9595
///
9696
/// The length of a month varies by month-of-year.
@@ -122,28 +122,28 @@ pub enum ConversionError {
122122
Negative(StdDuration),
123123
}
124124

125-
impl ConversionError {
125+
impl DurationConversionError {
126126
/// Try to recover from the conversion error and return a `std::time::Duration` if possible.
127-
/// See [`ConversionError`] for more details.
127+
/// See [`DurationConversionError`] for more details.
128128
///
129129
/// For `EstimationRequired`, possible values after recovery are `Overflow` and `Negative`.
130130
/// For `Overflow`, possible values after recovery are `Negative`.
131131
/// Recovery will always succeed for `Negative`.
132132
///
133-
/// To recover through all possible values, use [`ConversionError::deep_recover`].
133+
/// To recover through all possible values, use [`DurationConversionError::deep_recover`].
134134
pub fn recover(self) -> Result<StdDuration, Self> {
135135
match self {
136-
ConversionError::EstimationRequired(units) => {
136+
DurationConversionError::EstimationRequired(units) => {
137137
calculate_duration([units.months, units.days, units.seconds], units.nanoseconds)
138138
}
139-
ConversionError::Overflow(sign) => {
139+
DurationConversionError::Overflow(sign) => {
140140
if sign >= 0 {
141141
Ok(StdDuration::MAX)
142142
} else {
143143
Err(Self::Negative(StdDuration::MAX))
144144
}
145145
}
146-
ConversionError::Negative(duration) => Ok(duration),
146+
DurationConversionError::Negative(duration) => Ok(duration),
147147
}
148148
}
149149

@@ -162,7 +162,7 @@ impl ConversionError {
162162
fn calculate_duration(
163163
[months, days, secs]: [i64; 3],
164164
nanos: i32,
165-
) -> Result<StdDuration, ConversionError> {
165+
) -> Result<StdDuration, DurationConversionError> {
166166
const NANOS_PER_SECOND: i32 = 1_000_000_000;
167167
const SECONDS_PER_DAY: u32 = 86400;
168168
const SECONDS_PER_MONTH: u32 = {
@@ -186,13 +186,13 @@ fn calculate_duration(
186186
};
187187

188188
let sign = seconds.signum() as i32;
189-
let seconds =
190-
u64::try_from(seconds.unsigned_abs()).map_err(|_| ConversionError::Overflow(sign))?;
189+
let seconds = u64::try_from(seconds.unsigned_abs())
190+
.map_err(|_| DurationConversionError::Overflow(sign))?;
191191

192192
let duration = StdDuration::new(seconds, subsecond);
193193

194194
if sign < 0 {
195-
Err(ConversionError::Negative(duration))
195+
Err(DurationConversionError::Negative(duration))
196196
} else {
197197
Ok(duration)
198198
}

lib/src/bolt/structs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ pub use self::datetime::{
55
DateTime, DateTimeZoneId, DateTimeZoneIdRef, LegacyDateTime, LegacyDateTimeZoneId,
66
LegacyDateTimeZoneIdRef, LocalDateTime,
77
};
8-
pub use self::duration::Duration;
8+
pub use self::duration::{Duration, DurationConversionError};
99
pub use self::node::{Node, NodeRef};
1010
pub use self::path::{Path, PathRef, Segment};
11-
pub use self::point::{Point2D, Point3D};
11+
pub use self::point::{Point2D, Point3D, PointConversionError};
1212
pub use self::rel::{Relationship, RelationshipRef};
1313
pub use self::time::{LocalTime, Time};
1414

lib/src/bolt/structs/point.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Point2D {
5252
}
5353
}
5454

55-
pub fn as_nav(&self) -> Result<nav_types::WGS84<f64>, ConversionError> {
55+
pub fn as_nav(&self) -> Result<nav_types::WGS84<f64>, PointConversionError> {
5656
self.to_point().as_nav()
5757
}
5858
}
@@ -110,13 +110,13 @@ impl Point3D {
110110
}
111111
}
112112

113-
pub fn as_nav(&self) -> Result<nav_types::WGS84<f64>, ConversionError> {
113+
pub fn as_nav(&self) -> Result<nav_types::WGS84<f64>, PointConversionError> {
114114
self.to_point().as_nav()
115115
}
116116
}
117117

118118
#[derive(Copy, Clone, Debug, PartialEq, Eq, Error)]
119-
pub enum ConversionError {
119+
pub enum PointConversionError {
120120
#[error("The coordinate system is not in {0}")]
121121
WrongSystem(Crs),
122122
#[error("The point is not defined on the {0} ellipsoid.")]
@@ -225,16 +225,16 @@ pub enum Point {
225225
}
226226

227227
impl Point {
228-
pub fn as_nav(&self) -> Result<nav_types::WGS84<f64>, ConversionError> {
228+
pub fn as_nav(&self) -> Result<nav_types::WGS84<f64>, PointConversionError> {
229229
match self {
230230
Point::Wgs842d(p) => p
231231
.to_nav()
232-
.ok_or(ConversionError::UndefinedPosition(Crs::Wgs842D)),
232+
.ok_or(PointConversionError::UndefinedPosition(Crs::Wgs842D)),
233233
Point::Wgs843d(p) => p
234234
.to_nav()
235-
.ok_or(ConversionError::UndefinedPosition(Crs::Wgs843D)),
236-
Point::Cartesian2d(_) => Err(ConversionError::WrongSystem(Crs::Wgs842D)),
237-
Point::Cartesian3d(_) => Err(ConversionError::WrongSystem(Crs::Wgs843D)),
235+
.ok_or(PointConversionError::UndefinedPosition(Crs::Wgs843D)),
236+
Point::Cartesian2d(_) => Err(PointConversionError::WrongSystem(Crs::Wgs842D)),
237+
Point::Cartesian3d(_) => Err(PointConversionError::WrongSystem(Crs::Wgs843D)),
238238
}
239239
}
240240

lib/src/lib.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//! let pass = "neo";
2323
//! let id = uuid::Uuid::new_v4().to_string();
2424
//!
25-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
25+
//! let graph = Graph::new(uri, user, pass).unwrap();
2626
//!
2727
#![doc = include_str!("../include/example.rs")]
2828
//! }
@@ -49,7 +49,7 @@
4949
//! .max_connections(10)
5050
//! .build()
5151
//! .unwrap();
52-
//! let graph = Graph::connect(config).await.unwrap();
52+
//! let graph = Graph::connect(config).unwrap();
5353
//!
5454
#![doc = include_str!("../include/configurations.rs")]
5555
//! }
@@ -68,7 +68,7 @@
6868
//! let uri = "127.0.0.1:7687";
6969
//! let user = "neo4j";
7070
//! let pass = "neo";
71-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
71+
//! let graph = Graph::new(uri, user, pass).unwrap();
7272
//!
7373
#![doc = include_str!("../include/nodes.rs")]
7474
//! }
@@ -91,7 +91,7 @@
9191
//! let uri = "127.0.0.1:7687";
9292
//! let user = "neo4j";
9393
//! let pass = "neo";
94-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
94+
//! let graph = Graph::new(uri, user, pass).unwrap();
9595
//!
9696
#![doc = include_str!("../include/transactions.rs")]
9797
//! }
@@ -117,7 +117,7 @@
117117
//! .fetch_size(1)
118118
//! .build()
119119
//! .unwrap();
120-
//! let graph = Graph::connect(config).await.unwrap();
120+
//! let graph = Graph::connect(config).unwrap();
121121
//!
122122
#![doc = include_str!("../include/streams_within_a_transaction.rs")]
123123
//! }
@@ -141,7 +141,7 @@
141141
//! let uri = "127.0.0.1:7687";
142142
//! let user = "neo4j";
143143
//! let pass = "neo";
144-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
144+
//! let graph = Graph::new(uri, user, pass).unwrap();
145145
//!
146146
#![doc = include_str!("../include/result_stream.rs")]
147147
//! }
@@ -152,11 +152,7 @@
152152
feature = "unstable-result-summary",
153153
doc = r##"### Streaming summary
154154
155-
To get access to the result summary after streaming a [`RowStream`], you can use the [`RowStream::next_or_summary`] method.
156-
Alternatively, you can use one of the [`RowStream::as_row_items`], [`RowStream::as_items`], or [`RowStream::column_to_items`]
157-
methods to get the result as a stream of [`RowItem`], whis an enum of either the row or the summary.
158-
The last option is to use one of the [`RowStream::into_stream`], [`RowStream::into_stream_as`], or [`RowStream::column_into_stream`] methods
159-
and after the stream is consumed, call [`RowStream::finish`] to get the summary.
155+
To get access to the result summary after streaming a [`RowStream`], use the [`RowStream::finish`] method.
160156
161157
```no_run
162158
use neo4rs::*;
@@ -166,7 +162,7 @@ async fn main() {
166162
let uri = "127.0.0.1:7687";
167163
let user = "neo4j";
168164
let pass = "neo";
169-
let graph = Graph::new(uri, user, pass).await.unwrap();
165+
let graph = Graph::new(uri, user, pass).unwrap();
170166
171167
"##
172168
)]
@@ -188,7 +184,7 @@ async fn main() {
188184
//! let uri = "127.0.0.1:7687";
189185
//! let user = "neo4j";
190186
//! let pass = "neo";
191-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
187+
//! let graph = Graph::new(uri, user, pass).unwrap();
192188
//!
193189
#![doc = include_str!("../include/rollback_a_transaction.rs")]
194190
//! }
@@ -213,7 +209,7 @@ async fn main() {
213209
//! let uri = "127.0.0.1:7687";
214210
//! let user = "neo4j";
215211
//! let pass = "neo";
216-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
212+
//! let graph = Graph::new(uri, user, pass).unwrap();
217213
//!
218214
#![doc = include_str!("../include/txn_vs_graph.rs")]
219215
//! }
@@ -233,7 +229,7 @@ async fn main() {
233229
//! let uri = "127.0.0.1:7687";
234230
//! let user = "neo4j";
235231
//! let pass = "neo";
236-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
232+
//! let graph = Graph::new(uri, user, pass).unwrap();
237233
//!
238234
#![doc = include_str!("../include/relationships.rs")]
239235
//! }
@@ -250,7 +246,7 @@ async fn main() {
250246
//! let uri = "127.0.0.1:7687";
251247
//! let user = "neo4j";
252248
//! let pass = "neo";
253-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
249+
//! let graph = Graph::new(uri, user, pass).unwrap();
254250
//!
255251
#![doc = include_str!("../include/unbounded_relationships.rs")]
256252
//! }
@@ -272,7 +268,7 @@ async fn main() {
272268
//! let uri = "127.0.0.1:7687";
273269
//! let user = "neo4j";
274270
//! let pass = "neo";
275-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
271+
//! let graph = Graph::new(uri, user, pass).unwrap();
276272
//!
277273
//! let qry = "
278274
//! WITH point({ x: 2.3, y: 4.5, crs: 'cartesian' }) AS p1,
@@ -295,7 +291,7 @@ async fn main() {
295291
//! let uri = "127.0.0.1:7687";
296292
//! let user = "neo4j";
297293
//! let pass = "neo";
298-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
294+
//! let graph = Graph::new(uri, user, pass).unwrap();
299295
//!
300296
#![doc = include_str!("../include/raw_bytes.rs")]
301297
//! }
@@ -313,7 +309,7 @@ async fn main() {
313309
//! let uri = "127.0.0.1:7687";
314310
//! let user = "neo4j";
315311
//! let pass = "neo";
316-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
312+
//! let graph = Graph::new(uri, user, pass).unwrap();
317313
//!
318314
#![doc = include_str!("../include/durations.rs")]
319315
//! }
@@ -333,7 +329,7 @@ async fn main() {
333329
//! let uri = "127.0.0.1:7687";
334330
//! let user = "neo4j";
335331
//! let pass = "neo";
336-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
332+
//! let graph = Graph::new(uri, user, pass).unwrap();
337333
//!
338334
#![doc = include_str!("../include/dates.rs")]
339335
//! }
@@ -362,7 +358,7 @@ async fn main() {
362358
//! let uri = "127.0.0.1:7687";
363359
//! let user = "neo4j";
364360
//! let pass = "neo";
365-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
361+
//! let graph = Graph::new(uri, user, pass).unwrap();
366362
//!
367363
#![doc = include_str!("../include/time_as_param.rs")]
368364
//! }
@@ -379,7 +375,7 @@ async fn main() {
379375
//! let uri = "127.0.0.1:7687";
380376
//! let user = "neo4j";
381377
//! let pass = "neo";
382-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
378+
//! let graph = Graph::new(uri, user, pass).unwrap();
383379
//!
384380
#![doc = include_str!("../include/parse_time_from_result.rs")]
385381
//! }
@@ -410,7 +406,7 @@ async fn main() {
410406
//! let uri = "127.0.0.1:7687";
411407
//! let user = "neo4j";
412408
//! let pass = "neo";
413-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
409+
//! let graph = Graph::new(uri, user, pass).unwrap();
414410
//!
415411
#![doc = include_str!("../include/datetime_as_param.rs")]
416412
//! }
@@ -426,7 +422,7 @@ async fn main() {
426422
//! let uri = "127.0.0.1:7687";
427423
//! let user = "neo4j";
428424
//! let pass = "neo";
429-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
425+
//! let graph = Graph::new(uri, user, pass).unwrap();
430426
//!
431427
#![doc = include_str!("../include/parse_datetime_from_result.rs")]
432428
//! }
@@ -445,7 +441,7 @@ async fn main() {
445441
//! let uri = "127.0.0.1:7687";
446442
//! let user = "neo4j";
447443
//! let pass = "neo";
448-
//! let graph = Graph::new(uri, user, pass).await.unwrap();
444+
//! let graph = Graph::new(uri, user, pass).unwrap();
449445
//!
450446
#![doc = include_str!("../include/path.rs")]
451447
//! }

0 commit comments

Comments
 (0)