Skip to content

Commit 15e7409

Browse files
committed
rust: replace std queue with baselibs rust
1 parent d5414f7 commit 15e7409

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
// Generate `rust-project.json` with bazel run @rules_rust//tools/rust_analyzer:gen_rust_project
3+
"rust-analyzer.linkedProjects": [
4+
"rust-project.json"
5+
]
6+
}

MODULE.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ bazel_dep(name = "bazel_skylib", version = "1.8.1")
122122
bazel_dep(name = "rules_doxygen", version = "2.5.0")
123123
bazel_dep(name = "score_baselibs", version = "0.2.2")
124124

125+
bazel_dep(name = "score_baselibs_rust", version = "0.0.1")
126+
git_override(
127+
module_name = "score_baselibs_rust",
128+
commit = "9ee64ac85f2a990ef75b2858253ee44bfc1a7ab7",
129+
remote = "https://github.com/eclipse-score/baselibs_rust.git",
130+
)
131+
132+
125133
# Doxygen extension for documentation generation
126134
doxygen_extension = use_extension("@rules_doxygen//:extensions.bzl", "doxygen_extension")
127135
use_repo(doxygen_extension, "doxygen")

score/mw/com/example/com-api-example/basic-consumer-producer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<R: Runtime> VehicleMonitor<R> {
3434

3535
/// Monitor tire data from the consumer
3636
pub fn read_tire_data(&self) -> Result<String> {
37-
let mut sample_buf = SampleContainer::new();
37+
let mut sample_buf = SampleContainer::new(3);
3838

3939
match self.tire_subscriber.try_receive(&mut sample_buf, 1) {
4040
Ok(0) => Err(Error::Fail),

score/mw/com/impl/rust/com-api/com-api-concept/BUILD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ rust_library(
2222
visibility = [
2323
"//visibility:public", # platform_only
2424
],
25-
deps = [],
25+
deps = [
26+
"@score_baselibs_rust//src/containers:containers",
27+
],
2628
)
2729

2830
rust_test(

score/mw/com/impl/rust/com-api/com-api-concept/com_api_concept.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ use core::fmt::Debug;
5050
use core::future::Future;
5151
use core::ops::{Deref, DerefMut};
5252
pub mod reloc;
53+
use containers::fixed_capacity::FixedCapacityQueue;
5354
pub use reloc::Reloc;
54-
use std::collections::VecDeque;
5555
use std::path::Path;
5656

5757
/// Error enumeration for different failure cases in the Consumer/Producer/Runtime APIs.
@@ -597,21 +597,15 @@ pub trait Subscriber<T: Reloc + Send + Debug, R: Runtime + ?Sized> {
597597
/// # Type Parameters
598598
/// * `S`: The sample type stored in the container.
599599
pub struct SampleContainer<S> {
600-
inner: VecDeque<S>,
601-
}
602-
603-
impl<S> Default for SampleContainer<S> {
604-
fn default() -> Self {
605-
Self {
606-
inner: VecDeque::new(),
607-
}
608-
}
600+
inner: FixedCapacityQueue<S>,
609601
}
610602

611603
impl<S> SampleContainer<S> {
612604
/// Creates a new, empty `SampleContainer`
613-
pub fn new() -> Self {
614-
Self::default()
605+
pub fn new(capacity: usize) -> Self {
606+
Self {
607+
inner: FixedCapacityQueue::new(capacity),
608+
}
615609
}
616610

617611
/// Returns an iterator over references to the samples in the container.
@@ -645,7 +639,7 @@ impl<S> SampleContainer<S> {
645639
/// # Returns
646640
/// A `Result` indicating success or failure.
647641
pub fn push_back(&mut self, new: S) -> Result<()> {
648-
self.inner.push_back(new);
642+
self.inner.push_back(new).map_err(|_| Error::AllocateFailed)?;
649643
Ok(())
650644
}
651645

0 commit comments

Comments
 (0)