Skip to content

Commit 52264b5

Browse files
committed
rust: replace std queue with baselibs rust
1 parent d002a79 commit 52264b5

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
@@ -127,6 +127,14 @@ git_override(
127127
remote = "https://github.com/eclipse-score/baselibs.git",
128128
)
129129

130+
bazel_dep(name = "score_baselibs_rust", version = "0.0.1")
131+
git_override(
132+
module_name = "score_baselibs_rust",
133+
commit = "9ee64ac85f2a990ef75b2858253ee44bfc1a7ab7",
134+
remote = "https://github.com/eclipse-score/baselibs_rust.git",
135+
)
136+
137+
130138
# Doxygen extension for documentation generation
131139
doxygen_extension = use_extension("@rules_doxygen//:extensions.bzl", "doxygen_extension")
132140
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.
@@ -584,21 +584,15 @@ pub trait Subscriber<T: Reloc + Send + Debug, R: Runtime + ?Sized> {
584584
/// # Type Parameters
585585
/// * `S`: The sample type stored in the container.
586586
pub struct SampleContainer<S> {
587-
inner: VecDeque<S>,
588-
}
589-
590-
impl<S> Default for SampleContainer<S> {
591-
fn default() -> Self {
592-
Self {
593-
inner: VecDeque::new(),
594-
}
595-
}
587+
inner: FixedCapacityQueue<S>,
596588
}
597589

598590
impl<S> SampleContainer<S> {
599591
/// Creates a new, empty `SampleContainer`
600-
pub fn new() -> Self {
601-
Self::default()
592+
pub fn new(capacity: usize) -> Self {
593+
Self {
594+
inner: FixedCapacityQueue::new(capacity),
595+
}
602596
}
603597

604598
/// Returns an iterator over references to the samples in the container.
@@ -632,7 +626,7 @@ impl<S> SampleContainer<S> {
632626
/// # Returns
633627
/// A `Result` indicating success or failure.
634628
pub fn push_back(&mut self, new: S) -> Result<()> {
635-
self.inner.push_back(new);
629+
self.inner.push_back(new).map_err(|_| Error::AllocateFailed)?;
636630
Ok(())
637631
}
638632

0 commit comments

Comments
 (0)