2020-07-26 22:08:40 +03:00
|
|
|
//! # Sonic Channel
|
|
|
|
//! Rust client for [sonic] search backend.
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! ## Example usage
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! ### Search channel
|
2020-07-31 23:34:58 +03:00
|
|
|
//!
|
|
|
|
//! Note: This example requires enabling the `search` feature, enabled by default.
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-08-01 11:04:54 +03:00
|
|
|
//! ```rust,no_run
|
2020-07-26 22:08:40 +03:00
|
|
|
//! use sonic_channel::*;
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! fn main() -> result::Result<()> {
|
2020-11-25 19:09:08 +03:00
|
|
|
//! let channel = SearchChannel::start(
|
2020-07-26 22:08:40 +03:00
|
|
|
//! "localhost:1491",
|
|
|
|
//! "SecretPassword",
|
|
|
|
//! )?;
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! let objects = channel.query("collection", "bucket", "recipe")?;
|
|
|
|
//! dbg!(objects);
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! Ok(())
|
|
|
|
//! }
|
|
|
|
//! ```
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! ### Ingest channel
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-31 23:34:58 +03:00
|
|
|
//! Note: This example requires enabling the `ingest` feature.
|
|
|
|
//!
|
2020-08-01 11:04:54 +03:00
|
|
|
//! ```rust,no_run
|
2020-07-26 22:08:40 +03:00
|
|
|
//! use sonic_channel::*;
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! fn main() -> result::Result<()> {
|
2020-11-25 19:09:08 +03:00
|
|
|
//! let mut channel = IngestChannel::start(
|
2020-07-26 22:08:40 +03:00
|
|
|
//! "localhost:1491",
|
|
|
|
//! "SecretPassword",
|
|
|
|
//! )?;
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! let pushed = channel.push("collection", "bucket", "object:1", "my best recipe")?;
|
|
|
|
//! // or
|
|
|
|
//! // let pushed = channel.push_with_locale("collection", "bucket", "object:1", "Мой лучший рецепт", "rus")?;
|
|
|
|
//! dbg!(pushed);
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! Ok(())
|
|
|
|
//! }
|
|
|
|
//! ```
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-08-07 02:58:19 +03:00
|
|
|
//! ### Control channel
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-08-07 02:58:19 +03:00
|
|
|
//! Note: This example requires enabling the `control` feature.
|
|
|
|
//!
|
|
|
|
//! ```rust,no_run
|
|
|
|
//! use sonic_channel::*;
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-08-07 02:58:19 +03:00
|
|
|
//! fn main() -> result::Result<()> {
|
2020-11-25 19:09:08 +03:00
|
|
|
//! let mut channel = ControlChannel::start(
|
2020-08-07 02:58:19 +03:00
|
|
|
//! "localhost:1491",
|
|
|
|
//! "SecretPassword",
|
|
|
|
//! )?;
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-08-07 02:58:19 +03:00
|
|
|
//! let result = channel.consolidate()?;
|
|
|
|
//! assert_eq!(result, true);
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-08-07 02:58:19 +03:00
|
|
|
//! Ok(())
|
|
|
|
//! }
|
|
|
|
//! ```
|
2020-10-16 10:49:05 +03:00
|
|
|
//!
|
2020-07-26 22:08:40 +03:00
|
|
|
//! [sonic]: https://github.com/valeriansaliou/sonic
|
|
|
|
|
|
|
|
// Rustc lints.
|
|
|
|
#![deny(
|
|
|
|
missing_debug_implementations,
|
|
|
|
unsafe_code,
|
|
|
|
unstable_features,
|
|
|
|
unused_imports,
|
|
|
|
unused_qualifications
|
|
|
|
)]
|
|
|
|
#![warn(missing_docs)]
|
2020-10-16 10:45:21 +03:00
|
|
|
// Clippy lints
|
|
|
|
#![deny(clippy::all)]
|
2020-07-18 11:01:51 +03:00
|
|
|
|
2020-07-23 10:44:02 +03:00
|
|
|
#[cfg(not(any(feature = "ingest", feature = "search", feature = "control")))]
|
2020-10-16 10:49:05 +03:00
|
|
|
compile_error!(
|
|
|
|
r#"Either features "ingest" or "search" or "control" must be enabled for "sonic-channel" crate"#
|
|
|
|
);
|
2020-07-23 10:44:02 +03:00
|
|
|
|
2020-11-25 19:09:08 +03:00
|
|
|
#[macro_use]
|
|
|
|
mod macroses;
|
|
|
|
|
|
|
|
mod channels;
|
2020-07-18 11:01:51 +03:00
|
|
|
mod commands;
|
2020-07-26 23:36:07 +03:00
|
|
|
|
|
|
|
/// Contains sonic channel error type and custom Result type for easy configure your functions.
|
2020-07-19 10:17:53 +03:00
|
|
|
pub mod result;
|
2020-07-18 11:01:51 +03:00
|
|
|
|
2020-11-25 19:09:08 +03:00
|
|
|
pub use channels::*;
|
2020-07-18 11:01:51 +03:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
extern crate regex;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-11-25 19:09:08 +03:00
|
|
|
use crate::channels::ChannelMode;
|
2020-07-18 11:01:51 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn format_channel_enums() {
|
|
|
|
assert_eq!(format!("{}", ChannelMode::Search), String::from("search"));
|
|
|
|
assert_eq!(format!("{}", ChannelMode::Ingest), String::from("ingest"));
|
|
|
|
assert_eq!(format!("{}", ChannelMode::Control), String::from("control"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: write tests with sonic server
|
|
|
|
}
|