Skip to content

Commit 55a7179

Browse files
author
Daniel Lyne
committed
Improve documentation for crate
1 parent d49cb30 commit 55a7179

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ While the exact configuration will depend on the backend used, usage is roughly
3030
If you only need some backends, then simply disable the default features, and enable any backends
3131
that you require.
3232

33-
2. Construct anud use your queue.
33+
2. Construct and use your queue.
3434

3535
The exact configuration type used will depend on your backend, but it's as simple as:
3636

@@ -95,7 +95,7 @@ let (p, mut c) = RabbitMqBackend::builder(cfg)
9595
})
9696
.with_decoder(|v: &Vec<u8>| -> Result<ExampleType, QueueError> {
9797
Ok(ExampleType {
98-
field: *v.first().unwrap_or(i&0),
98+
field: *v.first().unwrap_or(&0),
9999
})
100100
})
101101
.build_pair()

omniqueue/src/lib.rs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,102 @@
1+
//! # Omniqueue
2+
//!
3+
//! Omniqueue provides a high-level interface for sending and receiving the following over a range
4+
//! of queue backends:
5+
//!
6+
//! * Raw byte arrays in the way most compatible with the queue backend
7+
//!
8+
//! * JSON encoded byte arrays for types that implement [`serde::Deserialize`] and
9+
//! [`serde::Serialize`]
10+
//!
11+
//! * Arbitrary types for which an encoder and/or decoder has been defined
12+
//!
13+
//! ## Cargo Features
14+
//!
15+
//! Each backend is enabled with its associated cargo feature. All backends are enabled by default.
16+
//! As of present it supports:
17+
//!
18+
//! * In-memory queues
19+
//!
20+
//! * RabbitMQ
21+
//!
22+
//! * Redis streams
23+
//!
24+
//! * SQS
25+
//!
26+
//! ## How to Use Omniqueue
27+
//!
28+
//! Each queue backend has a unique configuration type. One of these configurations is taken
29+
//! when constructing the [`queue::QueueBuilder`].
30+
//!
31+
//! To create a simple producer and/or consumer:
32+
//!
33+
//! ```compile_fail
34+
//! let cfg = SqsConfig {
35+
//! queue_dsn: "http://localhost:9234/queue/queue_name".to_owned(),
36+
//! override_endpoint: true,
37+
//! };
38+
//!
39+
//! // Either both producer and consumer
40+
//! let (p, mut c) = SqsQueueBackend::builder(cfg.clone()).build_pair().await?;
41+
//!
42+
//! // Or one half
43+
//! let p = SqsQueueBackend::builder(cfg.clone()).build_producer().await?;
44+
//! let mut c = SqsQueueBackend::builder(cfg).build_consumer().await?;
45+
//!
46+
//! (p, c)
47+
//! ```
48+
//!
49+
//! Sending and receiving information from this queue is simple:
50+
//!
51+
//! ```compile_fail
52+
//! p.send_serde_json(&ExampleType::default()).await?;
53+
//!
54+
//! let delivery = c.receive().await?;
55+
//! let payload = delivery.payload_serde_json::<ExampleType>().await?;
56+
//! delivery.ack().await?;
57+
//! ```
58+
//!
59+
//! ## `DynProducer`s and `DynConsumer`s
60+
//!
61+
//! Dynamic-dispatch can be used easily for when you're not sure which backend to use at
62+
//! compile-time.
63+
//!
64+
//! Making a `DynProducer` or `DynConsumer` is as simple as adding one line to the builder:
65+
//!
66+
//! ```compile_fail
67+
//! let (p, mut c) = RabbitMqBackend::builder(cfg)
68+
//! .make_dynamic()
69+
//! .build_pair()
70+
//! .await?;
71+
//! ```
72+
//!
73+
//! ## Encoders/Decoders
74+
//!
75+
//! The [`encoding::CustomEncoder`]s and [`decoding::CustomDecoder`]s given to the builder upon
76+
//! producer/consumer creation will be used to convert from/to the queue's native representation
77+
//! into/from a given type. This helps enforce a separation of responsibilities where only the
78+
//! application setting up a concrete queue instance should ever have to think about the internal
79+
//! data-representation of items within the queue while abstract uses of queues should be able to
80+
//! work with simple Rust types.
81+
//!
82+
//! Any function or closure with the right signature may be used as an encoder or decoder.
83+
//!
84+
//! ```compile_fail
85+
//! #[derive(Debug, PartialEq)]
86+
//! struct ExampleType {
87+
//! field: u8,
88+
//! }
89+
//!
90+
//! let (p, mut c) = RabbitMqBackend::builder(cfg)
91+
//! .with_encoder(|et: &ExampleType| -> Result<Vec<u8>, QueueError> {
92+
//! Ok(vec![et.field])
93+
//! })
94+
//! .with_decoder(|v: &Vec<u8>| -> Result<ExampleType, QueueError> {
95+
//! Ok(ExampleType {
96+
//! field: *v.first().unwrap_or(&0),
97+
//! })
98+
//! })
99+
//! ```
1100
use std::fmt::Debug;
2101

3102
use thiserror::Error;

0 commit comments

Comments
 (0)