Skip to content

Commit

Permalink
Added missing docstrings, added deny for missing docstrings
Browse files Browse the repository at this point in the history
This also renames a method for consistency.
  • Loading branch information
mitsuhiko committed Sep 3, 2019
1 parent 18fcc4b commit ce59cec
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/aio.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Adds experimental async IO support to redis.
use std::collections::VecDeque;
use std::fmt::Arguments;
use std::io::{self, BufReader, Read, Write};
Expand Down Expand Up @@ -105,9 +106,10 @@ macro_rules! with_write_connection {
}

impl Connection {
/// Retrieves a single response from the connection.
pub fn read_response(self) -> impl Future<Item = (Self, Value), Error = RedisError> {
let db = self.db;
with_connection!(self.con, crate::parser::parse_async).then(move |result| {
with_connection!(self.con, crate::parser::parse_redis_value_async).then(move |result| {
match result {
Ok((con, value)) => Ok((Connection { con: con, db }, value)),
Err(err) => {
Expand All @@ -119,6 +121,7 @@ impl Connection {
}
}

/// Opens a connection.
pub fn connect(
connection_info: ConnectionInfo,
) -> impl Future<Item = Connection, Error = RedisError> {
Expand Down Expand Up @@ -199,6 +202,7 @@ pub fn connect(
}))
}

/// An async abstraction over connections.
pub trait ConnectionLike: Sized {
/// Sends an already encoded (packed) command into the TCP socket and
/// reads the single response from it.
Expand Down Expand Up @@ -493,13 +497,15 @@ enum ActualPipeline {
Unix(Pipeline<Framed<UnixStream, ValueCodec>>),
}

/// A connection object bound to an executor.
#[derive(Clone)]
pub struct SharedConnection {
pipeline: ActualPipeline,
db: i64,
}

impl SharedConnection {
/// Creates a shared connection from a connection and executor.
pub fn new<E>(con: Connection, executor: E) -> impl Future<Item = Self, Error = RedisError>
where
E: Executor<Box<dyn Future<Item = (), Error = ()> + Send>>,
Expand Down
5 changes: 5 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ impl Client {
Ok(connect(&self.connection_info)?)
}

/// Returns an async connection from the client.
pub fn get_async_connection(
&self,
) -> impl Future<Item = crate::aio::Connection, Error = RedisError> {
crate::aio::connect(self.connection_info.clone())
}

/// Returns a async shared connection from the client.
///
/// This uses the default tokio executor.
#[cfg(feature = "executor")]
pub fn get_shared_async_connection(
&self,
Expand All @@ -59,6 +63,7 @@ impl Client {
.and_then(move |con| crate::aio::SharedConnection::new(con, executor))
}

/// Returns a async shared connection with a specific executor.
pub fn get_shared_async_connection_with_executor<E>(
&self,
executor: E,
Expand Down
3 changes: 3 additions & 0 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ impl Cmd {
}
}

/// Async version of `query`.
#[inline]
pub fn query_async<C, T: FromRedisValue>(&self, con: C) -> RedisFuture<(C, T)>
where
Expand Down Expand Up @@ -526,6 +527,7 @@ impl Pipeline {
Value::Bulk(rv)
}

/// Returns the encoded pipeline commands.
pub fn get_packed_pipeline(&self, atomic: bool) -> Vec<u8> {
encode_pipeline(&self.commands, atomic)
}
Expand Down Expand Up @@ -628,6 +630,7 @@ impl Pipeline {
)
}

/// Async version of `query`.
#[inline]
pub fn query_async<C, T: FromRedisValue>(self, con: C) -> RedisFuture<(C, T)>
where
Expand Down
2 changes: 2 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,9 @@ implement_commands! {
///
/// Arbitrary data may be returned from `Break`.
pub enum ControlFlow<U> {
/// Continues.
Continue,
/// Breaks with a value.
Break(U),
}

Expand Down
20 changes: 13 additions & 7 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ pub enum ConnectionAddr {
}

impl ConnectionAddr {
// Because not all platforms uspport all connection addresses this is a
// quick way to figure out if a connection method is supported. Currently
// this only affects unix connections which are only supported on unix
// platforms and on older versions of rust also require an explicit feature
// to be enabled.
/// Checks if this address is supported.
///
/// Because not all platforms support all connection addresses this is a
/// quick way to figure out if a connection method is supported. Currently
/// this only affects unix connections which are only supported on unix
/// platforms and on older versions of rust also require an explicit feature
/// to be enabled.
pub fn is_supported(&self) -> bool {
match *self {
ConnectionAddr::Tcp(_, _) => true,
Expand All @@ -72,6 +74,7 @@ pub struct ConnectionInfo {
/// constructor of the client to accept connection information in a
/// range of different formats.
pub trait IntoConnectionInfo {
/// Converts the object into a connection info object.
fn into_connection_info(self) -> RedisResult<ConnectionInfo>;
}

Expand Down Expand Up @@ -272,6 +275,7 @@ impl ActualConnection {
}
}

/// Fetches a single response from the connection.
pub fn read_response(&mut self) -> RedisResult<Value> {
let result = Parser::new(match *self {
ActualConnection::Tcp(TcpConnection { ref mut reader, .. }) => {
Expand Down Expand Up @@ -444,9 +448,11 @@ impl Connection {
self.con.set_read_timeout(dur)
}

/// Creats a pubsub instance.for this connection.
pub fn as_pubsub<'a>(&'a mut self) -> PubSub<'a> {
// NOTE: The pubsub flag is intentionally not raised at this time since running commands
// within the pubsub state should not try and exit from the pubsub state.
// NOTE: The pubsub flag is intentionally not raised at this time since
// running commands within the pubsub state should not try and exit from
// the pubsub state.
PubSub::new(self)
}

Expand Down
9 changes: 9 additions & 0 deletions src/geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ macro_rules! invalid_type_error {
/// [1]: ../trait.Commands.html#method.geo_dist
/// [2]: ../trait.Commands.html#method.geo_radius
pub enum Unit {
/// Represents meters.
Meters,
/// Represents kilometers.
Kilometers,
/// Represents miles.
Miles,
/// Represents feed.
Feet,
}

Expand Down Expand Up @@ -50,7 +54,9 @@ impl ToRedisArgs for Unit {
/// * To keep the raw value from Redis, use `String`.
#[derive(Debug, PartialEq)]
pub struct Coord<T> {
/// Longitude
pub longitude: T,
/// Latitude
pub latitude: T,
}

Expand Down Expand Up @@ -240,8 +246,11 @@ impl ToRedisArgs for RadiusOptions {
/// [1]: ../trait.Commands.html#method.geo_radius
/// [2]: ../trait.Commands.html#method.geo_radius_by_member
pub struct RadiusSearchResult {
/// The name that was found.
pub name: String,
/// The coordinate if available.
pub coord: Option<Coord<f64>>,
/// The distance if available.
pub dist: Option<f64>,
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
//! is a lot more stable than the structs.

#![deny(non_camel_case_types)]
#![deny(missing_docs)]

// public api
pub use crate::client::Client;
Expand All @@ -355,7 +356,7 @@ pub use crate::connection::{
parse_redis_url, transaction, Connection, ConnectionAddr, ConnectionInfo, ConnectionLike,
IntoConnectionInfo, Msg, PubSub,
};
pub use crate::parser::{parse_async, parse_redis_value, Parser};
pub use crate::parser::{parse_redis_value_async, parse_redis_value, Parser};
pub use crate::script::{Script, ScriptInvocation};

pub use crate::types::{
Expand Down
4 changes: 3 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ where
}
}

pub fn parse_async<R>(reader: R) -> impl Future<Item = (R, Value), Error = RedisError>
/// Parses a redis value asynchronously.
pub fn parse_redis_value_async<R>(reader: R) -> impl Future<Item = (R, Value), Error = RedisError>
where
R: AsyncRead + BufRead,
{
Expand Down Expand Up @@ -299,6 +300,7 @@ impl<'a, T: BufRead> Parser<T> {

// public api

/// Parses a single value from the reader.
pub fn parse_value(&mut self) -> RedisResult<Value> {
let mut parser = ValueFuture {
reader: Some(&mut self.reader),
Expand Down
9 changes: 9 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ use futures::Future;
/// the behavior of arguments in a numeric context.
#[derive(PartialEq, Eq, Clone, Debug, Copy)]
pub enum NumericBehavior {
/// This argument is not numeric.
NonNumeric,
/// This argument is an integer.
NumberIsInteger,
/// This argument is a floating point value.
NumberIsFloat,
}

Expand Down Expand Up @@ -344,6 +347,7 @@ pub fn make_extension_error(code: &str, detail: Option<&str>) -> RedisError {
/// Library generic result type.
pub type RedisResult<T> = Result<T, RedisError>;

/// Library generic future type.
pub type RedisFuture<T> = Box<dyn Future<Item = T, Error = RedisError> + Send>;

/// An info dictionary type.
Expand Down Expand Up @@ -396,20 +400,25 @@ impl InfoDict {
}
}

/// Looks up a key in the info dict.
pub fn find(&self, key: &&str) -> Option<&Value> {
self.map.get(*key)
}

/// Checks if a key is contained in the info dicf.
pub fn contains_key(&self, key: &&str) -> bool {
self.find(key).is_some()
}

/// Returns the size of the info dict.
pub fn len(&self) -> usize {
self.map.len()
}
}

/// Abstraction trait for redis command abstractions.
pub trait RedisWrite {
/// Accepts a serialized redis command.
fn write_arg(&mut self, arg: &[u8]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ quickcheck! {
let mut reader = &encoded_input[..];
let partial_reader = PartialAsyncRead::new(&mut reader, seq);

let result = block_on_all(redis::parse_async(BufReader::new(partial_reader))
let result = block_on_all(redis::parse_redis_value_async(BufReader::new(partial_reader))
.map(|t| t.1));
assert!(result.as_ref().is_ok(), "{}", result.unwrap_err());
assert_eq!(
Expand Down

0 comments on commit ce59cec

Please sign in to comment.