Skip to content

Commit 2d5c5f0

Browse files
Merge pull request #634 from swimos/docs4
Tidy up of crate/module API: Stage 4
2 parents a7f957e + 4ba931a commit 2d5c5f0

File tree

204 files changed

+2164
-2548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+2164
-2548
lines changed

api/swimos_api/src/agent/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use std::{
2828
use bytes::Bytes;
2929
use futures::{future::BoxFuture, ready, Future, FutureExt};
3030
use swimos_utilities::{
31-
future::retryable::RetryStrategy,
32-
io::byte_channel::{ByteReader, ByteWriter},
31+
byte_channel::{ByteReader, ByteWriter},
32+
future::RetryStrategy,
3333
non_zero_usize,
34-
routing::route_uri::RouteUri,
34+
routing::RouteUri,
3535
};
3636
use thiserror::Error;
3737
use tokio::sync::{mpsc, oneshot};

api/swimos_api/src/error/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use std::{error::Error, sync::Arc};
2020
use swimos_form::read::ReadError;
2121
use swimos_model::Text;
2222
use swimos_recon::parser::AsyncParseError;
23-
use swimos_utilities::{
24-
errors::Recoverable, routing::route_pattern::UnapplyError, trigger::promise,
25-
};
23+
use swimos_utilities::{errors::Recoverable, routing::UnapplyError, trigger::promise};
2624
use thiserror::Error;
2725
use tokio::sync::{mpsc, oneshot, watch};
2826

api/swimos_api/src/http/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl HeaderName {
6666

6767
impl HeaderValue {
6868
pub fn new(bytes: Bytes) -> Self {
69-
HeaderValue(match BytesStr::new(bytes) {
69+
HeaderValue(match BytesStr::try_wrap(bytes) {
7070
Ok(bytes_str) => HeaderValueInner::StringHeader(bytes_str),
7171
Err(bytes) => HeaderValueInner::BytesHeader(bytes),
7272
})

api/swimos_client_api/src/downlink/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use swimos_api::address::Address;
1919
use swimos_api::{agent::DownlinkKind, error::DownlinkTaskError};
2020
use swimos_model::Text;
2121
use swimos_utilities::{
22-
io::byte_channel::{ByteReader, ByteWriter},
22+
byte_channel::{ByteReader, ByteWriter},
2323
non_zero_usize,
2424
};
2525

api/swimos_form/src/structural/read/recognizer/impls.rs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ use std::str::FromStr;
4040
use std::time::Duration;
4141
use swimos_model::Timestamp;
4242
use swimos_model::{Text, ValueKind};
43-
use swimos_utilities::future::retryable::strategy::{
44-
DEFAULT_EXPONENTIAL_MAX_BACKOFF, DEFAULT_EXPONENTIAL_MAX_INTERVAL, DEFAULT_IMMEDIATE_RETRIES,
45-
DEFAULT_INTERVAL_DELAY, DEFAULT_INTERVAL_RETRIES,
46-
};
47-
use swimos_utilities::future::retryable::{Quantity, RetryStrategy};
48-
use swimos_utilities::routing::route_uri::RouteUri;
43+
use swimos_utilities::future::{ExponentialStrategy, IntervalStrategy, Quantity, RetryStrategy};
44+
use swimos_utilities::routing::RouteUri;
4945

5046
use super::BodyStage;
5147
use super::FirstOf;
@@ -222,9 +218,14 @@ impl Recognizer for RetryStrategyRecognizer {
222218
}
223219
ow => Some(Err(ReadError::UnexpectedField(Text::new(ow)))),
224220
},
225-
ReadEvent::EndRecord => Some(Ok(RetryStrategy::immediate(
226-
retries.unwrap_or(DEFAULT_IMMEDIATE_RETRIES),
227-
))),
221+
ReadEvent::EndRecord => {
222+
let strat = if let Some(retries) = retries {
223+
RetryStrategy::immediate(retries)
224+
} else {
225+
RetryStrategy::default_immediate()
226+
};
227+
Some(Ok(strat))
228+
}
228229
ow => Some(Err(ow.kind_error(ExpectedEvent::Or(vec![
229230
ExpectedEvent::ValueEvent(ValueKind::Text),
230231
ExpectedEvent::EndOfRecord,
@@ -251,10 +252,16 @@ impl Recognizer for RetryStrategyRecognizer {
251252
}
252253
ow => Some(Err(ReadError::UnexpectedField(Text::new(ow)))),
253254
},
254-
ReadEvent::EndRecord => Some(Ok(RetryStrategy::interval(
255-
delay.unwrap_or_else(|| Duration::from_secs(DEFAULT_INTERVAL_DELAY)),
256-
retries.unwrap_or(Quantity::Finite(DEFAULT_INTERVAL_RETRIES)),
257-
))),
255+
ReadEvent::EndRecord => {
256+
let mut strat = IntervalStrategy::default_interval();
257+
strat.delay = delay;
258+
match retries {
259+
Some(Quantity::Finite(n)) => strat.retry = Quantity::Finite(n.get()),
260+
Some(Quantity::Infinite) => strat.retry = Quantity::Infinite,
261+
_ => {}
262+
}
263+
Some(Ok(RetryStrategy::Interval(strat)))
264+
}
258265
ow => Some(Err(ow.kind_error(ExpectedEvent::Or(vec![
259266
ExpectedEvent::ValueEvent(ValueKind::Text),
260267
ExpectedEvent::EndOfRecord,
@@ -282,10 +289,16 @@ impl Recognizer for RetryStrategyRecognizer {
282289
}
283290
ow => Some(Err(ReadError::UnexpectedField(Text::new(ow)))),
284291
},
285-
ReadEvent::EndRecord => Some(Ok(RetryStrategy::exponential(
286-
max_interval.unwrap_or(DEFAULT_EXPONENTIAL_MAX_INTERVAL),
287-
max_backoff.unwrap_or(Quantity::Finite(DEFAULT_EXPONENTIAL_MAX_BACKOFF)),
288-
))),
292+
ReadEvent::EndRecord => {
293+
let mut strat = ExponentialStrategy::default();
294+
if let Some(interval) = max_interval {
295+
strat.max_interval = interval
296+
};
297+
if let Some(backoff) = max_backoff {
298+
strat.max_backoff = backoff
299+
};
300+
Some(Ok(RetryStrategy::Exponential(strat)))
301+
}
289302
ow => Some(Err(ow.kind_error(ExpectedEvent::Or(vec![
290303
ExpectedEvent::ValueEvent(ValueKind::Text),
291304
ExpectedEvent::EndOfRecord,

api/swimos_form/src/structural/write/impls.rs

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const NONE_TAG: &str = "none";
2222
use crate::structural::write::{
2323
BodyWriter, HeaderWriter, RecordBodyKind, StructuralWritable, StructuralWriter,
2424
};
25-
use swimos_utilities::future::retryable::RetryStrategy;
25+
use swimos_utilities::future::RetryStrategy;
2626

2727
impl StructuralWritable for RetryStrategy {
2828
fn num_attributes(&self) -> usize {
@@ -31,31 +31,32 @@ impl StructuralWritable for RetryStrategy {
3131

3232
fn write_with<W: StructuralWriter>(&self, writer: W) -> Result<W::Repr, W::Error> {
3333
match self {
34-
RetryStrategy::Immediate(strat) => {
35-
let header_writer = writer.record(1)?;
36-
let mut body_writer = header_writer
37-
.write_extant_attr(IMMEDIATE_TAG)?
38-
.complete_header(RecordBodyKind::MapLike, 1)?;
39-
body_writer = body_writer.write_slot(&RETRIES_TAG, &strat.retry)?;
40-
body_writer.done()
41-
}
42-
RetryStrategy::Interval(strat) => {
43-
let header_writer = writer.record(1)?;
44-
let mut body_writer = header_writer
45-
.write_extant_attr(INTERVAL_TAG)?
46-
.complete_header(RecordBodyKind::MapLike, 2)?;
47-
body_writer = body_writer.write_slot(&DELAY_TAG, &strat.delay)?;
48-
body_writer = body_writer.write_slot(&RETRIES_TAG, &strat.retry)?;
49-
body_writer.done()
50-
}
34+
RetryStrategy::Interval(strat) => match &strat.delay {
35+
Some(delay) => {
36+
let header_writer = writer.record(1)?;
37+
let mut body_writer = header_writer
38+
.write_extant_attr(INTERVAL_TAG)?
39+
.complete_header(RecordBodyKind::MapLike, 2)?;
40+
body_writer = body_writer.write_slot(&DELAY_TAG, delay)?;
41+
body_writer = body_writer.write_slot(&RETRIES_TAG, &strat.retry)?;
42+
body_writer.done()
43+
}
44+
_ => {
45+
let header_writer = writer.record(1)?;
46+
let mut body_writer = header_writer
47+
.write_extant_attr(IMMEDIATE_TAG)?
48+
.complete_header(RecordBodyKind::MapLike, 1)?;
49+
body_writer = body_writer.write_slot(&RETRIES_TAG, &strat.retry)?;
50+
body_writer.done()
51+
}
52+
},
5153
RetryStrategy::Exponential(strat) => {
5254
let header_writer = writer.record(1)?;
5355
let mut body_writer = header_writer
5456
.write_extant_attr(EXPONENTIAL_TAG)?
5557
.complete_header(RecordBodyKind::MapLike, 2)?;
56-
body_writer =
57-
body_writer.write_slot(&MAX_INTERVAL_TAG, &strat.get_max_interval())?;
58-
body_writer = body_writer.write_slot(&MAX_BACKOFF_TAG, &strat.get_max_backoff())?;
58+
body_writer = body_writer.write_slot(&MAX_INTERVAL_TAG, &strat.max_interval)?;
59+
body_writer = body_writer.write_slot(&MAX_BACKOFF_TAG, &strat.max_backoff)?;
5960
body_writer.done()
6061
}
6162
RetryStrategy::None(_) => writer
@@ -68,32 +69,32 @@ impl StructuralWritable for RetryStrategy {
6869

6970
fn write_into<W: StructuralWriter>(self, writer: W) -> Result<W::Repr, W::Error> {
7071
match self {
71-
RetryStrategy::Immediate(strat) => {
72-
let header_writer = writer.record(1)?;
73-
let mut body_writer = header_writer
74-
.write_extant_attr(IMMEDIATE_TAG)?
75-
.complete_header(RecordBodyKind::MapLike, 1)?;
76-
body_writer = body_writer.write_slot_into(RETRIES_TAG, strat.retry)?;
77-
body_writer.done()
78-
}
79-
RetryStrategy::Interval(strat) => {
80-
let header_writer = writer.record(1)?;
81-
let mut body_writer = header_writer
82-
.write_extant_attr(INTERVAL_TAG)?
83-
.complete_header(RecordBodyKind::MapLike, 2)?;
84-
body_writer = body_writer.write_slot_into(DELAY_TAG, strat.delay)?;
85-
body_writer = body_writer.write_slot_into(RETRIES_TAG, strat.retry)?;
86-
body_writer.done()
87-
}
72+
RetryStrategy::Interval(strat) => match &strat.delay {
73+
Some(delay) => {
74+
let header_writer = writer.record(1)?;
75+
let mut body_writer = header_writer
76+
.write_extant_attr(INTERVAL_TAG)?
77+
.complete_header(RecordBodyKind::MapLike, 2)?;
78+
body_writer = body_writer.write_slot_into(DELAY_TAG, delay)?;
79+
body_writer = body_writer.write_slot_into(RETRIES_TAG, strat.retry)?;
80+
body_writer.done()
81+
}
82+
_ => {
83+
let header_writer = writer.record(1)?;
84+
let mut body_writer = header_writer
85+
.write_extant_attr(IMMEDIATE_TAG)?
86+
.complete_header(RecordBodyKind::MapLike, 1)?;
87+
body_writer = body_writer.write_slot_into(RETRIES_TAG, strat.retry)?;
88+
body_writer.done()
89+
}
90+
},
8891
RetryStrategy::Exponential(strat) => {
8992
let header_writer = writer.record(1)?;
9093
let mut body_writer = header_writer
9194
.write_extant_attr(EXPONENTIAL_TAG)?
9295
.complete_header(RecordBodyKind::MapLike, 2)?;
93-
body_writer =
94-
body_writer.write_slot_into(MAX_INTERVAL_TAG, strat.get_max_interval())?;
95-
body_writer =
96-
body_writer.write_slot_into(MAX_BACKOFF_TAG, strat.get_max_backoff())?;
96+
body_writer = body_writer.write_slot_into(MAX_INTERVAL_TAG, strat.max_interval)?;
97+
body_writer = body_writer.write_slot_into(MAX_BACKOFF_TAG, strat.max_backoff)?;
9798
body_writer.done()
9899
}
99100
RetryStrategy::None(_) => writer

api/swimos_form/src/structural/write/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ use std::sync::Arc;
2525
use std::time::Duration;
2626
use swimos_model::{Attr, Blob, Item, Text, Value};
2727
use swimos_model::{BigInt, BigUint};
28-
use swimos_utilities::future::retryable::strategy::Quantity;
28+
use swimos_utilities::future::Quantity;
2929

3030
#[doc(hidden)]
3131
pub use swimos_form_derive::StructuralWritable;
3232
use swimos_model::Timestamp;
33-
use swimos_utilities::routing::route_uri::RouteUri;
33+
use swimos_utilities::routing::RouteUri;
3434

3535
pub use crate::structural::write::to_model::ValueInterpreter;
3636
mod impls;

api/swimos_form_derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use crate::structural::{
3131
build_derive_structural_writable,
3232
};
3333
use crate::tag::build_derive_tag;
34-
use swimos_utilities::errors::validation::Validation;
3534
use swimos_utilities::errors::Errors;
35+
use swimos_utilities::errors::Validation;
3636

3737
mod modifiers;
3838
mod structural;

api/swimos_form_derive/src/modifiers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use macro_utilities::{
2121
TypeLevelNameTransform, TypeLevelNameTransformConsumer,
2222
};
2323
use quote::ToTokens;
24-
use swimos_utilities::errors::validation::{Validation, ValidationItExt};
2524
use swimos_utilities::errors::Errors;
25+
use swimos_utilities::errors::{Validation, ValidationItExt};
2626

2727
/// Fold the attributes present on some syntactic element, accumulating errors.
2828
pub fn fold_attr_meta<'a, It, S, F>(path: Symbol, attrs: It, init: S, mut f: F) -> SynValidation<S>

api/swimos_form_derive/src/structural/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::structural::read::DeriveStructuralReadable;
2020
use crate::structural::write::DeriveStructuralWritable;
2121
use proc_macro2::TokenStream;
2222
use quote::ToTokens;
23-
use swimos_utilities::errors::validation::Validation;
2423
use swimos_utilities::errors::Errors;
24+
use swimos_utilities::errors::Validation;
2525
use syn::{Data, DeriveInput, Generics};
2626

2727
pub mod model;

0 commit comments

Comments
 (0)