Skip to content

Commit f5d2088

Browse files
committed
Added method docs.
1 parent 5547c0f commit f5d2088

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

server/swimos_agent/src/lanes/join/map/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ where
667667
}
668668
}
669669

670+
/// A [`HandlerAction`] that will produce a value by applying a closure to a reference to
671+
/// and entry in the lane.
670672
pub struct JoinMapLaneWithEntry<C, L, K, V, F, B: ?Sized> {
671673
projection: for<'a> fn(&'a C) -> &'a JoinMapLane<L, K, V>,
672674
key: K,
@@ -675,6 +677,10 @@ pub struct JoinMapLaneWithEntry<C, L, K, V, F, B: ?Sized> {
675677
}
676678

677679
impl<C, L, K, V, F, B: ?Sized> JoinMapLaneWithEntry<C, L, K, V, F, B> {
680+
/// #Arguments
681+
/// * `projection` - Projection from the agent context to the lane.
682+
/// * `key` - Key of the entry.
683+
/// * `f` - The closure to apply to the entry.
678684
pub fn new(projection: for<'a> fn(&'a C) -> &'a JoinMapLane<L, K, V>, key: K, f: F) -> Self {
679685
JoinMapLaneWithEntry {
680686
projection,

server/swimos_agent/src/lanes/join/value/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ impl<C, K, V> JoinValueAddDownlink<C, K, V> {
428428
}
429429
}
430430

431+
/// A [`HandlerAction`] that will produce a value by applying a closure to a reference to
432+
/// and entry in the lane.
431433
pub struct JoinValueLaneWithEntry<C, K, V, F, B: ?Sized> {
432434
projection: for<'a> fn(&'a C) -> &'a JoinValueLane<K, V>,
433435
key: K,
@@ -436,6 +438,10 @@ pub struct JoinValueLaneWithEntry<C, K, V, F, B: ?Sized> {
436438
}
437439

438440
impl<C, K, V, F, B: ?Sized> JoinValueLaneWithEntry<C, K, V, F, B> {
441+
/// #Arguments
442+
/// * `projection` - Projection from the agent context to the lane.
443+
/// * `key` - Key of the entry.
444+
/// * `f` - The closure to apply to the entry.
439445
pub fn new(projection: for<'a> fn(&'a C) -> &'a JoinValueLane<K, V>, key: K, f: F) -> Self {
440446
JoinValueLaneWithEntry {
441447
projection,

server/swimos_agent/src/lanes/map/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{
3535
Modification, StepResult,
3636
},
3737
item::{AgentItem, InspectableMapLikeItem, MapItem, MapLikeItem, MutableMapLikeItem},
38-
map_storage::{MapStoreInner, WithEntryResult},
38+
map_storage::{MapStoreInner, TransformEntryResult},
3939
meta::AgentMetadata,
4040
};
4141

@@ -104,7 +104,7 @@ where
104104
}
105105

106106
/// Transform the value associated with a key.
107-
pub fn transform_entry<F>(&self, key: K, f: F) -> WithEntryResult
107+
pub fn transform_entry<F>(&self, key: K, f: F) -> TransformEntryResult
108108
where
109109
F: FnOnce(Option<&V>) -> Option<V>,
110110
{
@@ -394,13 +394,19 @@ where
394394
}
395395
}
396396

397+
/// A [`HandlerAction`] that will produce a value by applying a closure to a reference to
398+
/// and entry in the lane.
397399
pub struct MapLaneWithEntry<C, K, V, F, B: ?Sized> {
398400
projection: for<'a> fn(&'a C) -> &'a MapLane<K, V>,
399401
key_and_f: Option<(K, F)>,
400402
_type: PhantomData<fn(&B)>,
401403
}
402404

