Skip to content

Commit 8fe57ab

Browse files
authored
Improve Many operation descriptions (#358)
1 parent da4952b commit 8fe57ab

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

butane_core/src/many.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ where
7878
self.all_values = OnceLock::new();
7979
}
8080

81-
/// Adds a value. Returns Err(ValueNotSaved) if the
82-
/// provided value uses automatic primary keys and appears
81+
/// Adds a value, yet to be performed in the backend.
82+
///
83+
/// After invoking this, `get()` can not be used until `save()` is performed.
84+
///
85+
/// Returns Err(ValueNotSaved) if the provided value uses automatic primary keys and appears
8386
/// to have an uninitialized one.
8487
pub fn add(&mut self, new_val: &T) -> Result<()> {
8588
// Check for uninitialized pk
@@ -93,23 +96,26 @@ where
9396
Ok(())
9497
}
9598

96-
/// Removes a value.
99+
/// Removes a value, yet to be performed in the backend
100+
///
101+
/// After invoking this, `get()` can not be used until `save()` is performed.
97102
pub fn remove(&mut self, val: &T) {
98103
// all_values is now out of date, so clear it
99104
self.all_values = OnceLock::new();
100105
self.removed_values.push(val.pk().to_sql())
101106
}
102107

103-
/// Returns a reference to the value. It must have already been loaded. If not, returns Error::ValueNotLoaded
108+
/// Returns already loaded values.
109+
///
110+
/// Returns [`Error::ValueNotLoaded`] if `load()` has not been invoked prior.
104111
pub fn get(&self) -> Result<impl Iterator<Item = &T>> {
105112
self.all_values
106113
.get()
107114
.ok_or(Error::ValueNotLoaded)
108115
.map(|v| v.iter())
109116
}
110117

111-
/// Query the values referred to by this many relationship from the
112-
/// database if necessary and returns a reference to them.
118+
/// Provide a Query for the values referred to by this many relationship.
113119
fn query(&self) -> Result<Query<T>> {
114120
let owner: &SqlVal = match &self.owner {
115121
Some(o) => o,

0 commit comments

Comments
 (0)