Skip to content

Commit 0e53693

Browse files
committed
pre-commit fixes.
1 parent 716fc8e commit 0e53693

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
- uses: auguwu/clippy-action@1.4.0
4949
with:
5050
token: ${{secrets.GITHUB_TOKEN}}
51-
deny: warnings
51+
deny: warnings

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,27 @@
33
This is a client library for [NATS](https://nats.io) written in rust.
44

55
Credits for [Intree](https://intree.com) for supporting this project.
6+
7+
8+
## installation
9+
10+
This package can be installed from pypi:
11+
12+
```bash
13+
pip install natsrpy
14+
```
15+
16+
Or alternatively you ca build it yourself using maturin, and stable rust.
17+
18+
## Development
19+
20+
We use stable rust and pyo3 for writing python extension module.
21+
22+
In order to run the project use maturin:
23+
24+
```bash
25+
# To create .venv folder
26+
uv venv
27+
# To build and install the package in a virtual environment
28+
maturin dev --uv
29+
```

src/js/stream.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl From<PersistenceMode> for async_nats::jetstream::stream::PersistenceMode {
9898
}
9999

100100
#[pyclass(from_py_object)]
101-
#[derive(Clone, Debug, PartialEq, Default)]
101+
#[derive(Clone, Debug, PartialEq, Eq, Default)]
102102
pub struct ConsumerLimits {
103103
pub inactive_threshold: Duration,
104104
pub max_ack_pending: i64,
@@ -107,7 +107,8 @@ pub struct ConsumerLimits {
107107
#[pymethods]
108108
impl ConsumerLimits {
109109
#[new]
110-
pub fn __new__(inactive_threshold: Duration, max_ack_pending: i64) -> Self {
110+
#[must_use]
111+
pub const fn __new__(inactive_threshold: Duration, max_ack_pending: i64) -> Self {
111112
Self {
112113
inactive_threshold,
113114
max_ack_pending,
@@ -135,7 +136,8 @@ pub struct Republish {
135136
#[pymethods]
136137
impl Republish {
137138
#[new]
138-
pub fn __new__(source: String, destination: String, headers_only: bool) -> Self {
139+
#[must_use]
140+
pub const fn __new__(source: String, destination: String, headers_only: bool) -> Self {
139141
Self {
140142
source,
141143
destination,
@@ -387,7 +389,7 @@ impl StreamConfig {
387389
allow_message_schedules=None,
388390
allow_message_counter=None,
389391
))]
390-
pub fn __new__(
392+
pub const fn __new__(
391393
name: String,
392394
subjects: Vec<String>,
393395
max_bytes: Option<i64>,
@@ -430,12 +432,12 @@ impl StreamConfig {
430432
) -> NatsrpyResult<Self> {
431433
Ok(Self {
432434
name,
435+
subjects,
433436
max_bytes,
434437
max_messages,
435438
max_messages_per_subject,
436439
discard,
437440
discard_new_per_subject,
438-
subjects,
439441
retention,
440442
max_consumers,
441443
max_age,
@@ -523,9 +525,9 @@ impl TryFrom<StreamConfig> for async_nats::jetstream::stream::Config {
523525

524526
// Values that require conversion between python -> rust types.
525527
conf.republish = value.republish.map(Into::into);
526-
conf.storage = value.storage.map(Into::into).unwrap_or(conf.storage);
527-
conf.retention = value.retention.map(Into::into).unwrap_or(conf.retention);
528-
conf.discard = value.discard.map(Into::into).unwrap_or(conf.discard);
528+
conf.storage = value.storage.map_or(conf.storage, Into::into);
529+
conf.retention = value.retention.map_or(conf.retention, Into::into);
530+
conf.discard = value.discard.map_or(conf.discard, Into::into);
529531
conf.mirror = value.mirror.map(TryInto::try_into).transpose()?;
530532
conf.sources = value
531533
.sources
@@ -543,7 +545,7 @@ impl TryFrom<StreamConfig> for async_nats::jetstream::stream::Config {
543545
conf.persist_mode = value.persist_mode.map(Into::into);
544546
conf.pause_until = value
545547
.pause_until
546-
.map(|val| time::OffsetDateTime::from_unix_timestamp(val))
548+
.map(time::OffsetDateTime::from_unix_timestamp)
547549
.transpose()?;
548550

549551
Ok(conf)
@@ -576,7 +578,7 @@ impl StreamMessage {
576578
time.minute(),
577579
time.second(),
578580
time.microsecond(),
579-
Some(tz_info.deref()),
581+
Some(&*tz_info),
580582
)?;
581583
Ok(Self {
582584
subject: msg.subject.to_string(),
@@ -608,6 +610,7 @@ pub struct Stream {
608610
stream: Arc<RwLock<async_nats::jetstream::stream::Stream<async_nats::jetstream::stream::Info>>>,
609611
}
610612
impl Stream {
613+
#[must_use]
611614
pub fn new(
612615
stream: async_nats::jetstream::stream::Stream<async_nats::jetstream::stream::Info>,
613616
) -> Self {

src/nats_cls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl NatsCls {
171171
payload: data,
172172
headers: headermap,
173173
inbox,
174-
timeout: timeout.map(|val| Some(val)),
174+
timeout: timeout.map(Some),
175175
};
176176
session.send_request(subject, request).await?;
177177
Ok(())

0 commit comments

Comments
 (0)