Skip to content

Commit a204a7b

Browse files
committed
codewide: migrate doctests to new deser API
1 parent 9a092f9 commit a204a7b

File tree

4 files changed

+169
-161
lines changed

4 files changed

+169
-161
lines changed

scylla/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
//! `Session` is created by specifying a few known nodes and connecting to them:
1818
//!
1919
//! ```rust,no_run
20-
//! use scylla::{LegacySession, SessionBuilder};
20+
//! use scylla::{Session, SessionBuilder};
2121
//! use std::error::Error;
2222
//!
2323
//! #[tokio::main]
2424
//! async fn main() -> Result<(), Box<dyn Error>> {
25-
//! let session: LegacySession = SessionBuilder::new()
25+
//! let session: Session = SessionBuilder::new()
2626
//! .known_node("127.0.0.1:9042")
2727
//! .known_node("1.2.3.4:9876")
28-
//! .build_legacy()
28+
//! .build()
2929
//! .await?;
3030
//!
3131
//! Ok(())
@@ -50,9 +50,9 @@
5050
//!
5151
//! The easiest way to specify bound values in a query is using a tuple:
5252
//! ```rust
53-
//! # use scylla::LegacySession;
53+
//! # use scylla::Session;
5454
//! # use std::error::Error;
55-
//! # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
55+
//! # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
5656
//! // Insert an int and text into the table
5757
//! session
5858
//! .query_unpaged(
@@ -69,24 +69,24 @@
6969
//! The easiest way to read rows returned by a query is to cast each row to a tuple of values:
7070
//!
7171
//! ```rust
72-
//! # use scylla::LegacySession;
72+
//! # use scylla::Session;
7373
//! # use std::error::Error;
74-
//! # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
75-
//! use scylla::IntoTypedRows;
74+
//! # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
7675
//!
7776
//! // Read rows containing an int and text
7877
//! // Keep in mind that all results come in one response (no paging is done!),
7978
//! // so the memory footprint and latency may be huge!
8079
//! // To prevent that, use `Session::query_iter` or `Session::query_single_page`.
81-
//! let rows_opt = session
80+
//! let query_rows = session
8281
//! .query_unpaged("SELECT a, b FROM ks.tab", &[])
8382
//! .await?
84-
//! .rows;
83+
//! .into_rows_result()?;
84+
//!
8585
//!
86-
//! if let Some(rows) = rows_opt {
87-
//! for row in rows.into_typed::<(i32, String)>() {
86+
//! if let Some(rows) = query_rows {
87+
//! for row in rows.rows()? {
8888
//! // Parse row as int and text \
89-
//! let (int_val, text_val): (i32, String) = row?;
89+
//! let (int_val, text_val): (i32, &str) = row?;
9090
//! }
9191
//! }
9292
//! # Ok(())

scylla/src/transport/execution_profile.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! # extern crate scylla;
1717
//! # use std::error::Error;
1818
//! # async fn check_only_compiles() -> Result<(), Box<dyn Error>> {
19-
//! use scylla::{LegacySession, SessionBuilder};
19+
//! use scylla::{Session, SessionBuilder};
2020
//! use scylla::statement::Consistency;
2121
//! use scylla::transport::ExecutionProfile;
2222
//!
@@ -27,10 +27,10 @@
2727
//!
2828
//! let handle = profile.into_handle();
2929
//!
30-
//! let session: LegacySession = SessionBuilder::new()
30+
//! let session: Session = SessionBuilder::new()
3131
//! .known_node("127.0.0.1:9042")
3232
//! .default_execution_profile_handle(handle)
33-
//! .build_legacy()
33+
//! .build()
3434
//! .await?;
3535
//! # Ok(())
3636
//! # }
@@ -109,7 +109,7 @@
109109
//! # extern crate scylla;
110110
//! # use std::error::Error;
111111
//! # async fn check_only_compiles() -> Result<(), Box<dyn Error>> {
112-
//! use scylla::{LegacySession, SessionBuilder};
112+
//! use scylla::{Session, SessionBuilder};
113113
//! use scylla::query::Query;
114114
//! use scylla::statement::Consistency;
115115
//! use scylla::transport::ExecutionProfile;
@@ -125,10 +125,10 @@
125125
//! let mut handle1 = profile1.clone().into_handle();
126126
//! let mut handle2 = profile2.clone().into_handle();
127127
//!
128-
//! let session: LegacySession = SessionBuilder::new()
128+
//! let session: Session = SessionBuilder::new()
129129
//! .known_node("127.0.0.1:9042")
130130
//! .default_execution_profile_handle(handle1.clone())
131-
//! .build_legacy()
131+
//! .build()
132132
//! .await?;
133133
//!
134134
//! let mut query1 = Query::from("SELECT * FROM ks.table");

