Skip to content

Commit

Permalink
Swap client parameters to put config in the end
Browse files Browse the repository at this point in the history
  • Loading branch information
rmja committed Dec 19, 2023
1 parent 4f87ddf commit d3997ad
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions atat/src/asynch/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ use futures::{
pub struct Client<'a, W: Write, const INGRESS_BUF_SIZE: usize> {
writer: W,
res_channel: &'a ResponseChannel<INGRESS_BUF_SIZE>,
buf: &'a mut [u8],
config: Config,
cooldown_timer: Option<Timer>,
buf: &'a mut [u8],
}

impl<'a, W: Write, const INGRESS_BUF_SIZE: usize> Client<'a, W, INGRESS_BUF_SIZE> {
pub fn new(
writer: W,
res_channel: &'a ResponseChannel<INGRESS_BUF_SIZE>,
config: Config,
buf: &'a mut [u8],
config: Config,
) -> Self {
Self {
writer,
res_channel,
buf,
config,
cooldown_timer: None,
buf,
}
}

Expand Down Expand Up @@ -185,7 +185,7 @@ mod tests {

let tx_mock = crate::tx_mock::TxMock::new(TX_CHANNEL.publisher().unwrap());
let client: Client<crate::tx_mock::TxMock, TEST_RX_BUF_LEN> =
Client::new(tx_mock, &RES_CHANNEL, $config, unsafe { BUF.as_mut() });
Client::new(tx_mock, &RES_CHANNEL, unsafe { BUF.as_mut() }, $config);
(
client,
TX_CHANNEL.subscriber().unwrap(),
Expand Down
8 changes: 4 additions & 4 deletions atat/src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ where
{
writer: W,
res_channel: &'a ResponseChannel<INGRESS_BUF_SIZE>,
buf: &'a mut [u8],
cooldown_timer: Option<BlockingTimer>,
config: Config,
buf: &'a mut [u8],
}

impl<'a, W, const INGRESS_BUF_SIZE: usize> Client<'a, W, INGRESS_BUF_SIZE>
Expand All @@ -29,15 +29,15 @@ where
pub fn new(
writer: W,
res_channel: &'a ResponseChannel<INGRESS_BUF_SIZE>,
config: Config,
buf: &'a mut [u8],
config: Config,
) -> Self {
Self {
writer,
res_channel,
buf,
cooldown_timer: None,
config,
buf,
}
}

Expand Down Expand Up @@ -268,7 +268,7 @@ mod test {

let tx_mock = crate::tx_mock::TxMock::new(TX_CHANNEL.publisher().unwrap());
let client: Client<crate::tx_mock::TxMock, TEST_RX_BUF_LEN> =
Client::new(tx_mock, &RES_CHANNEL, $config, unsafe { BUF.as_mut() });
Client::new(tx_mock, &RES_CHANNEL, unsafe { BUF.as_mut() }, $config);
(
client,
TX_CHANNEL.subscriber().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions atat/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ pub trait AtatCmd {
fn parse(&self, resp: Result<&[u8], InternalError>) -> Result<Self::Response, Error>;
}

impl<'a, T, const L: usize> AtatResp for Vec<T, L> where T: AtatResp {}
impl<T, const L: usize> AtatResp for Vec<T, L> where T: AtatResp {}

impl<const L: usize> AtatResp for String<L> {}

impl<'a, const L: usize> AtatCmd for String<L> {
impl<const L: usize> AtatCmd for String<L> {
type Response = String<256>;

fn write(&self, buf: &mut [u8]) -> usize {
Expand Down
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tokio = { version = "1.26", default-features = false, features = [
"macros",
], optional = true }
tokio-serial = { version = "5.4.4", optional = true }
static_cell = "2"

[features]
embedded = [
Expand Down
8 changes: 7 additions & 1 deletion examples/src/bin/embassy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ async fn main(spawner: Spawner) {
&RES_CHANNEL,
&URC_CHANNEL,
);
let mut client = Client::new(writer, RES_CHANNEL.subscriber(), atat::Config::default());
let buf = StaticCell::make_static!([0; 1024]);
let mut client = Client::new(
writer,
RES_CHANNEL.subscriber(),
buf,
atat::Config::default(),
);

spawner.spawn(ingress_task(ingress, reader)).unwrap();

Expand Down
3 changes: 2 additions & 1 deletion examples/src/bin/std-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async fn main() -> ! {
&RES_CHANNEL,
&URC_CHANNEL,
);
let mut client = Client::new(FromTokio::new(writer), &RES_CHANNEL, Config::default());
let buf = StaticCell::make_static!([0; 1024]);

Check failure on line 30 in examples/src/bin/std-tokio.rs

View workflow job for this annotation

GitHub Actions / Test

failed to resolve: use of undeclared type `StaticCell`
let mut client = Client::new(FromTokio::new(writer), &RES_CHANNEL, buf, Config::default());

tokio::spawn(ingress_task(ingress, FromTokio::new(reader)));

Expand Down

0 comments on commit d3997ad

Please sign in to comment.