Skip to content

Commit 22ef5fc

Browse files
committed
Improve docs and remove unused type params
1 parent 3c8922a commit 22ef5fc

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

src/actions.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
//! # Actions
1919
//!
20-
//! This module contains macros and other methods for running actions. To run actions:
20+
//! This module contains traits for running actions. To run actions:
2121
//! - For the `sync` feature, add this import:
2222
//! ```
2323
//! use skytable::actions::Actions;
@@ -50,7 +50,9 @@ use crate::Response;
5050
use core::{future::Future, pin::Pin};
5151
use std::io::ErrorKind;
5252

53+
/// The error string returned when the snapshot engine is busy
5354
pub const ERR_SNAPSHOT_BUSY: &str = "err-snapshot-busy";
55+
/// The error string returned when periodic snapshots are busy
5456
pub const ERR_SNAPSHOT_DISABLED: &str = "err-snapshot-disabled";
5557

5658
/// Errors while running actions
@@ -152,26 +154,26 @@ impl<T> AsyncActions for T where T: AsyncSocket {}
152154
implement_actions!(
153155
/// Get the number of keys present in the database
154156
fn dbsize() -> usize {
155-
{Query::from("dbsize")}
157+
{ Query::from("dbsize") }
156158
Response::Item(Element::UnsignedInt(int)) => int as usize
157159
}
158160
/// Deletes a single or a number of keys
159161
///
160162
/// This will return the number of keys that were deleted
161-
fn del<T: IntoSkyhashBytes>(key: impl IntoSkyhashAction + 's) -> usize {
162-
{Query::from("del").arg(key)}
163+
fn del(key: impl IntoSkyhashAction + 's) -> usize {
164+
{ Query::from("del").arg(key) }
163165
Response::Item(Element::UnsignedInt(int)) => int as usize
164166
}
165167
/// Checks if a key (or keys) exist(s)
166168
///
167169
/// This will return the number of keys that do exist
168-
fn exists<T: IntoSkyhashBytes>(key: impl IntoSkyhashAction + 's) -> usize {
169-
{Query::from("exists").arg(key)}
170+
fn exists(key: impl IntoSkyhashAction + 's) -> usize {
171+
{ Query::from("exists").arg(key) }
170172
Response::Item(Element::UnsignedInt(int)) => int as usize
171173
}
172174
/// Removes all the keys present in the database
173175
fn flushdb() -> () {
174-
{Query::from("flushdb")}
176+
{ Query::from("flushdb") }
175177
Response::Item(Element::RespCode(RespCode::Okay)) => {}
176178
}
177179
/// Get the value of a key
@@ -247,7 +249,7 @@ implement_actions!(
247249
}
248250
/// Deletes all the provided keys if they exist or doesn't do anything at all. This method
249251
/// will return true if all the provided keys were deleted, else it will return false
250-
fn sdel<T: IntoSkyhashBytes>(keys: impl IntoSkyhashAction + 's) -> bool {
252+
fn sdel(keys: impl IntoSkyhashAction + 's) -> bool {
251253
{ Query::from("sdel").arg(keys) }
252254
Response::Item(Element::RespCode(RespCode::Okay)) => true,
253255
Response::Item(Element::RespCode(RespCode::NotFound)) => false

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
//! ```
6464
//!
6565
//! Way to go &mdash; you're all set! Now go ahead and run more advanced queries!
66+
//!
67+
//! ## Going advanced
68+
//!
69+
//! Now that you know how you can run basic queries, check out the [`actions`] module documentation for learning
70+
//! to use actions and the [`types`] module documentation for implementing your own Skyhash serializable
71+
//! types.
6672
//!
6773
//! ## Async API
6874
//!

src/types.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,61 @@
2020
//! This module contains a collection of enumerations and traits that are used for converting multiple
2121
//! types, either primitve or user-defined, into Skyhash serializable items.
2222
//!
23+
//!
24+
//! ## Implementing a Skyhash serializable type
25+
//! If you have an object that can be turned into a [`String`] or a sequence of [`String`] objects, then
26+
//! your type can be serialized by Skyhash (this might change in the future with more types being supported).
27+
//! Here is a simple example:
28+
//! ```
29+
//! use skytable::actions::Actions;
30+
//! use skytable::types::{IntoSkyhashAction, IntoSkyhashBytes, GetIterator};
31+
//! use skytable::Query;
32+
//!
33+
//! /// Our custom element that adds "cool" to the end of every string when serialized
34+
//! struct CoolString(String);
35+
//!
36+
//! impl IntoSkyhashBytes for CoolString {
37+
//! fn into_string(&self) -> String {
38+
//! let mut st = self.0.to_string();
39+
//! // add cool
40+
//! st.push_str("cool");
41+
//! st
42+
//! }
43+
//! }
44+
//!
45+
//! /// Our custom sequence of `CoolString` objects
46+
//! struct CoolStringCollection(Vec<CoolString>);
47+
//!
48+
//! impl IntoSkyhashAction for CoolStringCollection {
49+
//! fn push_into_query(&self, query: &mut Query) {
50+
//! self.0.iter().for_each(|item| query.push(item.into_string()));
51+
//! }
52+
//! fn incr_len_by(&self) -> usize {
53+
//! self.0.len()
54+
//! }
55+
//! }
56+
//!
57+
//! // And finally implement `GetIterator` for use with some actions that need them
58+
//!
59+
//! impl GetIterator<CoolString> for CoolStringCollection {
60+
//! fn get_iter(&self) -> std::slice::Iter<'_, CoolString> {
61+
//! self.0.iter()
62+
//! }
63+
//! }
64+
//!
65+
//! // You can now directly append your custom element to queries
66+
//! fn main() {
67+
//! let mut q = Query::new();
68+
//! let cool = CoolString(String::from("sayan is "));
69+
//! q.push(cool);
70+
//! let other_cools = CoolStringCollection(vec![
71+
//! CoolString("ferris is ".to_owned()),
72+
//! CoolString("llvm is ".to_owned())
73+
//! ]);
74+
//! q.push(other_cools);
75+
//! assert_eq!(q, Query::from(vec!["sayan is cool", "ferris is cool", "llvm is cool"]));
76+
//! }
77+
//! ```
2378
2479
use crate::Query;
2580

@@ -181,7 +236,8 @@ pub enum SnapshotResult {
181236
Busy,
182237
}
183238

184-
/// Implement this trait for methods in [`AsyncActions`] or [`Actions`] that need them
239+
/// Implement this trait for methods in [`crate::actions`] that need them. See the
240+
/// [module level documentation](crate::types) for more information
185241
pub trait GetIterator<T: IntoSkyhashBytes>: IntoSkyhashAction {
186242
fn get_iter(&self) -> std::slice::Iter<T>;
187243
}

0 commit comments

Comments
 (0)