Skip to content

Commit d0a4df3

Browse files
committed
Update library docs and readme
1 parent 9a70f56 commit d0a4df3

File tree

4 files changed

+110
-22
lines changed

4 files changed

+110
-22
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,29 @@
88
Kafka client library for Rust based on [librdkafka].
99

1010
## The library
11-
This library aims to provide a safe interface to librdkafka.
12-
It currently exports some of the funcionalities provided by the producer and consumer
13-
of librdkafka 0.9.2.
11+
`rust-rdkafka` provides a safe Rust interface to librdkafka.
12+
It currently exports a subset of the funcionalities provided by librdkafka 0.9.2.
1413

15-
Producers and consumers can be accessed and polled directly, or alternatively
16-
a [futures]-based interface can be used:
14+
`rust-rdkafka` provides low level and high level consumers and producers. Low level:
1715

18-
* A consumer will return a [`stream`] of messages, as they are received from Kafka.
19-
* A producer will return a [`future`] that will eventually contain the delivery
20-
status of the message.
16+
* `BaseConsumer`: simple wrapper around the librdkafka consumer. It requires to be
17+
periodically `poll()`ed in order to execute callbacks, rebalance and receive messages.
18+
* `BaseProducer`: simple wrapper around the librdkafka producer. As in the consumer case,
19+
the user must call `poll()` periodically to execute delivery callbacks.
20+
21+
High level:
22+
23+
* `StreamConsumer`: it returns a [`stream`] of messages and takes care of polling the consumer
24+
internally.
25+
* `FutureProducer`: it returns a [`future`] that will be completed once the message is
26+
delivered to Kafka (or fails).
2127

2228
[librdkafka]: https://github.com/edenhill/librdkafka
2329
[futures]: https://github.com/alexcrichton/futures-rs
2430
[`future`]: https://docs.rs/futures/0.1.3/futures/trait.Future.html
2531
[`stream`]: https://docs.rs/futures/0.1.3/futures/stream/trait.Stream.html
2632

27-
*Warning*: this library is still at an early development stage, the API is very likely
28-
to change and it shouldn't be considered production ready.
33+
*Warning*: the library is under active development and the APIs are likely to change.
2934

3035
## Installation
3136