scylla/src/transport/session.rs

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ impl GenericSession<CurrentDeserializationApi> {
486486
///
487487
/// # Examples
488488
/// ```rust
489-
/// # use scylla::LegacySession;
489+
/// # use scylla::Session;
490490
/// # use std::error::Error;
491-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
491+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
492492
/// // Insert an int and text into a table.
493493
/// session
494494
/// .query_unpaged(
@@ -500,24 +500,24 @@ impl GenericSession<CurrentDeserializationApi> {
500500
/// # }
501501
/// ```
502502
/// ```rust
503-
/// # use scylla::LegacySession;
503+
/// # use scylla::Session;
504504
/// # use std::error::Error;
505-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
505+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
506506
/// use scylla::IntoTypedRows;
507507
///
508508
/// // Read rows containing an int and text.
509509
/// // Keep in mind that all results come in one response (no paging is done!),
510510
/// // so the memory footprint and latency may be huge!
511511
/// // To prevent that, use `Session::query_iter` or `Session::query_single_page`.
512-
/// let rows_opt = session
513-
/// .query_unpaged("SELECT a, b FROM ks.tab", &[])
512+
/// let query_rows = session
513+
/// .query_unpaged("SELECT a, b FROM ks.tab", &[])
514514
/// .await?
515-
/// .rows;
515+
/// .into_rows_result()?;
516516
///
517-
/// if let Some(rows) = rows_opt {
518-
/// for row in rows.into_typed::<(i32, String)>() {
519-
/// // Parse row as int and text \
520-
/// let (int_val, text_val): (i32, String) = row?;
517+
/// if let Some(rows) = query_rows {
518+
/// for row in rows.rows()? {
519+
/// // Parse row as int and text.
520+
/// let (int_val, text_val): (i32, &str) = row?;
521521
/// }
522522
/// }
523523
/// # Ok(())
@@ -546,9 +546,9 @@ impl GenericSession<CurrentDeserializationApi> {
546546
/// # Example
547547
///
548548
/// ```rust
549-
/// # use scylla::LegacySession;
549+
/// # use scylla::Session;
550550
/// # use std::error::Error;
551-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
551+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
552552
/// use std::ops::ControlFlow;
553553
/// use scylla::statement::PagingState;
554554
///
@@ -560,7 +560,11 @@ impl GenericSession<CurrentDeserializationApi> {
560560
/// .await?;
561561
///
562562
/// // Do something with a single page of results.
563-
/// for row in res.rows_typed::<(i32, String)>()? {
563+
/// for row in res
564+
/// .into_rows_result()?
565+
/// .unwrap()
566+
/// .rows::<(i32, &str)>()?
567+
/// {
564568
/// let (a, b) = row?;
565569
/// }
566570
///
@@ -608,16 +612,16 @@ impl GenericSession<CurrentDeserializationApi> {
608612
/// # Example
609613
///
610614
/// ```rust
611-
/// # use scylla::LegacySession;
615+
/// # use scylla::Session;
612616
/// # use std::error::Error;
613-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
617+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
614618
/// use scylla::IntoTypedRows;
615619
/// use futures::stream::StreamExt;
616620
///
617621
/// let mut rows_stream = session
618622
/// .query_iter("SELECT a, b FROM ks.t", &[])
619623
/// .await?
620-
/// .into_typed::<(i32, i32)>();
624+
/// .rows_stream::<(i32, i32)>()?;
621625
///
622626
/// while let Some(next_row_res) = rows_stream.next().await {
623627
/// let (a, b): (i32, i32) = next_row_res?;
@@ -661,9 +665,9 @@ impl GenericSession<CurrentDeserializationApi> {
661665
///
662666
/// # Example
663667
/// ```rust
664-
/// # use scylla::LegacySession;
668+
/// # use scylla::Session;
665669
/// # use std::error::Error;
666-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
670+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
667671
/// use scylla::prepared_statement::PreparedStatement;
668672
///
669673
/// // Prepare the query for later execution
@@ -697,9 +701,9 @@ impl GenericSession<CurrentDeserializationApi> {
697701
/// # Example
698702
///
699703
/// ```rust
700-
/// # use scylla::LegacySession;
704+
/// # use scylla::Session;
701705
/// # use std::error::Error;
702-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
706+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
703707
/// use std::ops::ControlFlow;
704708
/// use scylla::query::Query;
705709
/// use scylla::statement::{PagingState, PagingStateResponse};
@@ -719,7 +723,11 @@ impl GenericSession<CurrentDeserializationApi> {
719723
/// .await?;
720724
///
721725
/// // Do something with a single page of results.
722-
/// for row in res.rows_typed::<(i32, String)>()? {
726+
/// for row in res
727+
/// .into_rows_result()?
728+
/// .unwrap()
729+
/// .rows::<(i32, &str)>()?
730+
/// {
723731
/// let (a, b) = row?;
724732
/// }
725733
///
@@ -763,12 +771,12 @@ impl GenericSession<CurrentDeserializationApi> {
763771
/// # Example
764772
///
765773
/// ```rust
766-
/// # use scylla::LegacySession;
774+
/// # use scylla::Session;
775+
/// # use futures::StreamExt as _;
767776
/// # use std::error::Error;
768-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
777+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
769778
/// use scylla::prepared_statement::PreparedStatement;
770779
/// use scylla::IntoTypedRows;
771-
/// use futures::stream::StreamExt;
772780
///
773781
/// // Prepare the query for later execution
774782
/// let prepared: PreparedStatement = session
@@ -779,7 +787,7 @@ impl GenericSession<CurrentDeserializationApi> {
779787
/// let mut rows_stream = session
780788
/// .execute_iter(prepared, &[])
781789
/// .await?
782-
/// .into_typed::<(i32, i32)>();
790+
/// .rows_stream::<(i32, i32)>()?;
783791
///
784792
/// while let Some(next_row_res) = rows_stream.next().await {
785793
/// let (a, b): (i32, i32) = next_row_res?;
@@ -815,9 +823,9 @@ impl GenericSession<CurrentDeserializationApi> {
815823
///
816824
/// # Example
817825
/// ```rust
818-
/// # use scylla::LegacySession;
826+
/// # use scylla::Session;
819827
/// # use std::error::Error;
820-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
828+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
821829
/// use scylla::batch::Batch;
822830
///
823831
/// let mut batch: Batch = Default::default();
@@ -944,13 +952,13 @@ where
944952
/// ```rust
945953
/// # use std::error::Error;
946954
/// # async fn check_only_compiles() -> Result<(), Box<dyn Error>> {
947-
/// use scylla::{LegacySession, SessionConfig};
955+
/// use scylla::{Session, SessionConfig};
948956
/// use scylla::transport::KnownNode;
949957
///
950958
/// let mut config = SessionConfig::new();
951959
/// config.known_nodes.push(KnownNode::Hostname("127.0.0.1:9042".to_string()));
952960
///
953-
/// let session: LegacySession = LegacySession::connect(config).await?;
961+
/// let session: Session = Session::connect(config).await?;
954962
/// # Ok(())
955963
/// # }
956964
/// ```
@@ -1282,9 +1290,9 @@ where
12821290
///
12831291
/// # Example
12841292
/// ```rust
1285-
/// # use scylla::LegacySession;
1293+
/// # use scylla::Session;
12861294
/// # use std::error::Error;
1287-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
1295+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
12881296
/// use scylla::prepared_statement::PreparedStatement;
12891297
///
12901298
/// // Prepare the query for later execution
@@ -1611,9 +1619,9 @@ where
16111619
/// /// # Example
16121620
/// ```rust
16131621
/// # extern crate scylla;
1614-
/// # use scylla::LegacySession;
1622+
/// # use scylla::Session;
16151623
/// # use std::error::Error;
1616-
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
1624+
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
16171625
/// use scylla::batch::Batch;
16181626
///
16191627
/// // Create a batch statement with unprepared statements
@@ -1672,10 +1680,10 @@ where
16721680
/// * `case_sensitive` - if set to true the generated query will put keyspace name in quotes
16731681
/// # Example
16741682
/// ```rust
1675-
/// # use scylla::{LegacySession, SessionBuilder};
1683+
/// # use scylla::{Session, SessionBuilder};
16761684
/// # use scylla::transport::Compression;
16771685
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
1678-
/// # let session = SessionBuilder::new().known_node("127.0.0.1:9042").build_legacy().await?;
1686+
/// # let session = SessionBuilder::new().known_node("127.0.0.1:9042").build().await?;
16791687
/// session
16801688
/// .query_unpaged("INSERT INTO my_keyspace.tab (a) VALUES ('test1')", &[])
16811689
/// .await?;

0 commit comments

Comments
 (0)