Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IntoBody and IntoBytes to write data #10

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Use IntoBody and `IntoBytes to write data, [PR-10](https://github.com/reductstore/reduct-rs/pull/10)

## [1.9.5] - 2024-03-30

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn main() -> Result<(), ReductError> {
bucket
.write_record("entry-1")
.timestamp(timestamp)
.data(Bytes::from("Hello, World!"))
.data("Hello, World!")
.send()
.await?;

Expand Down
3 changes: 1 addition & 2 deletions examples/hallo_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use bytes::Bytes;
use reduct_rs::{ReductClient, ReductError};
use std::str::from_utf8;
use std::time::SystemTime;
Expand All @@ -18,7 +17,7 @@ async fn main() -> Result<(), ReductError> {
bucket
.write_record("entry-1")
.timestamp(timestamp)
.data(Bytes::from("Hello, World!"))
.data("Hello, World!")
.send()
.await?;

Expand Down
5 changes: 2 additions & 3 deletions examples/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use bytes::Bytes;
use futures_util::StreamExt;
use reduct_rs::{ReductClient, ReductError};
use std::str::from_utf8;
Expand All @@ -19,14 +18,14 @@ async fn main() -> Result<(), ReductError> {
bucket
.write_record("entry-1")
.add_label("planet", "Earth")
.data(Bytes::from("Hello, Earth!"))
.data("Hello, Earth!")
.send()
.await?;

bucket
.write_record("entry-1")
.add_label("planet", "Mars")
.data(Bytes::from("Hello, Mars!"))
.data("Hello, Mars!")
.send()
.await?;

Expand Down
10 changes: 8 additions & 2 deletions src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,21 @@ impl RecordBuilder {
}

/// Set the content length of the record to write
///
/// Note: use this with stream data
pub fn content_length(mut self, content_length: usize) -> Self {
self.record.content_length = content_length;
self
}

/// Set the content of the record
///
/// Overwrites content length
pub fn data(mut self, bytes: Bytes) -> Self {
/// Note: use this with data that fits in memory
pub fn data<D>(mut self, data: D) -> Self
where
D: Into<Bytes>,
{
let bytes = data.into();
self.record.content_length = bytes.len();
self.record.data = Some(Box::pin(futures::stream::once(async move { Ok(bytes) })));
self
Expand Down
9 changes: 8 additions & 1 deletion src/record/write_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ impl WriteRecordBuilder {
}

/// Set the data of the record to write.
pub fn data(mut self, data: Bytes) -> Self {
///
/// # Arguments
///
/// * `data` - The data to write.
pub fn data<B>(mut self, data: B) -> Self
where
B: Into<Body>,
{
self.data = Some(data.into());
self
}
Expand Down