@@ -36,7 +41,7 @@ Add this to your `Cargo.toml`:
3641
rdkafka = "^0.2.0"
3742
```
3843

39-
This crate will compile librdkafka from sources and link it statically in your
44+
This crate will compile librdkafka from sources and link it statically to your
4045
executable. To compile librdkafka you'll need:
4146

4247
* the GNU toolchain

generate_readme.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/python3
2+
3+
from collections import namedtuple
4+
import sys
5+
6+
7+
INCLUDE_MARKER = "__INCLUDE_RUST_DOC__"
8+
9+
Template = namedtuple("Template", ["header", "footer", "doc_path", "start"])
10+
11+
12+
def read_rust_doc_lines(path):
13+
with open(path, "r") as rust_doc:
14+
for line in rust_doc:
15+
if line.startswith('//! '):
16+
yield line[4:]
17+
elif line.startswith('//!'):
18+
yield line[3:]
19+
else:
20+
break
21+
22+
23+
def parse_template_file(path):
24+
content = [line for line in open(path, "r")]
25+
try:
26+
marker_position = [n for (n, line) in enumerate(content)
27+
if line.startswith(INCLUDE_MARKER)][0]
28+
except IndexError:
29+
raise Exception("Missing include marker")
30+
include_info = content[marker_position].split('$')
31+
return Template(
32+
header=content[0:marker_position], footer=content[marker_position+1:],
33+
doc_path=include_info[1], start=include_info[2],
34+
)
35+
36+
37+
template = parse_template_file("readme_template")
38+
doc = read_rust_doc_lines(template.doc_path)
39+
40+
output = sys.stdout
41+
42+
for line in template.header:
43+
output.write(line)
44+
45+
for line in doc:
46+
if line.startswith(template.start):
47+
output.write(line)
48+
break
49+
50+
for line in doc:
51+
output.write(line)
52+
53+
for line in template.footer:
54+
output.write(line)

readme_template

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# rust-rdkafka
2+
3+
[![crates.io](https://img.shields.io/crates/v/rdkafka.svg)](https://crates.io/crates/rdkafka)
4+
[![docs.rs](https://docs.rs/rdkafka/badge.svg)](https://docs.rs/rdkafka/)
5+
[![Build Status](https://travis-ci.org/fede1024/rust-rdkafka.svg?branch=master)](https://travis-ci.org/fede1024/rust-rdkafka)
6+
[![Join the chat at https://gitter.im/rust-rdkafka/Lobby](https://badges.gitter.im/rust-rdkafka/Lobby.svg)](https://gitter.im/rust-rdkafka/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7+
8+
Kafka client library for Rust based on [librdkafka].
9+
10+
__INCLUDE_RUST_DOC__$src/lib.rs$## The library
11+
## Documentation
12+
13+
Documentation is available on [docs.rs](https://docs.rs/rdkafka/).
14+
15+
## Contributors
16+
17+
Thanks to:
18+
* Thijs Cadier - [thijsc](https://github.com/thijsc)
19+
20+
## Alternatives
21+
22+
* [kafka-rust]: a pure Rust implementation of the Kafka client.
23+
24+
[kafka-rust]: https://github.com/spicavigo/kafka-rust

src/lib.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
//! Kafka client library for Rust based on [librdkafka].
33
//!
44
//! ## The library
5-
//! This library aims to provide a safe interface to librdkafka.
6-
//! It currently exports some of the funcionalities provided by the producer and consumer
7-
//! of librdkafka 0.9.2.
5+
//! `rust-rdkafka` provides a safe Rust interface to librdkafka.
6+
//! It currently exports a subset of the funcionalities provided by librdkafka 0.9.2.
87
//!
9-
//! Producers and consumers can be accessed and polled directly, or alternatively
10-
//! a [futures]-based interface can be used:
8+
//! `rust-rdkafka` provides low level and high level consumers and producers. Low level:
119
//!
12-
//! * A consumer will return a [`stream`] of messages, as they are received from Kafka.
13-
//! * A producer will return a [`future`] that will eventually contain the delivery
14-
//! status of the message.
10+
//! * `BaseConsumer`: simple wrapper around the librdkafka consumer. It requires to be
11+
//! periodically `poll()`ed in order to execute callbacks, rebalance and receive messages.
12+
//! * `BaseProducer`: simple wrapper around the librdkafka producer. As in the consumer case,
13+
//! the user must call `poll()` periodically to execute delivery callbacks.
14+
//!
15+
//! High level:
16+
//!
17+
//! * `StreamConsumer`: it returns a [`stream`] of messages and takes care of polling the consumer
18+
//! internally.
19+
//! * `FutureProducer`: it returns a [`future`] that will be completed once the message is
20+
//! delivered to Kafka (or fails).
1521
//!
1622
//! [librdkafka]: https://github.com/edenhill/librdkafka
1723
//! [futures]: https://github.com/alexcrichton/futures-rs
1824
//! [`future`]: https://docs.rs/futures/0.1.3/futures/trait.Future.html
1925
//! [`stream`]: https://docs.rs/futures/0.1.3/futures/stream/trait.Stream.html
2026
//!
21-
//! *Warning*: this library is still at an early development stage, the API is very likely
22-
//! to change and it shouldn't be considered production ready.
27+
//! *Warning*: the library is under active development and the APIs are likely to change.
2328
//!
2429
//! ## Installation
2530
//!
@@ -30,7 +35,7 @@
3035
//! rdkafka = "^0.2.0"
3136
//! ```
3237
//!
33-
//! This crate will compile librdkafka from sources and link it statically in your
38+
//! This crate will compile librdkafka from sources and link it statically to your
3439
//! executable. To compile librdkafka you'll need:
3540
//!
3641
//! * the GNU toolchain

0 commit comments

Comments
 (0)