Skip to content

Commit e43c6d4

Browse files
committed
Fix doctests with new serde feature
1 parent 5afc984 commit e43c6d4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/builder.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl Builder {
442442
/// let client = Postgrest::new("https://your.postgrest.endpoint");
443443
/// client
444444
/// .from("users")
445-
/// .insert(&my_serializable_struct)?;
445+
/// .insert(&my_serializable_struct).unwrap();
446446
/// ```
447447
#[cfg(feature = "serde")]
448448
pub fn insert<T>(self, body: &T) -> serde_json::Result<Self>
@@ -506,7 +506,7 @@ impl Builder {
506506
/// let client = Postgrest::new("https://your.postgrest.endpoint");
507507
/// client
508508
/// .from("users")
509-
/// .upsert(&my_serializable_struct)?;
509+
/// .upsert(&my_serializable_struct).unwrap();
510510
/// ```
511511
#[cfg(feature = "serde")]
512512
pub fn upsert<T>(self, body: &T) -> serde_json::Result<Self>
@@ -543,11 +543,23 @@ impl Builder {
543543
/// let client = Postgrest::new("https://your.postgrest.endpoint");
544544
/// // Suppose `users` are keyed an SERIAL primary key,
545545
/// // but have a unique index on `username`.
546-
/// client
547-
/// .from("users")
548-
/// .upsert(r#"[{ "username": "soedirgo", "status": "online" },
549-
/// { "username": "jose", "status": "offline" }]"#)
550-
/// .on_conflict("username");
546+
#[cfg_attr(not(feature = "serde"), doc = r##"
547+
client
548+
.from("users")
549+
.upsert(r#"[{ "username": "soedirgo", "status": "online" },
550+
{ "username": "jose", "status": "offline" }]"#)
551+
.on_conflict("username");
552+
"##)]
553+
#[cfg_attr(feature = "serde", doc = r##"
554+
#[derive(serde::Serialize)]
555+
struct MyStruct {}
556+
557+
let my_serializable_struct = MyStruct {};
558+
559+
client
560+
.from("users")
561+
.upsert(&my_serializable_struct).unwrap();
562+
"##)]
551563
/// ```
552564
pub fn on_conflict<T>(mut self, columns: T) -> Self
553565
where
@@ -595,7 +607,7 @@ impl Builder {
595607
/// client
596608
/// .from("users")
597609
/// .eq("username", "soedirgo")
598-
/// .update(&my_serializable_struct)?;
610+
/// .update(&my_serializable_struct).unwrap();
599611
/// ```
600612
#[cfg(feature = "serde")]
601613
pub fn update<T>(self, body: &T) -> serde_json::Result<Self>

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
//! Updating a table:
4545
//! ```
4646
//! # use postgrest::Postgrest;
47+
//! # #[cfg(not(feature = "serde"))]
4748
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
4849
//! # let client = Postgrest::new("https://your.postgrest.endpoint");
4950
//! let resp = client

0 commit comments

Comments
 (0)