Skip to content

Commit

Permalink
Merge pull request #32 from svix/jplatte/doctest
Browse files Browse the repository at this point in the history
Check that examples in crate-level docs compile
  • Loading branch information
svix-gabriel authored Feb 16, 2024
2 parents 5e18226 + 9254c26 commit 1833a2f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 31 deletions.
1 change: 1 addition & 0 deletions omniqueue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tokio-util = { version = "0.7", optional = true }
tracing = "0.1"

[dev-dependencies]
anyhow = "1.0.79"
fastrand = "1.9"
serde = { version = "1.0.196", features = ["derive"] }
tokio-executor-trait = "2.1"
Expand Down
93 changes: 62 additions & 31 deletions omniqueue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,53 @@
//!
//! ## How to Use Omniqueue
//!
//! Each queue backend has a unique configuration type. One of these configurations is taken
//! when constructing the [`queue::QueueBuilder`].
//!
//! To create a simple producer and/or consumer:
//!
//! ```compile_fail
//! let cfg = SqsConfig {
//! queue_dsn: "http://localhost:9234/queue/queue_name".to_owned(),
//! override_endpoint: true,
//! };
//!
//! // Either both producer and consumer
//! let (p, mut c) = SqsQueueBackend::builder(cfg.clone()).build_pair().await?;
//!
//! // Or one half
//! let p = SqsQueueBackend::builder(cfg.clone()).build_producer().await?;
//! let mut c = SqsQueueBackend::builder(cfg).build_consumer().await?;
//!
//! (p, c)
//! ```
//!
//! Sending and receiving information from this queue is simple:
//!
//! ```compile_fail
//! p.send_serde_json(&ExampleType::default()).await?;
//! Each queue backend has a unique configuration type. One of these configurations is taken
//! when constructing the [`queue::QueueBuilder`].
//!
//! To create a simple producer and/or consumer:
//!
//! ```no_run
//! # async {
//! use omniqueue::{
//! backends::sqs::{SqsConfig, SqsQueueBackend},
//! queue::QueueBackend,
//! };
//!
//! let cfg = SqsConfig {
//! queue_dsn: "http://localhost:9234/queue/queue_name".to_owned(),
//! override_endpoint: true,
//! };
//!
//! // Either both producer and consumer
//! let (p, mut c) = SqsQueueBackend::builder(cfg.clone()).build_pair().await?;
//!
//! // Or one half
//! let p = SqsQueueBackend::builder(cfg.clone()).build_producer().await?;
//! let mut c = SqsQueueBackend::builder(cfg).build_consumer().await?;
//! # anyhow::Ok(())
//! # };
//! ```
//!
//! let delivery = c.receive().await?;
//! let payload = delivery.payload_serde_json::<ExampleType>().await?;
//! delivery.ack().await?;
//! ```
//! Sending and receiving information from this queue is simple:
//!
//! ```no_run
//! # use omniqueue::{
//! # backends::sqs::SqsQueueBackend,
//! # queue::{consumer::QueueConsumer, producer::QueueProducer, QueueBackend},
//! # };
//! # async {
//! # #[derive(Default, serde::Deserialize, serde::Serialize)]
//! # struct ExampleType;
//! #
//! # let (p, mut c) = SqsQueueBackend::builder(todo!()).build_pair().await?;
//! p.send_serde_json(&ExampleType::default()).await?;
//!
//! let delivery = c.receive().await?;
//! let payload = delivery.payload_serde_json::<ExampleType>()?;
//! delivery.ack().await.map_err(|(e, _)| e)?;
//! # anyhow::Ok(())
//! # };
//! ```
//!
//! ## `DynProducer`s and `DynConsumer`s
//!
Expand All @@ -63,11 +80,17 @@
//!
//! Making a `DynProducer` or `DynConsumer` is as simple as adding one line to the builder:
//!
//! ```compile_fail
//! ```no_run
//! # async {
//! # let cfg = todo!();
//! use omniqueue::{backends::rabbitmq::RabbitMqBackend, queue::QueueBackend};
//!
//! let (p, mut c) = RabbitMqBackend::builder(cfg)
//! .make_dynamic()
//! .build_pair()
//! .await?;
//! # anyhow::Ok(())
//! # };
//! ```
//!
//! ## Encoders/Decoders
Expand All @@ -81,7 +104,11 @@
//!
//! Any function or closure with the right signature may be used as an encoder or decoder.
//!
//! ```compile_fail
//! ```no_run
//! # async {
//! # let cfg = todo!();
//! use omniqueue::{backends::rabbitmq::RabbitMqBackend, queue::QueueBackend, QueueError};
//!
//! #[derive(Debug, PartialEq)]
//! struct ExampleType {
//! field: u8,
Expand All @@ -96,6 +123,10 @@
//! field: *v.first().unwrap_or(&0),
//! })
//! })
//! .build_pair()
//! .await?;
//! # anyhow::Ok(())
//! # };
//! ```
use std::fmt::Debug;

Expand Down

0 comments on commit 1833a2f

Please sign in to comment.