403405
impl<C, K, V, F, B: ?Sized> MapLaneWithEntry<C, K, V, F, B> {
406+
/// #Arguments
407+
/// * `projection` - Projection from the agent context to the lane.
408+
/// * `key` - Key of the entry.
409+
/// * `f` - The closure to apply to the entry.
404410
pub fn new(projection: for<'a> fn(&'a C) -> &'a MapLane<K, V>, key: K, f: F) -> Self {
405411
MapLaneWithEntry {
406412
projection,
@@ -620,7 +626,7 @@ where
620626
} = self;
621627
if let Some((key, f)) = key_and_f.take() {
622628
let lane = projection(context);
623-
if matches!(lane.transform_entry(key, f), WithEntryResult::NoChange) {
629+
if matches!(lane.transform_entry(key, f), TransformEntryResult::NoChange) {
624630
StepResult::done(())
625631
} else {
626632
StepResult::Complete {

server/swimos_agent/src/lanes/value/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,17 @@ impl<C, T> HandlerAction<C> for ValueLaneSync<C, T> {
274274
}
275275
}
276276

277+
/// An [`HandlerAction`] that will produce a value from a reference to the contents of the lane.
277278
pub struct ValueLaneWithValue<C, T, F, B: ?Sized> {
278279
projection: for<'a> fn(&'a C) -> &'a ValueLane<T>,
279280
f: Option<F>,
280281
_type: PhantomData<fn(&B)>,
281282
}
282283

283284
impl<C, T, F, B: ?Sized> ValueLaneWithValue<C, T, F, B> {
285+
/// #Arguments
286+
/// * `projection` - Projection from the agent context to the lane.
287+
/// * `f` - Closure to apply to the value of the lane.
284288
pub fn new(projection: for<'a> fn(&'a C) -> &'a ValueLane<T>, f: F) -> Self {
285289
ValueLaneWithValue {
286290
projection,

server/swimos_agent/src/map_storage/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<K, V, Q: Default> MapStoreInner<K, V, Q> {
5252
}
5353
}
5454

55-
pub enum WithEntryResult {
55+
pub enum TransformEntryResult {
5656
NoChange,
5757
Update,
5858
Remove,
@@ -78,7 +78,7 @@ where
7878
queue.push(MapOperation::Update { key, value: () });
7979
}
8080

81-
pub fn transform_entry<F>(&mut self, key: K, f: F) -> WithEntryResult
81+
pub fn transform_entry<F>(&mut self, key: K, f: F) -> TransformEntryResult
8282
where
8383
F: FnOnce(Option<&V>) -> Option<V>,
8484
{
@@ -93,22 +93,22 @@ where
9393
content.insert(key.clone(), v2);
9494
*previous = Some(MapLaneEvent::Update(key.clone(), Some(v)));
9595
queue.push(MapOperation::Update { key, value: () });
96-
WithEntryResult::Update
96+
TransformEntryResult::Update
9797
}
9898
_ => {
9999
*previous = Some(MapLaneEvent::Remove(key.clone(), v));
100100
queue.push(MapOperation::Remove { key: key.clone() });
101-
WithEntryResult::Remove
101+
TransformEntryResult::Remove
102102
}
103103
},
104104
_ => match f(None) {
105105
Some(v2) => {
106106
content.insert(key.clone(), v2);
107107
*previous = Some(MapLaneEvent::Update(key.clone(), None));
108108
queue.push(MapOperation::Update { key, value: () });
109-
WithEntryResult::Update
109+
TransformEntryResult::Update
110110
}
111-
_ => WithEntryResult::NoChange,
111+
_ => TransformEntryResult::NoChange,
112112
},
113113
}
114114
}

server/swimos_agent/src/stores/map/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::agent_model::WriteResult;
2727
use crate::event_handler::{ActionContext, HandlerAction, Modification, StepResult};
2828
use crate::event_queue::EventQueue;
2929
use crate::item::{AgentItem, InspectableMapLikeItem, MapItem, MapLikeItem, MutableMapLikeItem};
30-
use crate::map_storage::{MapStoreInner, WithEntryResult};
30+
use crate::map_storage::{MapStoreInner, TransformEntryResult};
3131
use crate::meta::AgentMetadata;
3232

3333
use super::StoreItem;
@@ -92,7 +92,7 @@ where
9292
}
9393

9494
/// Transform the value associated with a key.
95-
pub fn transform_entry<F>(&self, key: K, f: F) -> WithEntryResult
95+
pub fn transform_entry<F>(&self, key: K, f: F) -> TransformEntryResult
9696
where
9797
F: FnOnce(Option<&V>) -> Option<V>,
9898
{
@@ -413,7 +413,10 @@ where
413413
} = self;
414414
if let Some((key, f)) = key_and_f.take() {
415415
let store = projection(context);
416-
if matches!(store.transform_entry(key, f), WithEntryResult::NoChange) {
416+
if matches!(
417+
store.transform_entry(key, f),
418+
TransformEntryResult::NoChange
419+
) {
417420
StepResult::done(())
418421
} else {
419422
StepResult::Complete {
@@ -427,13 +430,19 @@ where
427430
}
428431
}
429432

433+
/// A [`HandlerAction`] that will produce a value by applying a closure to a reference to
434+
/// and entry in the store.
430435
pub struct MapStoreWithEntry<C, K, V, F, B: ?Sized> {
431436
projection: for<'a> fn(&'a C) -> &'a MapStore<K, V>,
432437
key_and_f: Option<(K, F)>,
433438
_type: PhantomData<fn(&B)>,
434439
}
435440

436441
impl<C, K, V, F, B: ?Sized> MapStoreWithEntry<C, K, V, F, B> {
442+
/// #Arguments
443+
/// * `projection` - Projection from the agent context to the store.
444+
/// * `key` - Key of the entry.
445+
/// * `f` - The closure to apply to the entry.
437446
pub fn new(projection: for<'a> fn(&'a C) -> &'a MapStore<K, V>, key: K, f: F) -> Self {
438447
MapStoreWithEntry {
439448
projection,

server/swimos_agent/src/stores/value/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,17 @@ impl<C, T> HandlerAction<C> for ValueStoreSet<C, T> {
276276
}
277277
}
278278

279+
/// An [`HandlerAction`] that will produce a value from a reference to the contents of the store.
279280
pub struct ValueStoreWithValue<C, T, F, B: ?Sized> {
280281
projection: for<'a> fn(&'a C) -> &'a ValueStore<T>,
281282
f: Option<F>,
282283
_type: PhantomData<fn(&B)>,
283284
}
284285

285286
impl<C, T, F, B: ?Sized> ValueStoreWithValue<C, T, F, B> {
287+
/// #Arguments
288+
/// * `projection` - Projection from the agent context to the store.
289+
/// * `f` - Closure to apply to the value of the store.
286290
pub fn new(projection: for<'a> fn(&'a C) -> &'a ValueStore<T>, f: F) -> Self {
287291
ValueStoreWithValue {
288292
projection,

0 commit comments

Comments
 (0)